0

I’m trying to develop (using C++ - MSVS 12.0) a function that discover which pixels (from a raster image) have its center inside a polygon (previously populated using a shapefile). I’m using GDAL 1.11.0 (just installed, using devinstall) building from source and using the option INCLUDE_OGR_FRMTS=YES. I can use GDAL and most of OGR functions without problem. However, when I use the following code:

if (polygon->Contains(tmpPoint))

I receive the error message: ERROR 6: GEOS support not enabled

Anybody knows how to solve this issue?

I’m using:

#include "ogrsf_frmts.h"

and my function is declared:

void FindPixels(GDALDataset *image, OGRLayer *poLayer, OGRPolygon *polygon)

and part of my code is:

OGRPoint *tmpPoint = NULL

OGRSpatialReference *spatialReference = NULL;

spatialReference = polygon->getSpatialReference();

tmpPoint = new OGRPoint();

tmpPoint->assignSpatialReference(spatialReference);

loop begin:

tmpPoint->setX(imgTLX + (j * imgRes) + imgResHalf);

tmpPoint->setY(imgTLY - (i * imgRes) - imgResHalf);

if (polygon->Contains(tmpPoint))

Thanks in advance!

MB

  • It seems that the GEOS library has not been compiled in. Have you checked in the VC makefiles if the GEOS variables (FLAGS, LIB, etc.) are enabled and the paths are correct? Also, if you have been modifying some options, you may need to do a full clean and re-compile. – fedemp Jun 07 '14 at 12:47
  • You're right! I'm facing issues since GEOS lib doesn't support, yet, building the library with MSVS 2013 (v12). – user3468473 Jun 09 '14 at 17:34

1 Answers1

-1

Use GDALRasterizeLayers to burn the image of polygon onto a raster. This way you will find all the pixels that fall into the polygon, or not. The default is to burn the pixel only if the centre intersects a polygon.

If the source layer has multiple polygons, you may need to distinguish them by either setting an attribute filter, or using burned attribute ID fields (although this won't work if the polygons overlap).

Mike T
  • 41,085
  • 18
  • 152
  • 203
  • Hello Mike. I like this idea. I tryied to implement, but facing some issues with the code. Do you have any example of using GDALRasterizeLayers that suits for my case? – user3468473 Jun 09 '14 at 17:36
  • Yes, it can be tricky to get the parameters correct. However, I've only used this part of the API via Python, so it is slightly different. [Here are some examples using Python in the test suite](https://trac.osgeo.org/gdal/browser/trunk/autotest/alg/rasterize.py), but I'm not seeing anything similar for [cpp](https://trac.osgeo.org/gdal/browser/trunk/autotest/cpp/) – Mike T Jun 09 '14 at 22:00