GIS Application Development Using Libraries
13 Slides59.00 KB
GIS Application Development Using Libraries
What are (programming) Libraries? NOT Buildings or Rooms in Universities!! But, they are COLLECTIONS of works Highly Specialized Indexed by Topic
High-Level Routines U s in g L ib ra ry C o m p o n e n ts Y o u r P ro g ra m M a th F u n c tio n s S ta tis tic s M a p /G ra p h ic s S p a tia l/G IS
Sample Library Y o u r P ro g ra m M a th m th M e a n v a r ( ) S in g le N In te g e r v a rm e a n ( S in g le ) G IS o th e rs G e o g r a p h ic g e o D is t 2 d geoM eanX Y g e o N e ig h b o r x 1 ,y 1 x 2 ,y 2 d is t a n c e ( a ll S in g le ) x (),y () A S S in g le N p ts In te g e r M e a n X ,Y x (), y () N p ts In te g e r N e a r D is t ( ) ( fo r e a c h p o in t )
OPTION BASE 1 DIM x(1 TO 7) AS SINGLE DIM y(1 TO 7) AS SINGLE DIM nearst(1 TO 7) AS SINGLE DIM nearmean AS SINGLE DIM dist AS SINGLE DIM xmean AS SINGLE DIM ymean AS SINGLE DIM Npts AS INTEGER 'a DATA statement is used to store ‘information inside the program DATA 2,3,2,7,3,6,6,5,8,5,8,4,7,1 Npts 7 FOR i 1 TO Npts ' a READ statement gets data READ x(i), y(i) NEXT i
'example call to "library routine: geoMeanXY ' CALL geoMeanXY(x(), y(), Npts, xmean, ymean) PRINT "Mean of X and Y "; xmean, ymean
SUB geoMeanXY (x() AS SINGLE, y() AS SINGLE, Npts AS INTEGER, xmean AS SINGLE, ymean AS SINGLE) ' 'This routine finds the Mean X,Y Value for a set of points p1,p2 . pn 'With coordinates x1,y1,.xn,yn 'Requires the Number of points in the set (Npts) ' 'USES mthMean(v() as single, n as integer, vmean as Single) 'Returns the Arithmetic Mean of the X and Y coordinates CALL mthMean(x(), Npts, xmean) CALL mthMean(y(), Npts, ymean) END SUB
SUB mthMean (var() AS SINGLE, N AS INTEGER, varmean AS SINGLE) 'Calculates Arithmetic Mean of a Variable (var) with dimension N ' varmean 0 FOR i 1 TO N varmean varmean var(i) NEXT i varmean varmean / N END SUB
CALL geoNeighbor(x(), y(), Npts, nearst()) FOR i 1 TO Npts PRINT "Nearest Neighbor ", i, nearst(i) NEXT i
SUB geoNeighbor (x() AS SINGLE, y() AS SINGLE, Npts AS INTEGER, nearst() AS SINGLE) DIM tdist AS SINGLE ' 'This routine calculates the Nearest Neighbor Matrix for a Set of points 'Each point is represented by its X,Y coordinates 'Npts is the number of points in the set ' 'Returns the Array nearst(Npts) of Nearest Neighbor Distance for each point
FOR i 1 TO Npts ' for each point set the nearest value to a ridiculously high number nearst(i) 1E 07 ' FOR j 1 TO Npts tdist 0 IF i j THEN CALL geoDist2D(x(i), y(i), x(j), y(j), tdist) IF tdist nearst(i) THEN nearst(i) tdist END IF END IF NEXT j NEXT i END SUB
SUB geoDist2D (x1 AS SINGLE, y1 AS SINGLE, x2 AS SINGLE, y2 AS SINGLE, dist AS SINGLE) ' 'This routine accepts two points (p1, p2) with coordinates x1,y1 and x2,y2 'And Returns the euclidean distance between them ' dist ((x2 - x1) 2) ((y2 - y1) 2) dist SQR(dist) END SUB
'Calculate Mean Nearest Neighbor CALL mthMean(nearst(), Npts, nearmean) PRINT "Mean Nearest Neighbor "; nearmean