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

Definition at line 110 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: