return sq;
}
+static GEOSGeometry *
+ptarray_to_GEOSLinearRing(const POINTARRAY *pa, int autofix)
+{
+ GEOSCoordSeq sq;
+ GEOSGeom g;
+ POINTARRAY *npa = 0;
+ if ( autofix )
+ {
+ /* check ring for being closed and fix if not */
+ if ( ! ptarray_is_closed_2d(pa) ) {
+ npa = ptarray_addPoint(pa, getPoint_internal(pa, 0),
+ FLAGS_NDIMS(pa->flags), pa->npoints);
+ pa = npa;
+ }
+ /* TODO: check ring for having at least 4 vertices */
+#if 0
+ while ( pa->npoints < 4 ) {
+ npa = ptarray_addPoint(npa, getPoint_internal(pa, 0),
+ FLAGS_NDIMS(pa->flags), pa->npoints);
+ }
+#endif
+ }
+ sq = ptarray_to_GEOSCoordSeq(pa);
+ if ( npa ) ptarray_free(npa);
+ g = GEOSGeom_createLinearRing(sq);
+ return g;
+}
GEOSGeometry *
-LWGEOM2GEOS(const LWGEOM *lwgeom)
+LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
{
GEOSCoordSeq sq;
GEOSGeom g, shell;
break;
case LINETYPE:
lwl = (LWLINE *)lwgeom;
+ /* TODO: if (autofix) */
if ( lwl->points->npoints == 1 ) {
/* Duplicate point, to make geos-friendly */
lwl->points = ptarray_addPoint(lwl->points,
}
else
{
- sq = ptarray_to_GEOSCoordSeq(lwpoly->rings[0]);
- /* TODO: check ring for being closed and fix if not */
- shell = GEOSGeom_createLinearRing(sq);
+ shell = ptarray_to_GEOSLinearRing(lwpoly->rings[0], autofix);
if ( ! shell ) return NULL;
/*lwerror("LWGEOM2GEOS: exception during polygon shell conversion"); */
ngeoms = lwpoly->nrings-1;
for (i=1; i<lwpoly->nrings; ++i)
{
- sq = ptarray_to_GEOSCoordSeq(lwpoly->rings[i]);
- geoms[i-1] = GEOSGeom_createLinearRing(sq);
+ geoms[i-1] = ptarray_to_GEOSLinearRing(lwpoly->rings[i], autofix);
if ( ! geoms[i-1] )
{
--i;
for (i=0; i<ngeoms; ++i)
{
- GEOSGeometry* g = LWGEOM2GEOS(lwc->geoms[i]);
+ GEOSGeometry* g = LWGEOM2GEOS(lwc->geoms[i], 0);
if ( ! g )
{
while (i) GEOSGeom_destroy(geoms[--i]);
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = LWGEOM2GEOS(geom1);
+ g1 = LWGEOM2GEOS(geom1, 0);
if ( 0 == g1 ) /* exception thrown at construction */
{
lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
LWDEBUG(3, "intersection() START");
- g1 = LWGEOM2GEOS(geom1);
+ g1 = LWGEOM2GEOS(geom1, 0);
if ( 0 == g1 ) /* exception thrown at construction */
{
lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
return NULL ;
}
- g2 = LWGEOM2GEOS(geom2);
+ g2 = LWGEOM2GEOS(geom2, 0);
if ( 0 == g2 ) /* exception thrown at construction */
{
lwerror("Second argument geometry could not be converted to GEOS.");
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = LWGEOM2GEOS(geom1);
+ g1 = LWGEOM2GEOS(geom1, 0);
if ( 0 == g1 ) /* exception thrown at construction */
{
lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
return NULL;
}
- g2 = LWGEOM2GEOS(geom2);
+ g2 = LWGEOM2GEOS(geom2, 0);
if ( 0 == g2 ) /* exception thrown at construction */
{
GEOSGeom_destroy(g1);
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = LWGEOM2GEOS(geom1);
+ g1 = LWGEOM2GEOS(geom1, 0);
if ( 0 == g1 ) /* exception thrown at construction */
{
return NULL;
}
- g2 = LWGEOM2GEOS(geom2);
+ g2 = LWGEOM2GEOS(geom2, 0);
if ( 0 == g2 ) /* exception thrown at construction */
{
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = LWGEOM2GEOS(geom1);
+ g1 = LWGEOM2GEOS(geom1, 0);
if ( 0 == g1 ) /* exception thrown at construction */
{
return NULL;
}
- g2 = LWGEOM2GEOS(geom2);
+ g2 = LWGEOM2GEOS(geom2, 0);
if ( 0 == g2 ) /* exception thrown at construction */
{
LWDEBUG(3, "clip_by_rect() START");
- g1 = LWGEOM2GEOS(geom1);
+ g1 = LWGEOM2GEOS(geom1, 1); /* auto-fix structure */
if ( 0 == g1 ) /* exception thrown at construction */
{
lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
initGEOS(lwnotice, lwgeom_geos_error);
- geos_in = LWGEOM2GEOS(geom);
+ geos_in = LWGEOM2GEOS(geom, 0);
if ( 0 == geos_in ) /* exception thrown at construction */
{
int is3d = FLAGS_GET_Z(geom_in->flags);
initGEOS(lwnotice, lwgeom_geos_error);
- geosgeom = LWGEOM2GEOS(geom_in);
+ geosgeom = LWGEOM2GEOS(geom_in, 0);
if ( ! geosgeom ) {
lwerror("Geometry could not be converted to GEOS: %s",
lwgeom_geos_errmsg);
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = (GEOSGeometry *)LWGEOM2GEOS(geom1);
+ g1 = (GEOSGeometry *)LWGEOM2GEOS(geom1, 0);
if ( 0 == g1 ) /* exception thrown at construction */
{
lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
return NULL;
}
- g2 = (GEOSGeometry *)LWGEOM2GEOS(geom2);
+ g2 = (GEOSGeometry *)LWGEOM2GEOS(geom2, 0);
if ( 0 == g2 ) /* exception thrown at construction */
{
lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = (GEOSGeometry *)LWGEOM2GEOS(geom1);
+ g1 = (GEOSGeometry *)LWGEOM2GEOS(geom1, 0);
if ( 0 == g1 ) /* exception thrown at construction */
{
lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
return NULL;
}
- g2 = (GEOSGeometry *)LWGEOM2GEOS(geom2);
+ g2 = (GEOSGeometry *)LWGEOM2GEOS(geom2, 0);
if ( 0 == g2 ) /* exception thrown at construction */
{
lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in);
+ g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in, 0);
if ( ! g1 )
{
lwerror("lwgeom_offsetcurve: Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
initGEOS(lwnotice, lwgeom_geos_error);
- g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in);
+ g1 = (GEOSGeometry *)LWGEOM2GEOS(lwgeom_in, 0);
if ( ! g1 )
{
lwerror("lwgeom_delaunay_triangulation: Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);