2

I have a space defined by a polyhedral surface, and I would like to check if a point is inside this space, and I would like to do this in python with gdal.

After trying the default installation of gdal with conda, there were some functions that did not work that I wanted regarding sfcgal, so I compiled gdal from source with sfcgal (as this seemed to contain extra 3D functionality) and geos,for python3. I have tried the following in python:

>>> from osgeo import ogr
>>> ps2 = 'POLYHEDRALSURFACE Z (((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))'
>>> geom2 = ogr.CreateGeometryFromWkt(ps2)
>>> geom2.CloseRings()
>>> point3 = 'POINT Z (0.5 1.5 0.5)'
>>> point3_g = ogr.CreateGeometryFromWkt(point3)
>>> point3_g.Within(geom1)
False
>>> # This is correct behavior
>>> point2 = 'POINT Z (0.5 0.5 1.5)'
>>> point2_g = ogr.CreateGeometryFromWkt(point2)
>>> point2_g.Within(geom1)
True
>>> # This is unexpected behavior!

Is there anything I am missing for gdal to treat the Z dimension like one of the other dimensions?

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.