#ifndef COMM_FUNC_H #define COMM_FUNC_H /* The spatial column is identified by the fully qualified table name of the table to which it belongs, the spatial columns name and the columns spatial reference identifier. */ typedef struct { char table[128]; char column[128]; int srid; } SpatialColumn; /* The geometry type enumeration. */ typedef enum { geomEmpty = 0, geomPoint = 4, geomPointM = 5, geomPointZ = 6, geomPointZM = 7, geomMultiPoint = 8, geomMultiPointM = 9, geomMultiPointZ = 10, geomMultiPointZM = 11, geomLineString = 12, geomLineStringM = 13, geomLineStringZ = 14, geomLineStringZM = 15, geomPolygon = 16, geomPolygonM = 17, geomPolygonZ = 18, geomPolygonZM = 19, geomMultiLineString = 20, geomMultiLineStringM = 21, geomMultiLineStringZ = 22, geomMultiLineStringZM = 23, geomMultiPolygon = 24, geomMultiPolygonM = 25, geomMultiPolygonZ = 26, geomMultiPolygonZM = 27 } GeomType; /* The shape type enumeration. */ typedef enum { shpNil = 0, shpPoint = 1, shpPolyline = 3, shpPolygon = 5, shpMultiPoint = 8, shpPointZ = 9, shpPolylineZ = 10, shpPointZM = 11, shpPolylineZM = 13, shpPolygonZM = 15, shpMultiPointZM = 18, shpPolygonZ = 19, shpMultiPointZ = 20, shpPointM = 21, shpPolylineM = 23, shpPolygonM = 25, shpMultiPointM = 28 } ShpType; /* The OGIS WKB data type enumeration. */ typedef enum { wkbPoint = 1, wkbLineString = 2, wkbPolygon = 3, wkbMultiPoint = 4, wkbMultiLineString = 5, wkbMultiPolygon = 6, wkbCollection = 7 } WkbType; /* The OGIS byte order enumeration. */ typedef enum { BigEndian = 0, LittleEndian = 1 } ByteOrder; /* * This macro assigns 1 to __a if the machine is little-endian, * and 0 if the machine is big-endian. Adapted from the TEST_ENDIAN * macro in /usr/include/sys/portal.h on HP machines. Note that this * adaptation reverses the sense of the test output so that it is * the same as the OpenGIS byte order enumeration. */ #define ENDIAN_TEST(__a) \ { union { short __sh; \ char __ch[2]; \ } __endian; \ __endian.__sh = 0; \ __endian.__ch[1] = '\001'; \ __a = 1 - (__endian.__sh & 0x01); } /* The point coordinate structure. */ typedef struct { double x; double y; } Point; typedef struct { GeomType type; int num_points; /* Total # of points in the geometry */ int num_parts; /* Total # of parts */ int num_subparts; /* Total # of subparts */ int *offsets; /* The parts offsets index */ int *suboffsets; /* The subpart offset index */ Point *pt; /* The geometry's points array */ double *z; /* The geometry's z values array */ double *m; /* The geometry's m values array */ int alloc_size; /* Keeps track of size of alloc'd pt/z/m arrays */ int sub_allocsize; /* " " " suboffsets " */ } Geometry; #define POINT_ALLOC_THRESHOLD 10 #define GEOM_SUCCESS 0 #define GEOM_INVALID_WKB_BYTE_ORDER 501 #define GEOM_UNSUPPORTED_WKB_TYPE 502 #define GEOM_INVALID_WKB_TYPE 503 #define GEOM_TOO_FEW_POINTS 504 #define GEOM_INVALID_NUM_PARTS 505 #define GEOM_OUT_OF_MEMORY 506 #define GEOM_INVALID_SHP_TYPE 507 #define GEOM_INVALID_PART_OFFSET 508 void geom_to_wkb (Geometry *geom, int *max_alloced, int *data_len, char **binary); int wkb_to_geom (char *binary, Geometry *geom); void geom_to_shape (Geometry *geom, int *max_alloced, int *data_len, char **binary); int shape_to_geom (char *binary, Geometry *geom); void put_integer (char **buf_ptr, int swap, int num_ints, int *int_vals); void put_double (char **buf_ptr, int swap, int num_doubles, double *double_vals); void put_xy (char **buf_ptr, int swap, int num_points, Point *points); void get_integer (char **buf_ptr, int swap, int num_ints, int *int_vals); void get_double (char **buf_ptr, int swap, int num_doubles, double *double_vals); void get_xy (char **buf_ptr, int swap, int num_points, Point *points); int geom_allocate (Geometry *geom, int npoints); #endif