PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lwgeom_to_geojson()

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

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

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, POINTTYPE, POLYGONTYPE, precision, TINTYPE, TRIANGLETYPE, LWGEOM::type, and ovdump::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: