PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ GEOS2LWGEOM()

LWGEOM* GEOS2LWGEOM ( const GEOSGeometry *  geom,
uint8_t  want3d 
)

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

199 {
200  int type = GEOSGeomTypeId(geom);
201  int SRID = GEOSGetSRID(geom);
202 
203  /* GEOS's 0 is equivalent to our unknown as for SRID values */
204  if (SRID == 0) SRID = SRID_UNKNOWN;
205 
206  if (want3d && !GEOSHasZ(geom))
207  {
208  LWDEBUG(3, "Geometry has no Z, won't provide one");
209  want3d = 0;
210  }
211 
212  switch (type)
213  {
214  const GEOSCoordSequence* cs;
215  POINTARRAY *pa, **ppaa;
216  const GEOSGeometry* g;
217  LWGEOM** geoms;
218  uint32_t i, ngeoms;
219 
220  case GEOS_POINT:
221  LWDEBUG(4, "lwgeom_from_geometry: it's a Point");
222  cs = GEOSGeom_getCoordSeq(geom);
223  if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoint_construct_empty(SRID, want3d, 0);
224  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
225  return (LWGEOM*)lwpoint_construct(SRID, NULL, pa);
226 
227  case GEOS_LINESTRING:
228  case GEOS_LINEARRING:
229  LWDEBUG(4, "lwgeom_from_geometry: it's a LineString or LinearRing");
230  if (GEOSisEmpty(geom)) return (LWGEOM*)lwline_construct_empty(SRID, want3d, 0);
231 
232  cs = GEOSGeom_getCoordSeq(geom);
233  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
234  return (LWGEOM*)lwline_construct(SRID, NULL, pa);
235 
236  case GEOS_POLYGON:
237  LWDEBUG(4, "lwgeom_from_geometry: it's a Polygon");
238  if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoly_construct_empty(SRID, want3d, 0);
239  ngeoms = GEOSGetNumInteriorRings(geom);
240  ppaa = lwalloc(sizeof(POINTARRAY*) * (ngeoms + 1));
241  g = GEOSGetExteriorRing(geom);
242  cs = GEOSGeom_getCoordSeq(g);
243  ppaa[0] = ptarray_from_GEOSCoordSeq(cs, want3d);
244  for (i = 0; i < ngeoms; i++)
245  {
246  g = GEOSGetInteriorRingN(geom, i);
247  cs = GEOSGeom_getCoordSeq(g);
248  ppaa[i + 1] = ptarray_from_GEOSCoordSeq(cs, want3d);
249  }
250  return (LWGEOM*)lwpoly_construct(SRID, NULL, ngeoms + 1, ppaa);
251 
252  case GEOS_MULTIPOINT:
253  case GEOS_MULTILINESTRING:
254  case GEOS_MULTIPOLYGON:
255  case GEOS_GEOMETRYCOLLECTION:
256  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
257 
258  ngeoms = GEOSGetNumGeometries(geom);
259  geoms = NULL;
260  if (ngeoms)
261  {
262  geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
263  for (i = 0; i < ngeoms; i++)
264  {
265  g = GEOSGetGeometryN(geom, i);
266  geoms[i] = GEOS2LWGEOM(g, want3d);
267  }
268  }
269  return (LWGEOM*)lwcollection_construct(type, SRID, NULL, ngeoms, geoms);
270 
271  default:
272  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
273  return NULL;
274  }
275 }
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, uint8_t want3d)
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoint.c:151
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoly.c:161
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwline.c:55
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
type
Definition: ovdump.py:42

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

Referenced by convexhull(), coverage_window_calculation(), GEOS2POSTGIS(), GEOSARRAY2LWGEOM(), isvaliddetail(), lwgeom_buildarea(), lwgeom_centroid(), lwgeom_clip_by_rect(), lwgeom_concavehull(), lwgeom_delaunay_triangulation(), lwgeom_difference_prec(), lwgeom_extract_unique_endpoints(), lwgeom_geos_noop(), lwgeom_intersection_prec(), lwgeom_linemerge_directed(), lwgeom_make_valid_params(), lwgeom_node(), lwgeom_normalize(), lwgeom_pointonsurface(), lwgeom_reduceprecision(), lwgeom_sharedpaths(), lwgeom_simplify_polygonal(), lwgeom_snap(), lwgeom_symdifference_prec(), lwgeom_triangulate_polygon(), lwgeom_unaryunion_prec(), lwgeom_union_prec(), lwgeom_voronoi_diagram(), lwline_offsetcurve(), lwline_split_by_line(), lwpoly_split_by_line(), and rt_raster_surface().

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