[GDAL-dev] GEOS with GDAL

Frank Warmerdam warmerdam at pobox.com
Thu Jul 26 10:22:02 EDT 2007


abhay menon wrote:
> Hello all,
>  
> How do I verify that GEOS compilation is working with my GDAL utility.
>  
> I have compiled the gdal-1.4.1 with geos-3.0.0-rc4 in vs2003 for some 
> process to build in vc6.
>  
>   OGRPolygon *poPolygon = new OGRPolygon();
>   OGRPoint *pSt = new OGRPoint();
>  
> when I issue this :
>  
> 1)  int i = poPolygon->PointOnSurface(pSt);
>  
> result pSt is empty and i = 6.
> and when I try this :

Abhay,

I'm afraid PointOnSurface() is not implemented.  It appears to have
been a "good intention" based on the OGC geometry model I added to
the api 7-8 years ago and never implemented.

> 2)  int i =  poPolygon->Centroid(pSt);
>  
> it gives me an error and the application quits
>  
> But when I tried the same with vs2003 the 2) step breaks at getX();
> 1) step result the same as earlier.

Hmm.  Is pSt a pointer to an existing OGRPoint?  I don't know why
things are crashing but at least this indicates that OGR is trying
to use GEOS as otherwise it wouldn't do anything - just return
OGRERR_FAILURE.

At the core of the Centroid() method is this:

     	hOtherGeosGeom = GEOSGetCentroid( hThisGeosGeom );
         OGRPoint *poCentroid = (OGRPoint *)
             OGRGeometryFactory::createFromGEOS( hOtherGeosGeom );

         GEOSGeom_destroy( hThisGeosGeom );
         GEOSGeom_destroy( hOtherGeosGeom );

         if( poPoint == NULL
             || wkbFlatten(poPoint->getGeometryType()) != wkbPoint )
             return OGRERR_FAILURE;

	poPoint->setX( poCentroid->getX() );
	poPoint->setY( poCentroid->getY() );

         delete poCentroid;

I wonder if the return result (poCentroid) is invalid in
some fashion that isn't tested for?

I see the OGR autotests includes this python test:

     g1 = ogr.CreateGeometryFromWkt( 'POLYGON((0 0, 10 10, 10 0, 0 0))' )

     centroid = g1.Centroid()

     g1.Destroy()

     if ogrtest.check_feature_geometry( centroid,
                                        'POINT(6.666666667 3.333333333)') != 0:
         print 'Got: ', centroid.ExportToWkt()
         return 'fail'

     centroid.Destroy()

So it seems that Centroid() usually works.

I guess you will need to debug into the code to try and narrow down
what is happening.  You might want to determine whether other GEOS
based functions such as Union() work or not.  It may be a general problem
with using GEOS rather than Centroid() specific.

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    | President OSGeo, http://osgeo.org




More information about the Gdal-dev mailing list