PostGIS  2.1.10dev-r@@SVN_REVISION@@
static int parse_geojson_coord ( json_object *  poObj,
int *  hasz,
POINTARRAY pa 
)
static

Definition at line 84 of file lwin_geojson.c.

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, geojson_lwerror(), LW_FAILURE, LW_FALSE, LW_TRUE, LWDEBUGF, POINT4D::m, ptarray_append_point(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by parse_geojson_linestring(), parse_geojson_multilinestring(), parse_geojson_multipoint(), parse_geojson_multipolygon(), parse_geojson_point(), and parse_geojson_polygon().

85 {
86  POINT4D pt;
87 
88  LWDEBUGF(3, "parse_geojson_coord called for object %s.", json_object_to_json_string( poObj ) );
89 
90  if( json_type_array == json_object_get_type( poObj ) )
91  {
92 
93  json_object* poObjCoord = NULL;
94  const int nSize = json_object_array_length( poObj );
95  LWDEBUGF(3, "parse_geojson_coord called for array size %d.", nSize );
96 
97  if ( nSize < 2 )
98  {
99  geojson_lwerror("Too few ordinates in GeoJSON", 4);
100  return LW_FAILURE;
101  }
102 
103  // Read X coordinate
104  poObjCoord = json_object_array_get_idx( poObj, 0 );
105  pt.x = json_object_get_double( poObjCoord );
106  LWDEBUGF(3, "parse_geojson_coord pt.x = %f.", pt.x );
107 
108  // Read Y coordinate
109  poObjCoord = json_object_array_get_idx( poObj, 1 );
110  pt.y = json_object_get_double( poObjCoord );
111  LWDEBUGF(3, "parse_geojson_coord pt.y = %f.", pt.y );
112 
113  if( nSize > 2 ) /* should this be >= 3 ? */
114  {
115  // Read Z coordinate
116  poObjCoord = json_object_array_get_idx( poObj, 2 );
117  pt.z = json_object_get_double( poObjCoord );
118  LWDEBUGF(3, "parse_geojson_coord pt.z = %f.", pt.z );
119  *hasz = LW_TRUE;
120  }
121  else if ( nSize == 2 )
122  {
123  *hasz = LW_FALSE;
124  /* Initialize Z coordinate, if required */
125  if ( FLAGS_GET_Z(pa->flags) ) pt.z = 0.0;
126  }
127  else
128  {
129  /* TODO: should we account for nSize > 3 ? */
130  /* more than 3 coordinates, we're just dropping dimensions here... */
131  }
132 
133  /* Initialize M coordinate, if required */
134  if ( FLAGS_GET_M(pa->flags) ) pt.m = 0.0;
135 
136  }
137  else
138  {
139  /* If it's not an array, just don't handle it */
140  return LW_FAILURE;
141  }
142 
143  return ptarray_append_point(pa, &pt, LW_TRUE);
144 }
double x
Definition: liblwgeom.h:308
double m
Definition: liblwgeom.h:308
static void geojson_lwerror(char *msg, int error_code)
Definition: lwin_geojson.c:36
#define LW_FAILURE
Definition: liblwgeom.h:54
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
#define LW_FALSE
Definition: liblwgeom.h:52
uint8_t flags
Definition: liblwgeom.h:325
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
double z
Definition: liblwgeom.h:308
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
double y
Definition: liblwgeom.h:308
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55

Here is the call graph for this function:

Here is the caller graph for this function: