PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ parse_geojson_coord()

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

Definition at line 106 of file lwin_geojson.c.

107 {
108  POINT4D pt = {0, 0, 0, 0};
109 
110  if (json_object_get_type(poObj) == json_type_array)
111  {
112  json_object *poObjCoord = NULL;
113  const int nSize = json_object_array_length(poObj);
114  if (nSize < 2)
115  {
116  lwerror("Too few ordinates in GeoJSON");
117  return LW_FAILURE;
118  }
119 
120  /* Read X coordinate */
121  poObjCoord = json_object_array_get_idx(poObj, 0);
122  pt.x = json_object_get_double(poObjCoord);
123 
124  /* Read Y coordinate */
125  poObjCoord = json_object_array_get_idx(poObj, 1);
126  pt.y = json_object_get_double(poObjCoord);
127 
128  if (nSize > 2) /* should this be >= 3 ? */
129  {
130  /* Read Z coordinate */
131  poObjCoord = json_object_array_get_idx(poObj, 2);
132  pt.z = json_object_get_double(poObjCoord);
133  *hasz = LW_TRUE;
134  }
135  }
136  else
137  {
138  /* If it's not an array, just don't handle it */
139  lwerror("The 'coordinates' in GeoJSON are not sufficiently nested");
140  return LW_FAILURE;
141  }
142 
143  return ptarray_append_point(pa, &pt, LW_TRUE);
144 }
#define LW_FAILURE
Definition: liblwgeom.h:110
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:147
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
double x
Definition: liblwgeom.h:400
double z
Definition: liblwgeom.h:400
double y
Definition: liblwgeom.h:400

References LW_FAILURE, LW_TRUE, lwerror(), ptarray_append_point(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by parse_geojson_linestring(), parse_geojson_multilinestring(), parse_geojson_multipoint(), parse_geojson_point(), and parse_geojson_poly_rings().

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