GIS, Arcview, Avanue and headache

Sometime in the programmer’s life...
Sometime in the programmer’s life happen to meet strange languages, this has happened to me in latest two months.
Im trying to introduce you Avenue.
The reason of this meeting is that Avenue is the proprietary scripting language of the most used software to make GeographicInformationSystem in the world: ESRI ArcView!
Now I am here to tell you something about it.
Firs of all it is not a general-purpose language…yes you may not use it outside the ESRI environment, something like Visual Basic for Application in the MS Office suite but in a different way.
What is means? It simply means that you cannot make an IRC client with Avenue but you can perfectly drive ArcView to do what you wont (if ArcView can do it !-).
In my project - the principal I have made - the target was a geographic information system to simplify the life of metropolitan’s user.
Substantially the heart of the system is the capability to give the best road …yes, have catched it: Dijkstra is in the house.
The following is the code of the resulting script:
(Note that it was made only to work … not to be optimized, so please, have compassion and if you have suggestions please let me know) :
Smart notes for the readers:
- ' this is the Avenue code comment marker
- Self is the reference to the invoking script...not much more then a list of paramiters! :-/
- a Dictionary is a classic list of couple key:value
- {} is the constructor for the list (like [] for python/jython or ArrayList in Java)
- the reserved word are in violet
- Avenue is not CaSeSENsiTive
' '------------------------------------------------------------------
' ' A (very bad) implementation of Dijkstra's algorithm to find the minimum
' ' path in a single source graph
' '
' ' Input : The graph and the start node (a station of our metropolitan)
' ' Output : the dictionary of minimum paths
' '
' ' Note : Due to the impossibility to use a real Priority Queue it is implemented as a linear array
' ' and the varius push and pop operations are maked "in-line"
' ' The elemnts in the queue are lists(that are not changed during theelaborations)
' ' made of :
' ' a) The minimum estimated distance from the source node
' ' b) The node that precede it in the optimum path from the source to
' ' the current node
' ' c) current examinde node
' '------------------------------------------------------------------
' Input reading (Paramiters are spcified trought the SELF reference)
G = SELF.Get(0) ' Graph
startNode = SELF.Get(1) ' Starting node (the starting train station)
endNode = SELF.Get(2) ' Final destination
D = Dictionary.Make(_StimaLunghezzaMassimaDiUnPercorso) ' minimum distance dictionary
P = Dictionary.Make(_StimaNumeroStazioniNelPercorsoOttimo) ' predecessor's dictionary
Q = {{0,nil,startNode}} ' List of "(estimated distance, predecessor, current node)" ;' Q is the priority queue of the estimated distance of the varius vertex
'of the graph
the initial node have a 0 distance from itself
while (Q.count >0) ' The algorithm will end whenn there will be no more distance to be evaluated
' From Q we select the element with the minimum weight
mintupla = Q.get(0)
for each tupla in Q
if( tupla.get(0)< style="color: rgb(204, 102, 204);">thenmintupla = tupla
end
end
dist = mintupla.get(0)
pred = mintupla.get(1)
v = mintupla.get(2)
index_mintupla = Q.find(mintupla)
Q.remove(index_mintupla) ' We remove the minimum element from the priority queue (pop)
'Verify if v is in D D_contain_v = D.add(v,100) 'if D contain v D.add return False
if(d_contain_v) then 'if so it means that we have added it so we will remove it D.remove(v) 'to restore the previus situation end
if(D_contain_v) then d_contain_v = false else d_contain_v = true end if (D_contain_v) then ' If D have the node in exame it means that we have continue ' yett found an optimale distance and so we can jump it : good :-) end
D.add(v, dist)
P.add(v, pred)
key_list = G.ReturnKeys Lista ={} for each id in key_list Lista.add(id.get(0)) end branch_list_v = G.get(v)
'now we analyze the distanceses of the node v from his neighbors w
for each w in branch_list_v.ReturnKeys
'Optimal distance from the source to the endpoint node v
start_v_lenght = D.get(v)
'distance under exam from v to the neighboring w
v_w_lenght = branch_list_v.get(w)
'EXTIMATION of the optimum distance form the source to w
vwLength = start_v_lenght + v_w_lenght
tuplaToPop = {vwLength,v,w} 'we insert w and w predecessor's (v) in the optimum walk
' and the distance from w to the source of the walk
'we do the pop in the queue Q.insert(tuplaToPop)
end 'for
end 'while
return P 'for our purpose, it interests only us the dictionary of the walks.
'Then we avoid to also return the dictionary of the distances (D) Ok, good and not good:
Good
Avenue is an Object Oriented scripting language
Avenue have built in List and Dictionary
String and numbers are immutable
Bad
Is not possible to define Abstract data Type in a Script...we have to find some tournaround, like in ouar case for a priority queue.
The internal ArcView editor is worse than MS Notepad :-O (you have to write a script to call an externale editor.)
No Exception mechanism.
The conclusion is tha AVENUE is a powerfull scripting system but not syncornized with the modern programming language tendence even though it do the job!
PS: I'have tryed Avenue in ArcView 3.1 and it's not a so recent softwere. Now there is a new version but I haven't the possibility to try it, so if someone have let me now the improvements.
PPS: Migrating from Avenue to VBA Workshop


0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home