85 lwerror(
"lwgeom_to_geojson: '%s' geometry type not supported",
103 size =
sizeof(
"'crs':{'type':'name',");
104 size +=
sizeof(
"'properties':{'name':''}},");
105 size += strlen(srs) *
sizeof(char);
115 ptr += sprintf(ptr,
"\"crs\":{\"type\":\"name\",");
116 ptr += sprintf(ptr,
"\"properties\":{\"name\":\"%s\"}},", srs);
133 size =
sizeof(
"\"bbox\":[,,,],");
138 size =
sizeof(
"\"bbox\":[,,,,,],");
151 ptr += sprintf(ptr,
"\"bbox\":[%.*f,%.*f,%.*f,%.*f],",
155 ptr += sprintf(ptr,
"\"bbox\":[%.*f,%.*f,%.*f,%.*f,%.*f,%.*f],",
174 size +=
sizeof(
"{'type':'Point',");
175 size +=
sizeof(
"'coordinates':}");
191 ptr += sprintf(ptr,
"{\"type\":\"Point\",");
195 ptr += sprintf(ptr,
"\"coordinates\":");
197 ptr += sprintf(ptr,
"[]");
199 ptr += sprintf(ptr,
"}");
225 size =
sizeof(
"{'type':'Polygon',");
230 size +=
sizeof(
"'coordinates':[[]]}");
241 ptr += sprintf(ptr,
"{\"type\":\"Polygon\",");
246 ptr += sprintf(ptr,
"\"coordinates\":[[");
248 ptr += sprintf(ptr,
"]]}");
250 return (ptr - output);
275 size =
sizeof(
"{'type':'LineString',");
278 size +=
sizeof(
"'coordinates':[]}");
289 ptr += sprintf(ptr,
"{\"type\":\"LineString\",");
292 ptr += sprintf(ptr,
"\"coordinates\":[");
294 ptr += sprintf(ptr,
"]}");
305 size = asgeojson_line_size(line, srs, bbox,
precision);
307 asgeojson_line_buf(line, srs, output, bbox,
precision);
324 size =
sizeof(
"{\"type\":\"Polygon\",");
327 size +=
sizeof(
"\"coordinates\":[");
328 for (i=0; i<poly->
nrings; i++)
331 size +=
sizeof(
"[]");
333 size +=
sizeof(
",") * i;
334 size +=
sizeof(
"]}");
346 ptr += sprintf(ptr,
"{\"type\":\"Polygon\",");
349 ptr += sprintf(ptr,
"\"coordinates\":[");
350 for (i=0; i<poly->
nrings; i++)
352 if (i) ptr += sprintf(ptr,
",");
353 ptr += sprintf(ptr,
"[");
355 ptr += sprintf(ptr,
"]");
357 ptr += sprintf(ptr,
"]}");
368 size = asgeojson_poly_size(poly, srs, bbox,
precision);
370 asgeojson_poly_buf(poly, srs, output, bbox,
precision);
388 size =
sizeof(
"{'type':'MultiPoint',");
391 size +=
sizeof(
"'coordinates':[]}");
393 for (i=0; i<mpoint->
ngeoms; i++)
395 point = mpoint->
geoms[i];
398 size +=
sizeof(
",") * i;
410 ptr += sprintf(ptr,
"{\"type\":\"MultiPoint\",");
413 ptr += sprintf(ptr,
"\"coordinates\":[");
415 for (i=0; i<mpoint->
ngeoms; i++)
417 if (i) ptr += sprintf(ptr,
",");
418 point = mpoint->
geoms[i];
421 ptr += sprintf(ptr,
"]}");
423 return (ptr - output);
432 size = asgeojson_multipoint_size(mpoint, srs, bbox,
precision);
434 asgeojson_multipoint_buf(mpoint, srs, output, bbox,
precision);
452 size =
sizeof(
"{'type':'MultiLineString',");
455 size +=
sizeof(
"'coordinates':[]}");
457 for (i=0 ; i<mline->
ngeoms; i++)
459 line = mline->
geoms[i];
461 size +=
sizeof(
"[]");
463 size +=
sizeof(
",") * i;
469 asgeojson_multiline_buf(
const LWMLINE *mline,
char *srs,
char *output,
GBOX *bbox,
int precision)
475 ptr += sprintf(ptr,
"{\"type\":\"MultiLineString\",");
478 ptr += sprintf(ptr,
"\"coordinates\":[");
480 for (i=0; i<mline->
ngeoms; i++)
482 if (i) ptr += sprintf(ptr,
",");
483 ptr += sprintf(ptr,
"[");
484 line = mline->
geoms[i];
486 ptr += sprintf(ptr,
"]");
489 ptr += sprintf(ptr,
"]}");
491 return (ptr - output);
500 size = asgeojson_multiline_size(mline, srs, bbox,
precision);
502 asgeojson_multiline_buf(mline, srs, output, bbox,
precision);
520 size =
sizeof(
"{'type':'MultiPolygon',");
523 size +=
sizeof(
"'coordinates':[]}");
525 for (i=0; i < mpoly->
ngeoms; i++)
527 poly = mpoly->
geoms[i];
528 for (j=0 ; j <poly->
nrings ; j++)
531 size +=
sizeof(
"[]");
533 size +=
sizeof(
"[]");
535 size +=
sizeof(
",") * i;
536 size +=
sizeof(
"]}");
542 asgeojson_multipolygon_buf(
const LWMPOLY *mpoly,
char *srs,
char *output,
GBOX *bbox,
int precision)
548 ptr += sprintf(ptr,
"{\"type\":\"MultiPolygon\",");
551 ptr += sprintf(ptr,
"\"coordinates\":[");
552 for (i=0; i<mpoly->
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);
577 size = asgeojson_multipolygon_size(mpoly, srs, bbox,
precision);
579 asgeojson_multipolygon_buf(mpoly, srs, output, bbox,
precision);
597 size =
sizeof(
"{'type':'GeometryCollection',");
600 size +=
sizeof(
"'geometries':");
602 for (i=0; i<col->
ngeoms; i++)
604 subgeom = col->
geoms[i];
607 size +=
sizeof(
",") * i;
608 size +=
sizeof(
"]}");
620 ptr += sprintf(ptr,
"{\"type\":\"GeometryCollection\",");
623 ptr += sprintf(ptr,
"\"geometries\":[");
625 for (i=0; i<col->
ngeoms; i++)
627 if (i) ptr += sprintf(ptr,
",");
628 subgeom = col->
geoms[i];
632 ptr += sprintf(ptr,
"]}");
634 return (ptr - output);
643 size = asgeojson_collection_size(col, srs, bbox,
precision);
645 asgeojson_collection_buf(col, srs, output, 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.");
747 if ( i ) ptr += sprintf(ptr,
",");
748 ptr += sprintf(ptr,
"[%s,%s]",
x,
y);
764 if ( i ) ptr += sprintf(ptr,
",");
765 ptr += sprintf(ptr,
"[%s,%s,%s]",
x,
y, z);
781 * 2 * pa->
npoints +
sizeof(
",[]");
784 * 3 * pa->
npoints +
sizeof(
",[]");
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.
void * lwalloc(size_t size)
#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 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 POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
static size_t asgeojson_triangle_size(const LWTRIANGLE *tri, char *srs, GBOX *bbox, int precision)
Triangle Geometry.
static char * asgeojson_line(const LWLINE *line, char *srs, GBOX *bbox, int precision)
static size_t asgeojson_geom_size(const LWGEOM *geom, GBOX *bbox, int precision)
static size_t asgeojson_point_buf(const LWPOINT *point, char *srs, char *output, GBOX *bbox, int precision)
static char * asgeojson_multipoint(const LWMPOINT *mpoint, char *srs, GBOX *bbox, int precision)
static size_t pointArray_geojson_size(POINTARRAY *pa, int precision)
static char * asgeojson_point(const LWPOINT *point, 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 char * asgeojson_multiline(const LWMLINE *mline, char *srs, GBOX *bbox, int precision)
static size_t asgeojson_srs_size(char *srs)
Handle SRS.
static char * asgeojson_poly(const LWPOLY *poly, char *srs, GBOX *bbox, int precision)
static char * asgeojson_multipolygon(const LWMPOLY *mpoly, char *srs, GBOX *bbox, int precision)
static char * asgeojson_collection(const LWCOLLECTION *col, 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_triangle_buf(const LWTRIANGLE *tri, char *srs, char *output, GBOX *bbox, int precision)
static size_t asgeojson_bbox_buf(char *output, GBOX *bbox, int hasz, int precision)
static char * asgeojson_triangle(const LWTRIANGLE *tri, char *srs, GBOX *bbox, int precision)