160 likes | 319 Views
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. Sample Library. OPTION BASE 1 DIM x(1 TO 7) AS SINGLE
E N D
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
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