I'm sure I must be missing something here but for the life of me I can't see what it might be. I have been struggling for the last hour with an issue with the Contains() method in OGR.

I am iterating through a grid square feature set and trying to perform a function when Polygon.Contains(Point) returns true. Both point and polygon are projected correctly to ETRS89(3035), but contains always returns false.

The map below illustrates one such point and square:

enter image description here

But the following returns false. Note the WKT is taken directly from QGIS to ensure an accurate test.

testPoly = ogr.CreateGeometryFromWkt("POLYGON ((3260000 3560000, 3260000 3570000, 3270000 3570000, 3270000 3560000, 3260000 3560000))")
testPoint = ogr.CreateGeometryFromWkt("POINT (310936.84887920797336847 319641.00836165697546676)")
print(testPoly.Contains(testPoint)) #Always returns false!!
  • That is odd, when you say Both point and polygon are projected correctly to ETRS89(3035) is it that the point and polygon are derived from a geometry storage type (shapefile, TAB etc) and the coordinate system of those geometries are correctly defined? Though the coordinates given 310936 is less than any coordinate in the defined polygon when corrected to 326936.84 356641.00 contains still returns False. – Michael Stimson Jun 5 '19 at 0:06
  • 1
    Distance from the point to the polygon is about 4380 km. Please clarify what you are trying to do. The point corrected by @MichaelStimson is not much better - there should be 7 full meters, not 6 in the coordinates to match with the polygon. – user30184 Jun 5 '19 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.