void object::test<10>() { char* wkt1 = "POLYGON((0 0, 10 10, 10 0, 0 0))"; err_ = OGR_G_CreateFromWkt(&wkt1, NULL, &g1_); ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_); ensure("Can't create geometry", NULL != g1_); char* wkt2 = "POLYGON((-90 -90, -90 90, 190 -90, -90 -90))"; err_ = OGR_G_CreateFromWkt(&wkt2, NULL, &g2_); ensure_equals("Can't import geometry from WKT", OGRERR_NONE, err_); ensure("Can't create geometry", NULL != g2_); ensure_equals("OGR_G_Within() failed with FALSE", OGR_G_Within(g1_, g2_), TRUE); ensure_equals("OGR_G_Within() failed with TRUE", OGR_G_Within(g2_, g1_), FALSE); }
bool CUtils::insideInPolygons(OGRDataSourceH poDS, double x, double y) { bool res = false; OGRGeometryH pt = OGR_G_CreateGeometry(wkbPoint); OGR_G_AddPoint_2D(pt, x, y); for(int iLayer = 0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++) { OGRLayerH poLayer = OGR_DS_GetLayer(poDS, iLayer); if(poLayer!=NULL) { OGREnvelope layerBounds; OGR_L_GetExtent(poLayer, &layerBounds, 1); if( (layerBounds.MinX <= x) && (layerBounds.MinY <= y) && (layerBounds.MaxX >= x) && (layerBounds.MaxY >= y) ) { OGR_L_ResetReading(poLayer); if(OGR_FD_GetGeomType( OGR_L_GetLayerDefn(poLayer) ) == wkbPolygon) { OGRFeatureH poFeat; while((poFeat = OGR_L_GetNextFeature(poLayer))!= NULL) { OGRGeometryH hGeom = OGR_F_GetGeometryRef(poFeat); if(OGR_G_Within(pt, hGeom)) { res = true; break; } } if(res) { OGR_L_ResetReading(poLayer); break; } } } } } OGR_G_DestroyGeometry(pt); return res; }