commfuncs.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #ifndef COMM_FUNC_H
  2. #define COMM_FUNC_H
  3. /* The spatial column is identified by the fully qualified table name of the
  4. table to which it belongs, the spatial columns name and the columns spatial
  5. reference identifier. */
  6. typedef struct
  7. {
  8. char table[128];
  9. char column[128];
  10. int srid;
  11. } SpatialColumn;
  12. /* The geometry type enumeration. */
  13. typedef enum
  14. {
  15. geomEmpty = 0,
  16. geomPoint = 4,
  17. geomPointM = 5,
  18. geomPointZ = 6,
  19. geomPointZM = 7,
  20. geomMultiPoint = 8,
  21. geomMultiPointM = 9,
  22. geomMultiPointZ = 10,
  23. geomMultiPointZM = 11,
  24. geomLineString = 12,
  25. geomLineStringM = 13,
  26. geomLineStringZ = 14,
  27. geomLineStringZM = 15,
  28. geomPolygon = 16,
  29. geomPolygonM = 17,
  30. geomPolygonZ = 18,
  31. geomPolygonZM = 19,
  32. geomMultiLineString = 20,
  33. geomMultiLineStringM = 21,
  34. geomMultiLineStringZ = 22,
  35. geomMultiLineStringZM = 23,
  36. geomMultiPolygon = 24,
  37. geomMultiPolygonM = 25,
  38. geomMultiPolygonZ = 26,
  39. geomMultiPolygonZM = 27
  40. } GeomType;
  41. /* The shape type enumeration. */
  42. typedef enum
  43. {
  44. shpNil = 0,
  45. shpPoint = 1,
  46. shpPolyline = 3,
  47. shpPolygon = 5,
  48. shpMultiPoint = 8,
  49. shpPointZ = 9,
  50. shpPolylineZ = 10,
  51. shpPointZM = 11,
  52. shpPolylineZM = 13,
  53. shpPolygonZM = 15,
  54. shpMultiPointZM = 18,
  55. shpPolygonZ = 19,
  56. shpMultiPointZ = 20,
  57. shpPointM = 21,
  58. shpPolylineM = 23,
  59. shpPolygonM = 25,
  60. shpMultiPointM = 28
  61. } ShpType;
  62. /* The OGIS WKB data type enumeration. */
  63. typedef enum
  64. {
  65. wkbPoint = 1,
  66. wkbLineString = 2,
  67. wkbPolygon = 3,
  68. wkbMultiPoint = 4,
  69. wkbMultiLineString = 5,
  70. wkbMultiPolygon = 6,
  71. wkbCollection = 7
  72. } WkbType;
  73. /* The OGIS byte order enumeration. */
  74. typedef enum
  75. {
  76. BigEndian = 0,
  77. LittleEndian = 1
  78. } ByteOrder;
  79. /*
  80. * This macro assigns 1 to __a if the machine is little-endian,
  81. * and 0 if the machine is big-endian. Adapted from the TEST_ENDIAN
  82. * macro in /usr/include/sys/portal.h on HP machines. Note that this
  83. * adaptation reverses the sense of the test output so that it is
  84. * the same as the OpenGIS byte order enumeration.
  85. */
  86. #define ENDIAN_TEST(__a) \
  87. { union { short __sh; \
  88. char __ch[2]; \
  89. } __endian; \
  90. __endian.__sh = 0; \
  91. __endian.__ch[1] = '\001'; \
  92. __a = 1 - (__endian.__sh & 0x01); }
  93. /* The point coordinate structure. */
  94. typedef struct
  95. {
  96. double x;
  97. double y;
  98. } Point;
  99. typedef struct
  100. {
  101. GeomType type;
  102. int num_points; /* Total # of points in the geometry */
  103. int num_parts; /* Total # of parts */
  104. int num_subparts; /* Total # of subparts */
  105. int *offsets; /* The parts offsets index */
  106. int *suboffsets; /* The subpart offset index */
  107. Point *pt; /* The geometry's points array */
  108. double *z; /* The geometry's z values array */
  109. double *m; /* The geometry's m values array */
  110. int alloc_size; /* Keeps track of size of alloc'd pt/z/m arrays */
  111. int sub_allocsize; /* " " " suboffsets " */
  112. } Geometry;
  113. #define POINT_ALLOC_THRESHOLD 10
  114. #define GEOM_SUCCESS 0
  115. #define GEOM_INVALID_WKB_BYTE_ORDER 501
  116. #define GEOM_UNSUPPORTED_WKB_TYPE 502
  117. #define GEOM_INVALID_WKB_TYPE 503
  118. #define GEOM_TOO_FEW_POINTS 504
  119. #define GEOM_INVALID_NUM_PARTS 505
  120. #define GEOM_OUT_OF_MEMORY 506
  121. #define GEOM_INVALID_SHP_TYPE 507
  122. #define GEOM_INVALID_PART_OFFSET 508
  123. void geom_to_wkb (Geometry *geom,
  124. int *max_alloced,
  125. int *data_len,
  126. char **binary);
  127. int wkb_to_geom (char *binary,
  128. Geometry *geom);
  129. void geom_to_shape (Geometry *geom,
  130. int *max_alloced,
  131. int *data_len,
  132. char **binary);
  133. int shape_to_geom (char *binary,
  134. Geometry *geom);
  135. void put_integer (char **buf_ptr,
  136. int swap,
  137. int num_ints,
  138. int *int_vals);
  139. void put_double (char **buf_ptr,
  140. int swap,
  141. int num_doubles,
  142. double *double_vals);
  143. void put_xy (char **buf_ptr,
  144. int swap,
  145. int num_points,
  146. Point *points);
  147. void get_integer (char **buf_ptr,
  148. int swap,
  149. int num_ints,
  150. int *int_vals);
  151. void get_double (char **buf_ptr,
  152. int swap,
  153. int num_doubles,
  154. double *double_vals);
  155. void get_xy (char **buf_ptr,
  156. int swap,
  157. int num_points,
  158. Point *points);
  159. int geom_allocate (Geometry *geom,
  160. int npoints);
  161. #endif