PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWGEOM* GEOS2LWGEOM ( const GEOSGeometry *  geom,
char  want3d 
)

Definition at line 111 of file liblwgeom/lwgeom_geos.c.

References GEOS2LWGEOM(), lwalloc(), lwcollection_construct(), LWDEBUG, lwerror(), lwline_construct(), lwline_construct_empty(), lwpoint_construct(), lwpoint_construct_empty(), lwpoly_construct(), lwpoly_construct_empty(), ptarray_from_GEOSCoordSeq(), and SRID_UNKNOWN.

Referenced by convexhull(), GEOS2LWGEOM(), GEOS2POSTGIS(), GEOSARRAY2LWGEOM(), isvaliddetail(), lwgeom_buildarea(), lwgeom_centroid(), lwgeom_clip_by_rect(), lwgeom_delaunay_triangulation(), lwgeom_difference(), lwgeom_extract_unique_endpoints(), LWGEOM_GEOS_buildArea(), LWGEOM_GEOS_makeValid(), LWGEOM_GEOS_makeValidPolygon(), LWGEOM_GEOS_nodeLines(), lwgeom_geos_noop(), lwgeom_intersection(), lwgeom_linemerge(), lwgeom_make_valid(), lwgeom_node(), lwgeom_normalize(), lwgeom_offsetcurve(), lwgeom_sharedpaths(), lwgeom_snap(), lwgeom_symdifference(), lwgeom_unaryunion(), lwgeom_union(), lwgeom_voronoi_diagram(), lwline_split_by_line(), lwpoly_split_by_line(), and rt_raster_surface().

112 {
113  int type = GEOSGeomTypeId(geom) ;
114  int hasZ;
115  int SRID = GEOSGetSRID(geom);
116 
117  /* GEOS's 0 is equivalent to our unknown as for SRID values */
118  if ( SRID == 0 ) SRID = SRID_UNKNOWN;
119 
120  if ( want3d )
121  {
122  hasZ = GEOSHasZ(geom);
123  if ( ! hasZ )
124  {
125  LWDEBUG(3, "Geometry has no Z, won't provide one");
126 
127  want3d = 0;
128  }
129  }
130 
131 /*
132  if ( GEOSisEmpty(geom) )
133  {
134  return (LWGEOM*)lwcollection_construct_empty(COLLECTIONTYPE, SRID, want3d, 0);
135  }
136 */
137 
138  switch (type)
139  {
140  const GEOSCoordSequence *cs;
141  POINTARRAY *pa, **ppaa;
142  const GEOSGeometry *g;
143  LWGEOM **geoms;
144  uint32_t i, ngeoms;
145 
146  case GEOS_POINT:
147  LWDEBUG(4, "lwgeom_from_geometry: it's a Point");
148  cs = GEOSGeom_getCoordSeq(geom);
149  if ( GEOSisEmpty(geom) )
150  return (LWGEOM*)lwpoint_construct_empty(SRID, want3d, 0);
151  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
152  return (LWGEOM *)lwpoint_construct(SRID, NULL, pa);
153 
154  case GEOS_LINESTRING:
155  case GEOS_LINEARRING:
156  LWDEBUG(4, "lwgeom_from_geometry: it's a LineString or LinearRing");
157  if ( GEOSisEmpty(geom) )
158  return (LWGEOM*)lwline_construct_empty(SRID, want3d, 0);
159 
160  cs = GEOSGeom_getCoordSeq(geom);
161  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
162  return (LWGEOM *)lwline_construct(SRID, NULL, pa);
163 
164  case GEOS_POLYGON:
165  LWDEBUG(4, "lwgeom_from_geometry: it's a Polygon");
166  if ( GEOSisEmpty(geom) )
167  return (LWGEOM*)lwpoly_construct_empty(SRID, want3d, 0);
168  ngeoms = GEOSGetNumInteriorRings(geom);
169  ppaa = lwalloc(sizeof(POINTARRAY *)*(ngeoms+1));
170  g = GEOSGetExteriorRing(geom);
171  cs = GEOSGeom_getCoordSeq(g);
172  ppaa[0] = ptarray_from_GEOSCoordSeq(cs, want3d);
173  for (i=0; i<ngeoms; i++)
174  {
175  g = GEOSGetInteriorRingN(geom, i);
176  cs = GEOSGeom_getCoordSeq(g);
177  ppaa[i+1] = ptarray_from_GEOSCoordSeq(cs,
178  want3d);
179  }
180  return (LWGEOM *)lwpoly_construct(SRID, NULL,
181  ngeoms+1, ppaa);
182 
183  case GEOS_MULTIPOINT:
184  case GEOS_MULTILINESTRING:
185  case GEOS_MULTIPOLYGON:
186  case GEOS_GEOMETRYCOLLECTION:
187  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
188 
189  ngeoms = GEOSGetNumGeometries(geom);
190  geoms = NULL;
191  if ( ngeoms )
192  {
193  geoms = lwalloc(sizeof(LWGEOM *)*ngeoms);
194  for (i=0; i<ngeoms; i++)
195  {
196  g = GEOSGetGeometryN(geom, i);
197  geoms[i] = GEOS2LWGEOM(g, want3d);
198  }
199  }
200  return (LWGEOM *)lwcollection_construct(type,
201  SRID, NULL, ngeoms, geoms);
202 
203  default:
204  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
205  return NULL;
206  }
207 }
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
unsigned int uint32_t
Definition: uthash.h:78
LWGEOM * geom
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:159
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
void * lwalloc(size_t size)
Definition: lwutil.c:229
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, char want3d)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190

Here is the call graph for this function:

Here is the caller graph for this function: