[gdal-dev] FW: point within polygon c++ API problem

Ran, Limei lran at email.unc.edu
Wed Dec 19 12:18:55 PST 2012


Hello Even,

Since you helped me on GEOS compiling with GDAL, I think you may have ideas on what went wrong with my codes in the following.  Could you tell me what you think on my segmentation fault error?

Thank you,

Limei


From: Ran, Limei
Sent: Tuesday, December 18, 2012 3:21 PM
To: gdal-dev at lists.osgeo.org
Subject: point within polygon c++ API problem

Hello,

I am working on a C++ codes which reads polygon from polygon shapefile to see whether a point is within a polygon.  But, I got segmentation fault for pt.within (poGeometry).  Could you tell me where I may have errors.


1.      GDAL 1.9.1 is compiled with currect GEOS 3.3.6

2.      My c++ program compiled with GDAL.

3.      Here are my codes:

......
      float x = grid.x[col];
       float y = grid.y[row];

       OGRPoint pt;
        pt.setX( x );
        pt.setY( y );

        printf ("\tSet point\n");

        OGRFeature *poFeature;
        poLayer->ResetReading();

        while( (poFeature = poLayer->GetNextFeature()) != NULL )
        {
           OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
           int iField;

           OGRGeometry *poGeometry;

           poGeometry = poFeature->GetGeometryRef();
           if( poGeometry != NULL && ( poGeometry->getGeometryType() ) == wkbPolygon )
           {
              printf ("\tGot polygon\n");

              if ( pt.Within ( poGeometry ) )
              {  //find the polygon where point is within and get item values

                 printf ("\tpoint in polygon\n");
.........

I got segmentation fault when processing gets:  if ( pt.Within ( poGeometry ) )


Thank you,

Limei


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20121219/8a36d87c/attachment.html>


More information about the gdal-dev mailing list