PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ GEOS2LWGEOM()

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

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

175 {
176  int type = GEOSGeomTypeId(geom);
177  int SRID = GEOSGetSRID(geom);
178 
179  /* GEOS's 0 is equivalent to our unknown as for SRID values */
180  if (SRID == 0) SRID = SRID_UNKNOWN;
181 
182  if (want3d && !GEOSHasZ(geom))
183  {
184  LWDEBUG(3, "Geometry has no Z, won't provide one");
185  want3d = 0;
186  }
187 
188  switch (type)
189  {
190  const GEOSCoordSequence* cs;
191  POINTARRAY *pa, **ppaa;
192  const GEOSGeometry* g;
193  LWGEOM** geoms;
194  uint32_t i, ngeoms;
195 
196  case GEOS_POINT:
197  LWDEBUG(4, "lwgeom_from_geometry: it's a Point");
198  cs = GEOSGeom_getCoordSeq(geom);
199  if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoint_construct_empty(SRID, want3d, 0);
200  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
201  return (LWGEOM*)lwpoint_construct(SRID, NULL, pa);
202 
203  case GEOS_LINESTRING:
204  case GEOS_LINEARRING:
205  LWDEBUG(4, "lwgeom_from_geometry: it's a LineString or LinearRing");
206  if (GEOSisEmpty(geom)) return (LWGEOM*)lwline_construct_empty(SRID, want3d, 0);
207 
208  cs = GEOSGeom_getCoordSeq(geom);
209  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
210  return (LWGEOM*)lwline_construct(SRID, NULL, pa);
211 
212  case GEOS_POLYGON:
213  LWDEBUG(4, "lwgeom_from_geometry: it's a Polygon");
214  if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoly_construct_empty(SRID, want3d, 0);
215  ngeoms = GEOSGetNumInteriorRings(geom);
216  ppaa = lwalloc(sizeof(POINTARRAY*) * (ngeoms + 1));
217  g = GEOSGetExteriorRing(geom);
218  cs = GEOSGeom_getCoordSeq(g);
219  ppaa[0] = ptarray_from_GEOSCoordSeq(cs, want3d);
220  for (i = 0; i < ngeoms; i++)
221  {
222  g = GEOSGetInteriorRingN(geom, i);
223  cs = GEOSGeom_getCoordSeq(g);
224  ppaa[i + 1] = ptarray_from_GEOSCoordSeq(cs, want3d);
225  }
226  return (LWGEOM*)lwpoly_construct(SRID, NULL, ngeoms + 1, ppaa);
227 
228  case GEOS_MULTIPOINT:
229  case GEOS_MULTILINESTRING:
230  case GEOS_MULTIPOLYGON:
231  case GEOS_GEOMETRYCOLLECTION:
232  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
233 
234  ngeoms = GEOSGetNumGeometries(geom);
235  geoms = NULL;
236  if (ngeoms)
237  {
238  geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
239  for (i = 0; i < ngeoms; i++)
240  {
241  g = GEOSGetGeometryN(geom, i);
242  geoms[i] = GEOS2LWGEOM(g, want3d);
243  }
244  }
245  return (LWGEOM*)lwcollection_construct(type, SRID, NULL, ngeoms, geoms);
246 
247  default:
248  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
249  return NULL;
250  }
251 }
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:230
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(), GEOS2POSTGIS(), GEOSARRAY2LWGEOM(), isvaliddetail(), lwgeom_buildarea(), lwgeom_centroid(), lwgeom_clip_by_rect(), 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_snap(), lwgeom_symdifference_prec(), 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: