[GDAL-dev] GEOS with GDAL

abhay menon abhay.menon at gmail.com
Fri Jul 27 04:53:01 EDT 2007


On 7/26/07, Frank Warmerdam <warmerdam at pobox.com> wrote:
>
> 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
>
>
Hi Frank,
Thanks for the info about PointOnSuface.
But it would be really useful if the GDAL supported the PointOnSurface
function of GEOS as most of the GIS application will creating a Centriod of
a irregular polygon creates point inside the polygon which is not the real
centriod but an output of PointOnSurface or InnerPoint.

Hmm.. about the Centroid part.
I use the build for msvc80 in GEOS trunk to create the MSVC 8 compatible
version which I am able to call in VC++6.
I will let know on the problem that is being created on VC7.1. once I get
time for that. And let you know what happened within.


-- 
Best Regards

 Abhay Menon
 http://abhaymenon.info
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070727/23ed8a5b/attachment.html


More information about the Gdal-dev mailing list