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

Definition at line 96 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(), isvaliddetail(), lwgeom_buildarea(), 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_make_valid(), lwgeom_node(), lwgeom_normalize(), lwgeom_offsetcurve(), lwgeom_sharedpaths(), lwgeom_snap(), lwgeom_symdifference(), lwgeom_union(), lwline_split_by_line(), lwpoly_split_by_line(), and rt_raster_surface().

97 {
98  int type = GEOSGeomTypeId(geom) ;
99  int hasZ;
100  int SRID = GEOSGetSRID(geom);
101 
102  /* GEOS's 0 is equivalent to our unknown as for SRID values */
103  if ( SRID == 0 ) SRID = SRID_UNKNOWN;
104 
105  if ( want3d )
106  {
107  hasZ = GEOSHasZ(geom);
108  if ( ! hasZ )
109  {
110  LWDEBUG(3, "Geometry has no Z, won't provide one");
111 
112  want3d = 0;
113  }
114  }
115 
116 /*
117  if ( GEOSisEmpty(geom) )
118  {
119  return (LWGEOM*)lwcollection_construct_empty(COLLECTIONTYPE, SRID, want3d, 0);
120  }
121 */
122 
123  switch (type)
124  {
125  const GEOSCoordSequence *cs;
126  POINTARRAY *pa, **ppaa;
127  const GEOSGeometry *g;
128  LWGEOM **geoms;
129  uint32_t i, ngeoms;
130 
131  case GEOS_POINT:
132  LWDEBUG(4, "lwgeom_from_geometry: it's a Point");
133  cs = GEOSGeom_getCoordSeq(geom);
134  if ( GEOSisEmpty(geom) )
135  return (LWGEOM*)lwpoint_construct_empty(SRID, want3d, 0);
136  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
137  return (LWGEOM *)lwpoint_construct(SRID, NULL, pa);
138 
139  case GEOS_LINESTRING:
140  case GEOS_LINEARRING:
141  LWDEBUG(4, "lwgeom_from_geometry: it's a LineString or LinearRing");
142  if ( GEOSisEmpty(geom) )
143  return (LWGEOM*)lwline_construct_empty(SRID, want3d, 0);
144 
145  cs = GEOSGeom_getCoordSeq(geom);
146  pa = ptarray_from_GEOSCoordSeq(cs, want3d);
147  return (LWGEOM *)lwline_construct(SRID, NULL, pa);
148 
149  case GEOS_POLYGON:
150  LWDEBUG(4, "lwgeom_from_geometry: it's a Polygon");
151  if ( GEOSisEmpty(geom) )
152  return (LWGEOM*)lwpoly_construct_empty(SRID, want3d, 0);
153  ngeoms = GEOSGetNumInteriorRings(geom);
154  ppaa = lwalloc(sizeof(POINTARRAY *)*(ngeoms+1));
155  g = GEOSGetExteriorRing(geom);
156  cs = GEOSGeom_getCoordSeq(g);
157  ppaa[0] = ptarray_from_GEOSCoordSeq(cs, want3d);
158  for (i=0; i<ngeoms; i++)
159  {
160  g = GEOSGetInteriorRingN(geom, i);
161  cs = GEOSGeom_getCoordSeq(g);
162  ppaa[i+1] = ptarray_from_GEOSCoordSeq(cs,
163  want3d);
164  }
165  return (LWGEOM *)lwpoly_construct(SRID, NULL,
166  ngeoms+1, ppaa);
167 
168  case GEOS_MULTIPOINT:
169  case GEOS_MULTILINESTRING:
170  case GEOS_MULTIPOLYGON:
171  case GEOS_GEOMETRYCOLLECTION:
172  LWDEBUG(4, "lwgeom_from_geometry: it's a Collection or Multi");
173 
174  ngeoms = GEOSGetNumGeometries(geom);
175  geoms = NULL;
176  if ( ngeoms )
177  {
178  geoms = lwalloc(sizeof(LWGEOM *)*ngeoms);
179  for (i=0; i<ngeoms; i++)
180  {
181  g = GEOSGetGeometryN(geom, i);
182  geoms[i] = GEOS2LWGEOM(g, want3d);
183  }
184  }
185  return (LWGEOM *)lwcollection_construct(type,
186  SRID, NULL, ngeoms, geoms);
187 
188  default:
189  lwerror("GEOS2LWGEOM: unknown geometry type: %d", type);
190  return NULL;
191 
192  }
193 
194 }
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:51
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:118
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWGEOM * geom
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:29
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:96
void * lwalloc(size_t size)
Definition: lwutil.c:175
POINTARRAY * ptarray_from_GEOSCoordSeq(const GEOSCoordSequence *cs, char want3d)

Here is the call graph for this function:

Here is the caller graph for this function: