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

Definition at line 83 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().

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