83 lwerror(
"lwgeom_to_geojson: '%s' geometry type not supported",
101 size =
sizeof(
"'crs':{'type':'name',");
102 size +=
sizeof(
"'properties':{'name':''}},");
103 size += strlen(srs) *
sizeof(char);
113 ptr += sprintf(ptr,
"\"crs\":{\"type\":\"name\",");
114 ptr += sprintf(ptr,
"\"properties\":{\"name\":\"%s\"}},", srs);
131 size =
sizeof(
"\"bbox\":[,,,],");
136 size =
sizeof(
"\"bbox\":[,,,,,],");
149 ptr += sprintf(ptr,
"\"bbox\":[%.*f,%.*f,%.*f,%.*f],",
153 ptr += sprintf(ptr,
"\"bbox\":[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f],",
172 size +=
sizeof(
"{'type':'Point',");
173 size +=
sizeof(
"'coordinates':}");
189 ptr += sprintf(ptr,
"{\"type\":\"Point\",");
193 ptr += sprintf(ptr,
"\"coordinates\":");
195 ptr += sprintf(ptr,
"[]");
197 ptr += sprintf(ptr,
"}");
221 size =
sizeof(
"{'type':'Polygon',");
226 size +=
sizeof(
"'coordinates':[[]]}");
237 ptr += sprintf(ptr,
"{\"type\":\"Polygon\",");
242 ptr += sprintf(ptr,
"\"coordinates\":[[");
244 ptr += sprintf(ptr,
"]]}");
246 return (ptr - output);
268 size =
sizeof(
"{'type':'LineString',");
271 size +=
sizeof(
"'coordinates':[]}");
278 asgeojson_line_buf(
const LWLINE *line,
const char *srs,
char *output,
GBOX *bbox,
int precision)
282 ptr += sprintf(ptr,
"{\"type\":\"LineString\",");
285 ptr += sprintf(ptr,
"\"coordinates\":[");
287 ptr += sprintf(ptr,
"]}");
295 uint32_t size = asgeojson_line_size(line, srs, bbox,
precision);
297 size = asgeojson_line_buf(line, srs, output->
data, bbox,
precision);
314 size =
sizeof(
"{\"type\":\"Polygon\",");
317 size +=
sizeof(
"\"coordinates\":[");
318 for (i=0; i<poly->
nrings; i++)
321 size +=
sizeof(
"[]");
323 size +=
sizeof(
",") * i;
324 size +=
sizeof(
"]}");
330 asgeojson_poly_buf(
const LWPOLY *poly,
const char *srs,
char *output,
GBOX *bbox,
int precision)
336 ptr += sprintf(ptr,
"{\"type\":\"Polygon\",");
339 ptr += sprintf(ptr,
"\"coordinates\":[");
340 for (i=0; i<poly->
nrings; i++)
342 if (i) ptr += sprintf(ptr,
",");
343 ptr += sprintf(ptr,
"[");
345 ptr += sprintf(ptr,
"]");
347 ptr += sprintf(ptr,
"]}");
355 uint32_t size = asgeojson_poly_size(poly, srs, bbox,
precision);
357 size = asgeojson_poly_buf(poly, srs, output->
data, bbox,
precision);
375 size =
sizeof(
"{'type':'MultiPoint',");
378 size +=
sizeof(
"'coordinates':[]}");
380 for (i=0; i<mpoint->
ngeoms; i++)
382 point = mpoint->
geoms[i];
385 size +=
sizeof(
",") * i;
391 asgeojson_multipoint_buf(
const LWMPOINT *mpoint,
const char *srs,
char *output,
GBOX *bbox,
int precision)
397 ptr += sprintf(ptr,
"{\"type\":\"MultiPoint\",");
400 ptr += sprintf(ptr,
"\"coordinates\":[");
402 for (i=0; i<mpoint->
ngeoms; i++)
404 if (i) ptr += sprintf(ptr,
",");
405 point = mpoint->
geoms[i];
408 ptr += sprintf(ptr,
"]}");
410 return (ptr - output);
416 uint32_t size = asgeojson_multipoint_size(mpoint, srs, bbox,
precision);
418 size = asgeojson_multipoint_buf(mpoint, srs, output->
data, bbox,
precision);
436 size =
sizeof(
"{'type':'MultiLineString',");
439 size +=
sizeof(
"'coordinates':[]}");
441 for (i=0 ; i<mline->
ngeoms; i++)
443 line = mline->
geoms[i];
445 size +=
sizeof(
"[]");
447 size +=
sizeof(
",") * i;
453 asgeojson_multiline_buf(
const LWMLINE *mline,
const char *srs,
char *output,
GBOX *bbox,
int precision)
459 ptr += sprintf(ptr,
"{\"type\":\"MultiLineString\",");
462 ptr += sprintf(ptr,
"\"coordinates\":[");
464 for (i=0; i<mline->
ngeoms; i++)
466 if (i) ptr += sprintf(ptr,
",");
467 ptr += sprintf(ptr,
"[");
468 line = mline->
geoms[i];
470 ptr += sprintf(ptr,
"]");
473 ptr += sprintf(ptr,
"]}");
475 return (ptr - output);
481 uint32_t size = asgeojson_multiline_size(mline, srs, bbox,
precision);
483 size = asgeojson_multiline_buf(mline, srs, output->
data, bbox,
precision);
501 size =
sizeof(
"{'type':'MultiPolygon',");
504 size +=
sizeof(
"'coordinates':[]}");
506 for (i=0; i < mpoly->
ngeoms; i++)
508 poly = mpoly->
geoms[i];
509 for (j=0 ; j <poly->
nrings ; j++)
512 size +=
sizeof(
"[]");
514 size +=
sizeof(
"[]");
516 size +=
sizeof(
",") * i;
517 size +=
sizeof(
"]}");
523 asgeojson_multipolygon_buf(
const LWMPOLY *mpoly,
const char *srs,
char *output,
GBOX *bbox,
int precision)
529 ptr += sprintf(ptr,
"{\"type\":\"MultiPolygon\",");
532 ptr += sprintf(ptr,
"\"coordinates\":[");
533 for (i=0; i<mpoly->
ngeoms; i++)
535 if (i) ptr += sprintf(ptr,
",");
536 ptr += sprintf(ptr,
"[");
537 poly = mpoly->
geoms[i];
538 for (j=0 ; j < poly->
nrings ; j++)
540 if (j) ptr += sprintf(ptr,
",");
541 ptr += sprintf(ptr,
"[");
543 ptr += sprintf(ptr,
"]");
545 ptr += sprintf(ptr,
"]");
547 ptr += sprintf(ptr,
"]}");
549 return (ptr - output);
555 uint32_t size = asgeojson_multipolygon_size(mpoly, srs, bbox,
precision);
557 size = asgeojson_multipolygon_buf(mpoly, srs, output->
data, bbox,
precision);
575 size =
sizeof(
"{'type':'GeometryCollection',");
578 size +=
sizeof(
"'geometries':");
580 for (i=0; i<col->
ngeoms; i++)
582 subgeom = col->
geoms[i];
585 size +=
sizeof(
",") * i;
586 size +=
sizeof(
"]}");
598 ptr += sprintf(ptr,
"{\"type\":\"GeometryCollection\",");
601 ptr += sprintf(ptr,
"\"geometries\":[");
603 for (i=0; i<col->
ngeoms; i++)
605 if (i) ptr += sprintf(ptr,
",");
606 subgeom = col->
geoms[i];
610 ptr += sprintf(ptr,
"]}");
612 return (ptr - output);
618 uint32_t size = asgeojson_collection_size(col, srs, bbox,
precision);
620 size = asgeojson_collection_buf(col, srs, output->
data, bbox,
precision);
647 lwerror(
"GeoJson: geometry not supported.");
686 ptr += asgeojson_multipolygon_buf((
LWMPOLY*)geom, NULL, ptr, bbox,
precision);
691 lwerror(
"GeoJson: geometry not supported.");
704 for (uint32_t i = 0; i < pa->
npoints; i++)
725 for (uint32_t i = 0; i < pa->
npoints; i++)
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
#define FLAGS_NDIMS(flags)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define LWSIZE_SET(varsize, len)
void * lwalloc(size_t size)
#define OUT_MAX_BYTES_DOUBLE
int lwpoint_is_empty(const LWPOINT *point)
int lwprint_double(double d, int maxdd, char *buf)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
static const POINT3D * getPoint3d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT3D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
static size_t asgeojson_srs_buf(char *output, const char *srs)
static size_t asgeojson_geom_size(const LWGEOM *geom, GBOX *bbox, int precision)
static size_t asgeojson_point_buf(const LWPOINT *point, const char *srs, char *output, GBOX *bbox, int precision)
static lwvarlena_t * asgeojson_multipolygon(const LWMPOLY *mpoly, const char *srs, GBOX *bbox, int precision)
static size_t pointArray_geojson_size(POINTARRAY *pa, int precision)
static lwvarlena_t * asgeojson_triangle(const LWTRIANGLE *tri, const char *srs, GBOX *bbox, int precision)
static size_t asgeojson_srs_size(const char *srs)
Handle SRS.
static lwvarlena_t * asgeojson_point(const LWPOINT *point, const char *srs, GBOX *bbox, int precision)
static size_t asgeojson_geom_buf(const LWGEOM *geom, char *output, GBOX *bbox, int precision)
static size_t pointArray_to_geojson(POINTARRAY *pa, char *buf, int precision)
static size_t asgeojson_point_size(const LWPOINT *point, const char *srs, GBOX *bbox, int precision)
Point Geometry.
static lwvarlena_t * asgeojson_poly(const LWPOLY *poly, const char *srs, GBOX *bbox, int precision)
static lwvarlena_t * asgeojson_line(const LWLINE *line, const char *srs, GBOX *bbox, int precision)
static size_t asgeojson_triangle_size(const LWTRIANGLE *tri, const char *srs, GBOX *bbox, int precision)
Triangle Geometry.
lwvarlena_t * lwgeom_to_geojson(const LWGEOM *geom, const char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
static lwvarlena_t * asgeojson_multipoint(const LWMPOINT *mpoint, const char *srs, GBOX *bbox, int precision)
static size_t asgeojson_bbox_size(int hasz, int precision)
Handle Bbox.
static lwvarlena_t * asgeojson_collection(const LWCOLLECTION *col, const char *srs, GBOX *bbox, int precision)
static size_t asgeojson_triangle_buf(const LWTRIANGLE *tri, const char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_bbox_buf(char *output, GBOX *bbox, int hasz, int precision)
static lwvarlena_t * asgeojson_multiline(const LWMLINE *mline, const char *srs, GBOX *bbox, int precision)