PostGIS  2.1.10dev-r@@SVN_REVISION@@
char* lwgeom_to_geojson ( const LWGEOM geom,
char *  srs,
int  precision,
int  has_bbox 
)

Takes a GEOMETRY and returns a GeoJson representation.

Definition at line 35 of file lwout_geojson.c.

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, and LWGEOM::type.

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

36 {
37  int type = geom->type;
38  GBOX *bbox = NULL;
39  GBOX tmp;
40 
41  if ( precision > OUT_MAX_DOUBLE_PRECISION ) precision = OUT_MAX_DOUBLE_PRECISION;
42 
43  if (has_bbox)
44  {
45  /* Whether these are geography or geometry,
46  the GeoJSON expects a cartesian bounding box */
48  bbox = &tmp;
49  }
50 
51  switch (type)
52  {
53  case POINTTYPE:
54  return asgeojson_point((LWPOINT*)geom, srs, bbox, precision);
55  case LINETYPE:
56  return asgeojson_line((LWLINE*)geom, srs, bbox, precision);
57  case POLYGONTYPE:
58  return asgeojson_poly((LWPOLY*)geom, srs, bbox, precision);
59  case MULTIPOINTTYPE:
60  return asgeojson_multipoint((LWMPOINT*)geom, srs, bbox, precision);
61  case MULTILINETYPE:
62  return asgeojson_multiline((LWMLINE*)geom, srs, bbox, precision);
63  case MULTIPOLYGONTYPE:
64  return asgeojson_multipolygon((LWMPOLY*)geom, srs, bbox, precision);
65  case COLLECTIONTYPE:
66  return asgeojson_collection((LWCOLLECTION*)geom, srs, bbox, precision);
67  default:
68  lwerror("lwgeom_to_geojson: '%s' geometry type not supported",
69  lwtype_name(type));
70  }
71 
72  /* Never get here */
73  return NULL;
74 }
#define LINETYPE
Definition: liblwgeom.h:61
static char * asgeojson_collection(const LWCOLLECTION *col, char *srs, GBOX *bbox, int precision)
static char * asgeojson_multipoint(const LWMPOINT *mpoint, char *srs, GBOX *bbox, int precision)
#define OUT_MAX_DOUBLE_PRECISION
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
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)
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)
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
static char * asgeojson_multipolygon(const LWMPOLY *mpoly, char *srs, GBOX *bbox, int precision)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
uint8_t type
Definition: liblwgeom.h:352
#define MULTILINETYPE
Definition: liblwgeom.h:64
#define COLLECTIONTYPE
Definition: liblwgeom.h:66
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:607

Here is the call graph for this function:

Here is the caller graph for this function: