PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ parse_geojson_coord()

static int parse_geojson_coord ( json_object *  poObj,
int *  hasz,
POINTARRAY pa 
)
static

Definition at line 103 of file lwin_geojson.c.

104 {
105  POINT4D pt;
106 
107  LWDEBUGF(3, "parse_geojson_coord called for object %s.", json_object_to_json_string( poObj ) );
108 
109  if( json_type_array == json_object_get_type( poObj ) )
110  {
111 
112  json_object* poObjCoord = NULL;
113  const int nSize = json_object_array_length( poObj );
114  LWDEBUGF(3, "parse_geojson_coord called for array size %d.", nSize );
115 
116  if ( nSize < 2 )
117  {
118  geojson_lwerror("Too few ordinates in GeoJSON", 4);
119  return LW_FAILURE;
120  }
121 
122  /* Read X coordinate */
123  poObjCoord = json_object_array_get_idx( poObj, 0 );
124  pt.x = json_object_get_double( poObjCoord );
125  LWDEBUGF(3, "parse_geojson_coord pt.x = %f.", pt.x );
126 
127  /* Read Y coordinate */
128  poObjCoord = json_object_array_get_idx( poObj, 1 );
129  pt.y = json_object_get_double( poObjCoord );
130  LWDEBUGF(3, "parse_geojson_coord pt.y = %f.", pt.y );
131 
132  if( nSize > 2 ) /* should this be >= 3 ? */
133  {
134  /* Read Z coordinate */
135  poObjCoord = json_object_array_get_idx( poObj, 2 );
136  pt.z = json_object_get_double( poObjCoord );
137  LWDEBUGF(3, "parse_geojson_coord pt.z = %f.", pt.z );
138  *hasz = LW_TRUE;
139  }
140  else if ( nSize == 2 )
141  {
142  *hasz = LW_FALSE;
143  /* Initialize Z coordinate, if required */
144  if ( FLAGS_GET_Z(pa->flags) ) pt.z = 0.0;
145  }
146  else
147  {
148  /* TODO: should we account for nSize > 3 ? */
149  /* more than 3 coordinates, we're just dropping dimensions here... */
150  }
151 
152  /* Initialize M coordinate, if required */
153  if ( FLAGS_GET_M(pa->flags) ) pt.m = 0.0;
154 
155  }
156  else
157  {
158  /* If it's not an array, just don't handle it */
159  return LW_FAILURE;
160  }
161 
162  return ptarray_append_point(pa, &pt, LW_TRUE);
163 }
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_FAILURE
Definition: liblwgeom.h:79
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
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_FALSE,...
Definition: ptarray.c:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
static void geojson_lwerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwin_geojson.c:55
double m
Definition: liblwgeom.h:355
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
uint8_t flags
Definition: liblwgeom.h:372

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().

Here is the call graph for this function:
Here is the caller graph for this function: