From Programmatically manipulate GPX data
- osgeo.ogr can read all these formats: OGR Vector Formats
- osgeo.ogr and shapely support 3D:
from osgeo import ogr
point = ogr.Geometry(ogr.wkbPoint25D)
point.AddPoint(5,4,4)
point.GetZ()
4.0
from shapely.geometry import Point
point1 = Point(5,4,4)
point1.has_z
True
point1.z
4.0
-
you can change projections with osgeo.ogr: see Projecting shapefile with transformation using OGR in python and many, many other examples
-
transform the geometries between ogr and shapely is easy:
from shapely.wkb import loads
point = ogr.Geometry(ogr.wkbPoint25D)
point.AddPoint(5,4,4)
point_shapely = loads(point.ExportToWkb())
point_shapely.has_z
True
- inverse
point_ogr = ogr.CreateGeometryFromWkb(point_shapely.wkb)
print point_ogr.GetX(), point_ogr.GetY(), point_ogr.GetZ()
5.0 4.0 0.0
- so you can use ogr or pyproj to change the projection of a shapely geometry, (see Measuring distance in spherical Mercator vs zoned UTM for example)
- and shapely or analytical geometry allows to project a point on a PoLyline (see How to draw perpendicular lines in QGIS?, with PyQGIS, but it is similar with ogr)
As one example of the process, here are the results of the creation of geological cross-sections from 3D points (from Python: Using vector and raster layers in a geological perspective, without GIS software, in French, but the scripts and the figures are universal).
3D representation (distance between points):
cumulative distance (geological cross-section)