PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ parse_geojson_coord()

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

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

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