81 lwerror(
"lwgeom_to_geojson: '%s' geometry type not supported",
99 size =
sizeof(
"'crs':{'type':'name',");
100 size +=
sizeof(
"'properties':{'name':''}},");
101 size += strlen(srs) *
sizeof(char);
111 ptr += sprintf(ptr,
"\"crs\":{\"type\":\"name\",");
112 ptr += sprintf(ptr,
"\"properties\":{\"name\":\"%s\"}},", srs);
129 size =
sizeof(
"\"bbox\":[,,,],");
134 size =
sizeof(
"\"bbox\":[,,,,,],");
147 ptr += sprintf(ptr,
"\"bbox\":[%.*f,%.*f,%.*f,%.*f],",
151 ptr += sprintf(ptr,
"\"bbox\":[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f],",
170 size +=
sizeof(
"{'type':'Point',");
171 size +=
sizeof(
"'coordinates':}");
187 ptr += sprintf(ptr,
"{\"type\":\"Point\",");
191 ptr += sprintf(ptr,
"\"coordinates\":");
193 ptr += sprintf(ptr,
"[]");
195 ptr += sprintf(ptr,
"}");
223 size =
sizeof(
"{'type':'LineString',");
226 size +=
sizeof(
"'coordinates':[]}");
237 ptr += sprintf(ptr,
"{\"type\":\"LineString\",");
240 ptr += sprintf(ptr,
"\"coordinates\":[");
242 ptr += sprintf(ptr,
"]}");
272 size =
sizeof(
"{\"type\":\"Polygon\",");
275 size +=
sizeof(
"\"coordinates\":[");
276 for (i=0; i<poly->
nrings; i++)
279 size +=
sizeof(
"[]");
281 size +=
sizeof(
",") * i;
282 size +=
sizeof(
"]}");
293 ptr += sprintf(ptr,
"{\"type\":\"Polygon\",");
296 ptr += sprintf(ptr,
"\"coordinates\":[");
297 for (i=0; i<poly->
nrings; i++)
299 if (i) ptr += sprintf(ptr,
",");
300 ptr += sprintf(ptr,
"[");
302 ptr += sprintf(ptr,
"]");
304 ptr += sprintf(ptr,
"]}");
335 size =
sizeof(
"{'type':'MultiPoint',");
338 size +=
sizeof(
"'coordinates':[]}");
340 for (i=0; i<mpoint->
ngeoms; i++)
342 point = mpoint->
geoms[i];
345 size +=
sizeof(
",") * i;
357 ptr += sprintf(ptr,
"{\"type\":\"MultiPoint\",");
360 ptr += sprintf(ptr,
"\"coordinates\":[");
362 for (i=0; i<mpoint->
ngeoms; i++)
364 if (i) ptr += sprintf(ptr,
",");
365 point = mpoint->
geoms[i];
368 ptr += sprintf(ptr,
"]}");
370 return (ptr - output);
399 size =
sizeof(
"{'type':'MultiLineString',");
402 size +=
sizeof(
"'coordinates':[]}");
404 for (i=0 ; i<mline->
ngeoms; i++)
406 line = mline->
geoms[i];
408 size +=
sizeof(
"[]");
410 size +=
sizeof(
",") * i;
422 ptr += sprintf(ptr,
"{\"type\":\"MultiLineString\",");
425 ptr += sprintf(ptr,
"\"coordinates\":[");
427 for (i=0; i<mline->
ngeoms; i++)
429 if (i) ptr += sprintf(ptr,
",");
430 ptr += sprintf(ptr,
"[");
431 line = mline->
geoms[i];
433 ptr += sprintf(ptr,
"]");
436 ptr += sprintf(ptr,
"]}");
438 return (ptr - output);
467 size =
sizeof(
"{'type':'MultiPolygon',");
470 size +=
sizeof(
"'coordinates':[]}");
472 for (i=0; i < mpoly->
ngeoms; i++)
474 poly = mpoly->
geoms[i];
475 for (j=0 ; j <poly->
nrings ; j++)
478 size +=
sizeof(
"[]");
480 size +=
sizeof(
"[]");
482 size +=
sizeof(
",") * i;
483 size +=
sizeof(
"]}");
495 ptr += sprintf(ptr,
"{\"type\":\"MultiPolygon\",");
498 ptr += sprintf(ptr,
"\"coordinates\":[");
499 for (i=0; i<mpoly->
ngeoms; i++)
501 if (i) ptr += sprintf(ptr,
",");
502 ptr += sprintf(ptr,
"[");
503 poly = mpoly->
geoms[i];
504 for (j=0 ; j < poly->
nrings ; j++)
506 if (j) ptr += sprintf(ptr,
",");
507 ptr += sprintf(ptr,
"[");
509 ptr += sprintf(ptr,
"]");
511 ptr += sprintf(ptr,
"]");
513 ptr += sprintf(ptr,
"]}");
515 return (ptr - output);
544 size =
sizeof(
"{'type':'GeometryCollection',");
547 size +=
sizeof(
"'geometries':");
549 for (i=0; i<col->
ngeoms; i++)
551 subgeom = col->
geoms[i];
554 size +=
sizeof(
",") * i;
555 size +=
sizeof(
"]}");
567 ptr += sprintf(ptr,
"{\"type\":\"GeometryCollection\",");
570 ptr += sprintf(ptr,
"\"geometries\":[");
572 for (i=0; i<col->
ngeoms; i++)
574 if (i) ptr += sprintf(ptr,
",");
575 subgeom = col->
geoms[i];
579 ptr += sprintf(ptr,
"]}");
581 return (ptr - output);
632 lwerror(
"GeoJson: geometry not supported.");
673 lwerror(
"GeoJson: geometry not supported.");
704 if ( i ) ptr += sprintf(ptr,
",");
705 ptr += sprintf(ptr,
"[%s,%s]",
x,
y);
722 if ( i ) ptr += sprintf(ptr,
",");
723 ptr += sprintf(ptr,
"[%s,%s,%s]",
x,
y, z);
739 * 2 * pa->
npoints +
sizeof(
",[]");
742 * 3 * pa->
npoints +
sizeof(
",[]");
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
#define FLAGS_NDIMS(flags)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
void * lwalloc(size_t size)
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
#define OUT_MAX_DIGS_DOUBLE
#define OUT_DOUBLE_BUFFER_SIZE
int lwpoint_is_empty(const LWPOINT *point)
#define OUT_MAX_DOUBLE_PRECISION
int lwprint_double(double d, int maxdd, char *buf, size_t bufsize)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
static char * asgeojson_collection(const LWCOLLECTION *col, char *srs, GBOX *bbox, int precision)
static char * asgeojson_multipolygon(const LWMPOLY *mpoly, char *srs, GBOX *bbox, int precision)
static size_t asgeojson_geom_size(const LWGEOM *geom, GBOX *bbox, int precision)
static char * asgeojson_multipoint(const LWMPOINT *mpoint, char *srs, GBOX *bbox, int precision)
static size_t asgeojson_multiline_buf(const LWMLINE *mline, char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_multiline_size(const LWMLINE *mline, char *srs, GBOX *bbox, int precision)
Multiline Geometry.
static size_t asgeojson_poly_buf(const LWPOLY *poly, char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_multipoint_buf(const LWMPOINT *mpoint, char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_multipoint_size(const LWMPOINT *mpoint, char *srs, GBOX *bbox, int precision)
Multipoint Geometry.
static size_t asgeojson_line_buf(const LWLINE *line, char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_point_buf(const LWPOINT *point, char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_line_size(const LWLINE *line, char *srs, GBOX *bbox, int precision)
Line Geometry.
static size_t pointArray_geojson_size(POINTARRAY *pa, int precision)
Returns maximum size of rendered pointarray in bytes.
static char * asgeojson_point(const LWPOINT *point, char *srs, GBOX *bbox, int precision)
static char * asgeojson_poly(const LWPOLY *poly, char *srs, GBOX *bbox, int precision)
static size_t asgeojson_collection_buf(const LWCOLLECTION *col, char *srs, char *output, 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_srs_size(char *srs)
Handle SRS.
static size_t asgeojson_poly_size(const LWPOLY *poly, char *srs, GBOX *bbox, int precision)
Polygon Geometry.
static char * asgeojson_multiline(const LWMLINE *mline, char *srs, GBOX *bbox, int precision)
static size_t asgeojson_multipolygon_buf(const LWMPOLY *mpoly, char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_collection_size(const LWCOLLECTION *col, char *srs, GBOX *bbox, int precision)
Collection Geometry.
static char * asgeojson_line(const LWLINE *line, char *srs, GBOX *bbox, int precision)
static size_t asgeojson_bbox_size(int hasz, int precision)
Handle Bbox.
static size_t asgeojson_point_size(const LWPOINT *point, char *srs, GBOX *bbox, int precision)
Point Geometry.
char * lwgeom_to_geojson(const LWGEOM *geom, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
static size_t asgeojson_srs_buf(char *output, char *srs)
static size_t asgeojson_bbox_buf(char *output, GBOX *bbox, int hasz, int precision)
static size_t asgeojson_multipolygon_size(const LWMPOLY *mpoly, char *srs, GBOX *bbox, int precision)
MultiPolygon Geometry.