private static OSGeo.OGR.Geometry GetOgrGeometry(wkbGeometryType geometryType, IEnumerable <ICoordinate> coordinates) { OSGeo.OGR.Geometry ogrGeometry = null; var firstCoord = coordinates?.FirstOrDefault(); if (firstCoord != null) { ogrGeometry = new OSGeo.OGR.Geometry(geometryType); Action <ICoordinate> addCoordAction; switch (firstCoord.Dimension) { case 2: addCoordAction = (coordinate) => ogrGeometry.AddPoint_2D(coordinate.X, coordinate.Y); break; case 3: addCoordAction = (coordinate) => ogrGeometry.AddPoint(coordinate.X, coordinate.Y, coordinate.Z); break; case 4: addCoordAction = (coordinate) => ogrGeometry.AddPointZM(coordinate.X, coordinate.Y, coordinate.Z, coordinate.M); break; default: return(ogrGeometry); } foreach (var item in coordinates) { addCoordAction(item); } } return(ogrGeometry); }
private static void AddPoint(this OSGeo.OGR.Geometry geometry, double x, double y, double z = double.NaN, double m = double.NaN) { if (geometry != null) { if (double.IsNaN(z)) { if (double.IsNaN(m)) { geometry.AddPoint_2D(x, y); } else { geometry.AddPointM(x, y, m); } } else { if (double.IsNaN(m)) { geometry.AddPoint(x, y, z); } else { geometry.AddPointZM(x, y, z, m); } } } }
public static OSGeo.OGR.Geometry ToOgrPoint(double x, double y, double z = double.NaN, double m = double.NaN) { OSGeo.OGR.Geometry ogrGeometry = new OSGeo.OGR.Geometry(wkbGeometryType.wkbPoint); if (double.IsNaN(z)) { ogrGeometry.AddPoint_2D(x, y); } else { if (double.IsNaN(m)) { ogrGeometry.AddPoint(x, y, z); } else { ogrGeometry.AddPointZM(x, y, z, m); } } return(ogrGeometry); }