PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwgeom_to_geojson()

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

Takes a GEOMETRY and returns a GeoJson representation.

Definition at line 48 of file lwout_geojson.c.

49 {
50  int type = geom->type;
51  GBOX *bbox = NULL;
52  GBOX tmp;
53 
55 
56  if (has_bbox)
57  {
58  /* Whether these are geography or geometry,
59  the GeoJSON expects a cartesian bounding box */
61  bbox = &tmp;
62  }
63 
64  switch (type)
65  {
66  case POINTTYPE:
67  return asgeojson_point((LWPOINT*)geom, srs, bbox, precision);
68  case LINETYPE:
69  return asgeojson_line((LWLINE*)geom, srs, bbox, precision);
70  case POLYGONTYPE:
71  return asgeojson_poly((LWPOLY*)geom, srs, bbox, precision);
72  case MULTIPOINTTYPE:
73  return asgeojson_multipoint((LWMPOINT*)geom, srs, bbox, precision);
74  case MULTILINETYPE:
75  return asgeojson_multiline((LWMLINE*)geom, srs, bbox, precision);
76  case MULTIPOLYGONTYPE:
77  return asgeojson_multipolygon((LWMPOLY*)geom, srs, bbox, precision);
78  case COLLECTIONTYPE:
79  return asgeojson_collection((LWCOLLECTION*)geom, srs, bbox, precision);
80  default:
81  lwerror("lwgeom_to_geojson: '%s' geometry type not supported",
82  lwtype_name(type));
83  }
84 
85  /* Never get here */
86  return NULL;
87 }
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: g_box.c:678
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
#define MULTILINETYPE
Definition: liblwgeom.h:89
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POLYGONTYPE
Definition: liblwgeom.h:87
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#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_line(const LWLINE *line, char *srs, GBOX *bbox, int precision)
type
Definition: ovdump.py:41

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

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

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