MIMS Spatial Allocator Programmer's Guide

How to implement a customized reader:

A. The developer needs to change the PolyReader() method. The second argument to this method is a character string that points to the environment variable that specifies the type of the reader. In addition to adding customized code for the new reader, the developer must insert a section similar to the following segment:


   else if (!strcmp(type,"ShapeFile")) 

   {

      poly PolyShapeReader(ename);

B. To implement the customized reader (i.e. the substitute for PolyShapeReader), the developer needs to provide a reader method that returns a PolyObject and takes a character string argument pointing to the environment variable that specifies the file name. This method should do all the data reading and fill in an appropriate PolyObject struct. A pointer to the struct should be obtained by a call to getNewPoly(nObjects). The reader code should specify the type of polygon (polygon, line, or point), the map information struct, and the bounding box. (See PolyShapeReader and RegularGridReader for complete examples.)


   poly->nSHPType = SHPT_POLYGON;

   poly->map = map;

   poly->bb = newBBox(xmin, ymin, xmax, ymax)

Then in a loop over the objects the developer can do the following:

  1. Get a pointer to a PolyShape struct, e.g.:
    
          ps = getNewPolyShape(number_of_parts);
    
          ps->num_contours = 0; 
    
    
  2. Loop over the parts (i.e. contours, or polylines), get a pointer to a Shape struct
    
          shp = getNewShape(number_of_vertices);
    
    
  3. In a loop over the vertices, fill in the x and y for each vertex
    
          shp->vertex[i].x = xcoord;
    
          shp->vertex[i].y = ycoord;
    
    
  4. Close vertices loop
  5. Add a contour to the PolyShape, i.e.
    
          gpc_add_contour(ps,shp,SOLID_POLYGON);
    
    
  6. Close the loop over the parts
  7. Add the PolyShape struct to the PolyShape Object
    
          polyShapeIncl(&(poly->plist),ps,NULL);
    
    

C. A replacement for the attachAttribute method will also need to be developed for the new file format. This routine will need to properly associate the attribute information with the polygons.

Creating a new writer / Adding new operations

Currently, the program is organized into two main operations: creating surrogates (implemented in reportSurrogate), and performing spatial aggregation (reportSum). These methods each take a PolyObject * (a list of Shapes), perform a computation based on the attributes, and write the results to the file formats applicable to that operation. e.g. reportSurrogate has the format of the surrogate file embedded in it; reportSum calls polyShapeWrite to write the .shp portion of the shape file, and then in manipulates the attributes as appropriate (summing or averaging) and writes the new values with calls to DBFWriteDoubleAttribute.

Several major methods are used in support of the surrogate generation and the spatial aggregation. These are: sum1Poly, sum2Poly, and avg1Poly. If the developer wanted to add an interpolation method and fit it into the current aggregation framework, a new method (e.g. interp1Poly) could be developed that would interpolate the values of the attributes as desired. Alternatively, if the new operation would not fit into this framework, a new branch to the main program could be added.