From: Sandro Santilli Date: Mon, 20 Sep 2004 21:13:23 +0000 (+0000) Subject: Optimized postgis->geos conversion X-Git-Tag: pgis_1_0_0RC1~412 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c1f0ecf46a4dc99c59d5b70218d0e19fd349423;p=postgis Optimized postgis->geos conversion git-svn-id: http://svn.osgeo.org/postgis/trunk@860 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/lwgeom_geos_wrapper.cpp b/lwgeom/lwgeom_geos_wrapper.cpp index 2ec51fb69..29b86650a 100644 --- a/lwgeom/lwgeom_geos_wrapper.cpp +++ b/lwgeom/lwgeom_geos_wrapper.cpp @@ -260,16 +260,26 @@ PostGIS2GEOS_linestring(const LWLINE *lwline) POINT3D *p; //build coordinatelist & pre-allocate space +#if GEOS_LAST_INTERFACE >= 2 + vector *vc = new vector(pa->npoints); +#else DefaultCoordinateSequence *coords = new DefaultCoordinateSequence(pa->npoints); +#endif if (is3d) { for (t=0; tnpoints; t++) { p = (POINT3D *)getPoint(pa, t); +#if GEOS_LAST_INTERFACE >= 2 + (*vc)[t].x = p->x; + (*vc)[t].y = p->y; + (*vc)[t].z = p->z; +#else c.x = p->x; c.y = p->y; c.z = p->z; coords->setAt(c ,t); +#endif } } else //make 2d points @@ -277,12 +287,21 @@ PostGIS2GEOS_linestring(const LWLINE *lwline) for (t=0; tnpoints; t++) { p = (POINT3D *)getPoint(pa, t); +#if GEOS_LAST_INTERFACE >= 2 + (*vc)[t].x = p->x; + (*vc)[t].y = p->y; + (*vc)[t].z = DoubleNotANumber; +#else c.x = p->x; c.y = p->y; c.z = DoubleNotANumber; coords->setAt(c ,t); +#endif } } +#if GEOS_LAST_INTERFACE >= 2 + CoordinateSequence *coords = DefaultCoordinateSequenceFactory::instance()->create(vc); +#endif Geometry *g = geomFactory->createLineString(coords); #if GEOS_LAST_INTERFACE < 2 delete coords; @@ -318,22 +337,33 @@ Geometry *PostGIS2GEOS_polygon(const LWPOLY *lwpoly) Geometry *g; LinearRing *outerRing; LinearRing *innerRing; - DefaultCoordinateSequence *cl; + CoordinateSequence *cl; POINT3D *p; - vector *innerRings=new vector; + vector *innerRings; + vector *vc; // make outerRing pa = lwpoly->rings[0]; +#if GEOS_LAST_INTERFACE >= 2 + vc = new vector(pa->npoints); +#else cl = new DefaultCoordinateSequence(pa->npoints); +#endif if (is3d) { for(t=0; tnpoints; t++) { p = (POINT3D *)getPoint(pa, t); +#if GEOS_LAST_INTERFACE >= 2 + (*vc)[t].x = p->x; + (*vc)[t].y = p->y; + (*vc)[t].z = p->z; +#else c.x = p->x; c.y = p->y; c.z = p->z; cl->setAt( c ,t); +#endif } } else @@ -341,12 +371,21 @@ Geometry *PostGIS2GEOS_polygon(const LWPOLY *lwpoly) for(t=0; tnpoints; t++) { p = (POINT3D *)getPoint(pa, t); +#if GEOS_LAST_INTERFACE >= 2 + (*vc)[t].x = p->x; + (*vc)[t].y = p->y; + (*vc)[t].z = DoubleNotANumber; +#else c.x = p->x; c.y = p->y; c.z = DoubleNotANumber; cl->setAt(c ,t); +#endif } } +#if GEOS_LAST_INTERFACE >= 2 + cl = DefaultCoordinateSequenceFactory::instance()->create(vc); +#endif outerRing = (LinearRing*) geomFactory->createLinearRing(cl); #if GEOS_LAST_INTERFACE < 2 delete cl; @@ -354,19 +393,30 @@ Geometry *PostGIS2GEOS_polygon(const LWPOLY *lwpoly) if (outerRing == NULL) return NULL; outerRing->setSRID(SRID); + innerRings=new vector(lwpoly->nrings-1); for(ring=1; ringnrings; ring++) { pa = lwpoly->rings[ring]; +#if GEOS_LAST_INTERFACE >= 2 + vector *vc = new vector(pa->npoints); +#else cl = new DefaultCoordinateSequence(pa->npoints); +#endif if (is3d) { for(t=0; tnpoints; t++) { p = (POINT3D *)getPoint(pa, t); +#if GEOS_LAST_INTERFACE >= 2 + (*vc)[t].x = p->x; + (*vc)[t].y = p->y; + (*vc)[t].z = p->z; +#else c.x = p->x; c.y = p->y; c.z = p->z; cl->setAt(c ,t); +#endif } } else @@ -374,12 +424,21 @@ Geometry *PostGIS2GEOS_polygon(const LWPOLY *lwpoly) for(t=0; tnpoints; t++) { p = (POINT3D *)getPoint(pa, t); +#if GEOS_LAST_INTERFACE >= 2 + (*vc)[t].x = p->x; + (*vc)[t].y = p->y; + (*vc)[t].z = DoubleNotANumber; +#else c.x = p->x; c.y = p->y; c.z = DoubleNotANumber; cl->setAt(c ,t); +#endif } } +#if GEOS_LAST_INTERFACE >= 2 + CoordinateSequence *cl = DefaultCoordinateSequenceFactory::instance()->create(vc); +#endif innerRing = (LinearRing *) geomFactory->createLinearRing(cl); #if GEOS_LAST_INTERFACE < 2 delete cl; @@ -390,7 +449,7 @@ Geometry *PostGIS2GEOS_polygon(const LWPOLY *lwpoly) return NULL; } innerRing->setSRID(SRID); - innerRings->push_back(innerRing); + (*innerRings)[ring-1] = innerRing; } g = geomFactory->createPolygon(outerRing, innerRings); @@ -419,11 +478,11 @@ Geometry *PostGIS2GEOS_multipoint(LWPOINT *const *const geoms, uint32 ngeoms, in vector *subGeoms=NULL; Geometry *g; - subGeoms=new vector; + subGeoms=new vector(ngeoms); for (t=0; tpush_back(PostGIS2GEOS_point(geoms[t])); + (*subGeoms)[t] = PostGIS2GEOS_point(geoms[t]); } g = geomFactory->createMultiPoint(subGeoms); #if GEOS_LAST_INTERFACE < 2 @@ -456,11 +515,11 @@ Geometry *PostGIS2GEOS_multilinestring(LWLINE *const *const geoms, uint32 ngeoms vector *subGeoms=NULL; Geometry *g; - subGeoms=new vector; + subGeoms=new vector(ngeoms); for (t=0; tpush_back(PostGIS2GEOS_linestring(geoms[t])); + (*subGeoms)[t] = PostGIS2GEOS_linestring(geoms[t]); } g = geomFactory->createMultiLineString(subGeoms); #if GEOS_LAST_INTERFACE < 2 @@ -493,11 +552,11 @@ Geometry *PostGIS2GEOS_multipolygon(LWPOLY *const *const polygons, uint32 npolys vector *subPolys=NULL; Geometry *g; - subPolys=new vector; + subPolys=new vector(npolys); for (t =0; t< npolys; t++) { - subPolys->push_back(PostGIS2GEOS_polygon(polygons[t])); + (*subPolys)[t] = PostGIS2GEOS_polygon(polygons[t]); } g = geomFactory->createMultiPolygon(subPolys); #if GEOS_LAST_INTERFACE < 2 @@ -528,11 +587,11 @@ Geometry *PostGIS2GEOS_collection(Geometry **geoms, int ngeoms, int SRID, bool i { Geometry *g; int t; - vector *subGeos=new vector; + vector *subGeos=new vector(ngeoms); - for (t =0; t< ngeoms; t++) + for (t =0; tpush_back(geoms[t]); + (*subGeos)[t] = geoms[t]; } g = geomFactory->buildGeometry(subGeos); #if GEOS_LAST_INTERFACE < 2