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);
373 uint32_t i, ngeoms = mpoint->
ngeoms;
375 size =
sizeof(
"{'type':'MultiPoint',");
378 size +=
sizeof(
"'coordinates':[]}");
383 for (i=0; i<ngeoms; i++)
385 point = mpoint->geoms[i];
388 size +=
sizeof(
",") * i;
394 asgeojson_multipoint_buf(
const LWMPOINT *mpoint,
const char *srs,
char *output,
GBOX *bbox,
int precision)
397 uint32_t i, ngeoms = mpoint->
ngeoms;
400 ptr += sprintf(ptr,
"{\"type\":\"MultiPoint\",");
403 ptr += sprintf(ptr,
"\"coordinates\":[");
408 for (i=0; i<ngeoms; i++)
410 if (i) ptr += sprintf(ptr,
",");
411 point = mpoint->geoms[i];
414 ptr += sprintf(ptr,
"]}");
416 return (ptr - output);
422 uint32_t size = asgeojson_multipoint_size(mpoint, srs, bbox,
precision);
424 size = asgeojson_multipoint_buf(mpoint, srs, output->
data, bbox,
precision);
440 uint32_t i, ngeoms = mline->
ngeoms;
442 size =
sizeof(
"{'type':'MultiLineString',");
445 size +=
sizeof(
"'coordinates':[]}");
450 for (i=0 ; i<ngeoms; i++)
452 line = mline->geoms[i];
454 size +=
sizeof(
"[]");
456 size +=
sizeof(
",") * i;
462 asgeojson_multiline_buf(
const LWMLINE *mline,
const char *srs,
char *output,
GBOX *bbox,
int precision)
465 uint32_t i, ngeoms = mline->
ngeoms;
468 ptr += sprintf(ptr,
"{\"type\":\"MultiLineString\",");
471 ptr += sprintf(ptr,
"\"coordinates\":[");
476 for (i=0; i<ngeoms; i++)
478 if (i) ptr += sprintf(ptr,
",");
479 ptr += sprintf(ptr,
"[");
480 line = mline->geoms[i];
482 ptr += sprintf(ptr,
"]");
485 ptr += sprintf(ptr,
"]}");
487 return (ptr - output);
493 uint32_t size = asgeojson_multiline_size(mline, srs, bbox,
precision);
495 size = asgeojson_multiline_buf(mline, srs, output->
data, bbox,
precision);
511 uint32_t i, j, ngeoms = mpoly->
ngeoms;
513 size =
sizeof(
"{'type':'MultiPolygon',");
516 size +=
sizeof(
"'coordinates':[]}");
521 for (i=0; i < ngeoms; i++)
523 poly = mpoly->geoms[i];
524 for (j=0 ; j <poly->
nrings ; j++)
527 size +=
sizeof(
"[]");
529 size +=
sizeof(
"[]");
531 size +=
sizeof(
",") * i;
532 size +=
sizeof(
"]}");
538 asgeojson_multipolygon_buf(
const LWMPOLY *mpoly,
const char *srs,
char *output,
GBOX *bbox,
int precision)
541 uint32_t i, j, ngeoms = mpoly->
ngeoms;
544 ptr += sprintf(ptr,
"{\"type\":\"MultiPolygon\",");
547 ptr += sprintf(ptr,
"\"coordinates\":[");
552 for (i=0; i < ngeoms; i++)
554 if (i) ptr += sprintf(ptr,
",");
555 ptr += sprintf(ptr,
"[");
556 poly = mpoly->geoms[i];
557 for (j=0 ; j < poly->
nrings ; j++)
559 if (j) ptr += sprintf(ptr,
",");
560 ptr += sprintf(ptr,
"[");
562 ptr += sprintf(ptr,
"]");
564 ptr += sprintf(ptr,
"]");
566 ptr += sprintf(ptr,
"]}");
568 return (ptr - output);
574 uint32_t size = asgeojson_multipolygon_size(mpoly, srs, bbox,
precision);
576 size = asgeojson_multipolygon_buf(mpoly, srs, output->
data, bbox,
precision);
590 uint32_t i, ngeoms = col->
ngeoms;
594 size =
sizeof(
"{'type':'GeometryCollection',");
597 size +=
sizeof(
"'geometries':");
602 for (i=0; i<ngeoms; i++)
604 subgeom = col->geoms[i];
607 size +=
sizeof(
",") * i;
608 size +=
sizeof(
"]}");
616 uint32_t i, ngeoms = col->
ngeoms;
620 ptr += sprintf(ptr,
"{\"type\":\"GeometryCollection\",");
623 ptr += sprintf(ptr,
"\"geometries\":[");
628 for (i=0; i<ngeoms; i++)
630 if (i) ptr += sprintf(ptr,
",");
631 subgeom = col->geoms[i];
635 ptr += sprintf(ptr,
"]}");
637 return (ptr - output);
643 uint32_t size = asgeojson_collection_size(col, srs, bbox,
precision);
645 size = asgeojson_collection_buf(col, srs, output->
data, bbox,
precision);
672 lwerror(
"GeoJson: geometry not supported.");
711 ptr += asgeojson_multipolygon_buf((
LWMPOLY*)geom, NULL, ptr, bbox,
precision);
716 lwerror(
"GeoJson: geometry not supported.");
729 for (uint32_t i = 0; i < pa->
npoints; i++)
750 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 int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
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)