[Gdal-dev] exportToGEOS performance
Pirmin Kalberer
sp_ml at sourcepole.com
Mon Oct 10 04:13:10 EDT 2005
Frank,
I tried to write my own WKB based exportToGEOS. The geos::WKBReader exists in
the CVS version of GEOS only. But my usage of istringstream doesn't work. It
hangs in geosWkbReader.read. Any ideas?
Pirmin
#ifdef HAVE_GEOS
geos::Geometry *exportToGEOS(OGRGeometry *geom)
{
#if GEOS_VERSION_MAJOR*100+GEOS_VERSION_MINOR*10+GEOS_VERSION_PATCH < 300
return geom->exportToGEOS();
#else
GByte *pabyWKB;
pabyWKB = (GByte *) CPLMalloc(geom->WkbSize());
geos::WKBReader geosWkbReader(
*OGRGeometryFactory::getGEOSGeometryFactory() );
if( geom->exportToWkb( wkbNDR, pabyWKB ) != OGRERR_NONE )
return NULL;
istringstream oWKB((const char*)pabyWKB, istringstream::in |
istringstream::binary);
CPLFree( pabyWKB );
try
{
geos::Geometry *geosGeometry = NULL;
geosGeometry = geosWkbReader.read( oWKB );
return geosGeometry;
}
catch( geos::GEOSException *e )
{
CPLError( CE_Failure, CPLE_AppDefined,
"GEOSException: %s",
e->toString().c_str() );
delete e;
return NULL;
}
#endif
}
#endif /* HAVE_GEOS */
Am Donnerstag, 6. Oktober 2005 18.17 schrieb Frank Warmerdam:
> On 10/6/05, Pirmin Kalberer <sp_ml at sourcepole.com> wrote:
> > Hi,
> >
> > I'm using the GEOS polygonizer for the OGR Interlis driver. But the
> > polygonization is quite slow because of the exportToGEOS call. The code
> > looks like this:
> >
> > geos::Geometry *poThisGeosGeom = poLines->exportToGEOS(); //slow
> > geos::Polygonizer* polygonizer = new geos::Polygonizer();
> > polygonizer->add(poThisGeosGeom);
> > vector<geos::Polygon*> *poOtherGeosGeom = polygonizer->getPolygons();
> >
> > We're talking about exporting 1677 OGRLineString's in about 1'20'' and
> > polygonizing them within a few second.
>
> Pirmin,
>
> I was planning to rewrite exportToGEOS() to translate using WKB
> format instead of WKT which I suspect will be significantly faster.
> This will be part of an upgrade to use the GEOS C API in time for
> the next release. In the meantime, you might want to try modifying
> your local copy to go via WKB instead of WKT. I think when I
> first looked at GEOS only the WKT conversion was supported.
>
> Best regards,
> --
> ---------------------------------------+-----------------------------------
>--- I set the clouds in motion - turn up | Frank Warmerdam,
> warmerdam at pobox.com light and sound - activate the windows |
> http://pobox.com/~warmerdam and watch the world go round - Rush |
> Geospatial Programmer for Rent
--
Pirmin Kalberer
Sourcepole - Linux & Open Source Solutions
http://www.sourcepole.com
More information about the Gdal-dev
mailing list