PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ GEOS2LWGEOM()

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

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

167{
168 int type = GEOSGeomTypeId(geom);
169 int SRID = GEOSGetSRID(geom);
170
171 /* GEOS's 0 is equivalent to our unknown as for SRID values */
172 if (SRID == 0) SRID = SRID_UNKNOWN;
173
174 if (want3d && !GEOSHasZ(geom))
175 {
176 LWDEBUG(3, "Geometry has no Z, won't provide one");
177 want3d = 0;
178 }
179
180 switch (type)
181 {
182 const GEOSCoordSequence* cs;
183 POINTARRAY *pa, **ppaa;
184 const GEOSGeometry* g;
185 LWGEOM** geoms;
186 uint32_t i, ngeoms;
187
188 case GEOS_POINT:
189 LWDEBUG(4, "lwgeom_from_geometry: it's a Point");
190 cs = GEOSGeom_getCoordSeq(geom);
191 if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoint_construct_empty(SRID, want3d, 0);
192 pa = ptarray_from_GEOSCoordSeq(cs, want3d);
193 return (LWGEOM*)lwpoint_construct(SRID, NULL, pa);
194
195 case GEOS_LINESTRING:
196 case GEOS_LINEARRING:
197 LWDEBUG(4, "lwgeom_from_geometry: it's a LineString or LinearRing");
198 if (GEOSisEmpty(geom)) return (LWGEOM*)lwline_construct_empty(SRID, want3d, 0);
199
200 cs = GEOSGeom_getCoordSeq(geom);
201 pa = ptarray_from_GEOSCoordSeq(cs, want3d);
202 return (LWGEOM*)lwline_construct(SRID, NULL, pa);
203
204 case GEOS_POLYGON:
205 LWDEBUG(4, "lwgeom_from_geometry: it's a Polygon");
206 if (GEOSisEmpty(geom)) return (LWGEOM*)lwpoly_construct_empty(SRID, want3d, 0);
207 ngeoms = GEOSGetNumInteriorRings(geom);
208 ppaa = lwalloc(sizeof(POINTARRAY*) * (ngeoms + 1));
209 g = GEOSGetExteriorRing(geom);
210 cs = GEOSGeom_getCoordSeq(g);
211 ppaa[0] = ptarray_from_GEOSCoordSeq(cs, want3d);
212 for (i = 0; i < ngeoms; i++)
213 {
214 g = GEOSGetInteriorRingN(geom, i);
215 cs = GEOSGeom_getCoordSeq(g);
216 ppaa[i + 1] = ptarray_from_GEOSCoordSeq(cs, want3d);
217 }
218 return (LWGEOM*)lwpoly_construct(SRID, NULL, ngeoms + 1, ppaa);
219
220 case GEOS_MULTIPOINT:
221 case GEOS_MULTILINESTRING:
222 case GEOS_MULTIPOLYGON:
223 case GEOS_GEOMETRYCOLLECTION:
224 LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
225
226 ngeoms = GEOSGetNumGeometries(geom);
227 geoms = NULL;
228 if (ngeoms)
229 {
230 geoms = lwalloc(sizeof(LWGEOM*) * ngeoms);
231 for (i = 0; i < ngeoms; i++)
232 {
233 g = GEOSGetGeometryN(geom, i);
234 geoms[i] = GEOS2LWGEOM(g, want3d);
235 }
236 }
237 return (LWGEOM*)lwcollection_construct(type, SRID, NULL, ngeoms, geoms);
238
239 default:
240 lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
241 return NULL;
242 }
243}
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, uint8_t want3d)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition lwpoint.c:129
void * lwalloc(size_t size)
Definition lwutil.c:227
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoint.c:151
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition lwpoly.c:43
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoly.c:161
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:229
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

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_noop(), lwgeom_intersection(), lwgeom_linemerge(), lwgeom_make_valid(), lwgeom_node(), lwgeom_normalize(), lwgeom_pointonsurface(), lwgeom_sharedpaths(), lwgeom_snap(), lwgeom_symdifference(), lwgeom_unaryunion(), lwgeom_union(), lwgeom_voronoi_diagram(), lwline_offsetcurve(), lwline_split_by_line(), lwpoly_split_by_line(), mvt_grid_and_validate_geos(), mvt_safe_clip_polygon_by_box(), and rt_raster_surface().

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