PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ GEOS2LWGEOM()

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

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

194 {
195  int type = GEOSGeomTypeId(geom);
196  int SRID = GEOSGetSRID(geom);
197 
198  /* GEOS's 0 is equivalent to our unknown as for SRID values */
199  if (SRID == 0) SRID = SRID_UNKNOWN;
200 
201  if (want3d && !GEOSHasZ(geom))
202  {
203  LWDEBUG(3, "Geometry has no Z, won't provide one");
204  want3d = 0;
205  }
206 
207  switch (type)
208  {
209  const GEOSCoordSequence* cs;
210  POINTARRAY *pa, **ppaa;
211  const GEOSGeometry* g;
212  LWGEOM** geoms;
213  uint32_t i, ngeoms;
214 
215  case GEOS_POINT:
216  LWDEBUG(4, "lwgeom_from_geometry: it's a Point");
217  cs = GEOSGeom_getCoordSeq(geom);
218  if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoint_construct_empty(SRID, want3d, 0);
219  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
220  return (LWGEOM*)lwpoint_construct(SRID, NULL, pa);
221 
222  case GEOS_LINESTRING:
223  case GEOS_LINEARRING:
224  LWDEBUG(4, "lwgeom_from_geometry: it's a LineString or LinearRing");
225  if (GEOSisEmpty(geom)) return (LWGEOM*)lwline_construct_empty(SRID, want3d, 0);
226 
227  cs = GEOSGeom_getCoordSeq(geom);
228  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
229  return (LWGEOM*)lwline_construct(SRID, NULL, pa);
230 
231  case GEOS_POLYGON:
232  LWDEBUG(4, "lwgeom_from_geometry: it's a Polygon");
233  if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoly_construct_empty(SRID, want3d, 0);
234  ngeoms = GEOSGetNumInteriorRings(geom);
235  ppaa = lwalloc(sizeof(POINTARRAY*) * (ngeoms + 1));
236  g = GEOSGetExteriorRing(geom);
237  cs = GEOSGeom_getCoordSeq(g);
238  ppaa[0] = ptarray_from_GEOSCoordSeq(cs, want3d);
239  for (i = 0; i < ngeoms; i++)
240  {
241  g = GEOSGetInteriorRingN(geom, i);
242  cs = GEOSGeom_getCoordSeq(g);
243  ppaa[i + 1] = ptarray_from_GEOSCoordSeq(cs, want3d);
244  }
245  return (LWGEOM*)lwpoly_construct(SRID, NULL, ngeoms + 1, ppaa);
246 
247  case GEOS_MULTIPOINT:
248  case GEOS_MULTILINESTRING:
249  case GEOS_MULTIPOLYGON:
250  case GEOS_GEOMETRYCOLLECTION:
251  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
252 
253  ngeoms = GEOSGetNumGeometries(geom);
254  geoms = NULL;
255  if (ngeoms)
256  {
257  geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
258  for (i = 0; i < ngeoms; i++)
259  {
260  g = GEOSGetGeometryN(geom, i);
261  geoms[i] = GEOS2LWGEOM(g, want3d);
262  }
263  }
264  return (LWGEOM*)lwcollection_construct(type, SRID, NULL, ngeoms, geoms);
265 
266  default:
267  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
268  return NULL;
269  }
270 }
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:101
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
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 lwgeom_buildarea(), lwgeom_centroid(), lwgeom_clip_by_rect(), lwgeom_concavehull(), lwgeom_delaunay_triangulation(), lwgeom_difference_prec(), lwgeom_geos_noop(), lwgeom_intersection_prec(), lwgeom_linemerge_directed(), 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(), and lwline_offsetcurve().

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