PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 34 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: