PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwgeom_to_geojson()

char * lwgeom_to_geojson ( const LWGEOM geo,
char *  srs,
int  precision,
int  has_bbox 
)
extern

Takes a GEOMETRY and returns a GeoJson representation.

Definition at line 49 of file lwout_geojson.c.

50{
51 int type = geom->type;
52 GBOX *bbox = NULL;
53 GBOX tmp;
54
56
57 if (has_bbox)
58 {
59 /* Whether these are geography or geometry,
60 the GeoJSON expects a cartesian bounding box */
62 bbox = &tmp;
63 }
64
65 switch (type)
66 {
67 case POINTTYPE:
68 return asgeojson_point((LWPOINT*)geom, srs, bbox, precision);
69 case LINETYPE:
70 return asgeojson_line((LWLINE*)geom, srs, bbox, precision);
71 case POLYGONTYPE:
72 return asgeojson_poly((LWPOLY*)geom, srs, bbox, precision);
73 case MULTIPOINTTYPE:
74 return asgeojson_multipoint((LWMPOINT*)geom, srs, bbox, precision);
75 case MULTILINETYPE:
76 return asgeojson_multiline((LWMLINE*)geom, srs, bbox, precision);
78 return asgeojson_multipolygon((LWMPOLY*)geom, srs, bbox, precision);
79 case TRIANGLETYPE:
80 return asgeojson_triangle((LWTRIANGLE *)geom, srs, bbox, precision);
81 case TINTYPE:
82 case COLLECTIONTYPE:
83 return asgeojson_collection((LWCOLLECTION*)geom, srs, bbox, precision);
84 default:
85 lwerror("lwgeom_to_geojson: '%s' geometry type not supported",
86 lwtype_name(type));
87 }
88
89 /* Never get here */
90 return NULL;
91}
static uint8_t precision
Definition cu_in_twkb.c:25
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition gbox.c:740
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
#define COLLECTIONTYPE
Definition liblwgeom.h:122
#define MULTILINETYPE
Definition liblwgeom.h:120
#define LINETYPE
Definition liblwgeom.h:117
#define MULTIPOINTTYPE
Definition liblwgeom.h:119
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:116
#define TINTYPE
Definition liblwgeom.h:130
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:121
#define POLYGONTYPE
Definition liblwgeom.h:118
#define TRIANGLETYPE
Definition liblwgeom.h:129
#define OUT_MAX_DOUBLE_PRECISION
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition lwutil.c:190
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 char * asgeojson_multipoint(const LWMPOINT *mpoint, char *srs, GBOX *bbox, int precision)
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 char * asgeojson_multiline(const LWMLINE *mline, char *srs, GBOX *bbox, int precision)
static char * asgeojson_triangle(const LWTRIANGLE *tri, char *srs, GBOX *bbox, int precision)
static char * asgeojson_line(const LWLINE *line, char *srs, GBOX *bbox, int precision)

References asgeojson_collection(), asgeojson_line(), asgeojson_multiline(), asgeojson_multipoint(), asgeojson_multipolygon(), asgeojson_point(), asgeojson_poly(), asgeojson_triangle(), COLLECTIONTYPE, LINETYPE, lwerror(), lwgeom_calculate_gbox_cartesian(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, OUT_MAX_DOUBLE_PRECISION, POINTTYPE, POLYGONTYPE, precision, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by do_geojson_test(), do_geojson_unsupported(), geography_as_geojson(), geometry_to_json(), geometry_to_jsonb(), and LWGEOM_asGeoJson().

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