GIS Application Development Using Libraries What are programming
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 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, 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: geo. Mean. XY ' CALL geo. Mean. XY(x(), y(), Npts, xmean, ymean) PRINT "Mean of X and Y "; xmean, ymean
SUB geo. Mean. XY (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 p 1, p 2. . pn 'With coordinates x 1, y 1, . . . xn, yn 'Requires the Number of points in the set (Npts) ' 'USES mth. Mean(v() as single, n as integer, vmean as Single) 'Returns the Arithmetic Mean of the X and Y coordinates CALL mth. Mean(x(), Npts, xmean) CALL mth. Mean(y(), Npts, ymean) END SUB
SUB mth. Mean (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 geo. Neighbor(x(), y(), Npts, nearst()) FOR i = 1 TO Npts PRINT "Nearest Neighbor ", i, nearst(i) NEXT i
SUB geo. Neighbor (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) = 1 E+07 ' FOR j = 1 TO Npts tdist = 0 IF i <> j THEN CALL geo. Dist 2 D(x(i), y(i), x(j), y(j), tdist) IF tdist < nearst(i) THEN nearst(i) = tdist END IF NEXT j NEXT i END SUB
SUB geo. Dist 2 D (x 1 AS SINGLE, y 1 AS SINGLE, x 2 AS SINGLE, y 2 AS SINGLE, dist AS SINGLE) ' 'This routine accepts two points (p 1, p 2) with coordinates x 1, y 1 and x 2, y 2 'And Returns the euclidean distance between them ' dist = ((x 2 - x 1) ^ 2) + ((y 2 - y 1) ^ 2) dist = SQR(dist) END SUB
'Calculate Mean Nearest Neighbor CALL mth. Mean(nearst(), Npts, nearmean) PRINT "Mean Nearest Neighbor "; nearmean
- Slides: 13