/// <summary> /// Set the SRID from PostGis to NetTopology equivalent. /// Throw InvalidCastException if SRID is out of range. /// Throw ArgumentNullException if any of input marameter is null. /// </summary> /// <param name="netTopologyGeom">the geometry to set the SRID</param> /// <param name="postGisGeom">the geometry to get the SRID</param> private static void SetSRID(Geometry netTopologyGeom, PostgisGeometry postGisGeom) { if (postGisGeom != null && netTopologyGeom != null) { if (postGisGeom.SRID > Int32.MaxValue) { throw new InvalidCastException("SRID is out of range value."); } else { netTopologyGeom.SRID = (int)postGisGeom.SRID; } } else { throw new ArgumentNullException(); } }
/// <summary> /// Convert the first PostGis Geometry column or the column specified by geomOrdinal into the corresponding NetTopologyGeometry /// Can throw the following Exceptions /// - ArgumentNullException /// - InvalidCastException in case of SRID not compatible for example. /// - NotImplementedException if no converter is avaialble for this type. /// </summary> /// <param name="pgCursor">The cursor where to look for the Geometry column</param> /// <param name="geomOrdinal">optionnal, geom. column index if known, otherwise will be search for.</param> /// <returns>the NetTopology geometry equivalent.</returns> public static Geometry ConvertFrom(IFieldValueGetter pgCursor, int?geomOrdinal = null) { Geometry retour = null; if (pgCursor != null) { PostgisGeometry geometry = pgCursor.GetFieldValue <PostgisGeometry>(GetGeomtryColumnIndex(pgCursor, geomOrdinal)); if (geometry is PostgisPoint) { retour = ProcessPoint((PostgisPoint)geometry); } else if (geometry is PostgisMultiPoint) { retour = ProcessMultiPoint((PostgisMultiPoint)geometry); } else if (geometry is PostgisLineString) { retour = ProcessLineString((PostgisLineString)geometry); } else if (geometry is PostgisMultiLineString) { retour = ProcessMultiLineString((PostgisMultiLineString)geometry); } else if (geometry is PostgisPolygon) { retour = ProcessPolygon((PostgisPolygon)geometry); } else if (geometry is PostgisMultiPolygon) { retour = ProcessMultiPolygon((PostgisMultiPolygon)geometry); } else { throw new NotImplementedException(); } SetSRID(retour, geometry); } else { throw new ArgumentNullException(); } return(retour); }
public void CopyBinaryArray(TestAtt a) { using (var c = OpenConnection()) { using (var cmd = new NpgsqlCommand("CREATE TEMPORARY TABLE testcopybinarray (g geometry[3])", c)) cmd.ExecuteNonQuery(); var t = new PostgisGeometry[3] { a.Geom, a.Geom, a.Geom }; try { using (var writer = c.BeginBinaryImport("COPY testcopybinarray (g) FROM STDIN (FORMAT BINARY)")) { for (var i = 0; i < 1000; i++) { writer.WriteRow(new[] { t }); } writer.Complete(); } } catch (Exception e) { Assert.Fail($"Copy from stdin failed with {e} at geometry {a.Geom}."); } try { using (var rdr = c.BeginBinaryExport("COPY testcopybinarray (g) TO STDOUT (FORMAT BINARY)")) for (var i = 0; i < 1000; i++) { rdr.StartRow(); Assert.IsTrue(t.SequenceEqual(rdr.Read <PostgisGeometry[]>())); } } catch (Exception e) { Assert.Fail($"Copy to stdout failed with {e} at geometry {a.Geom}."); } } }
public static int STCoordDim(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static bool StIntersects(this PostgisGeometry geomA, PostgisGeometry geomB) { throw new InvalidOperationException(); }
public static PostgisGeometry STShortestLine(this PostgisGeometry geom1, PostgisGeometry geom2) { throw new InvalidOperationException(); }
public static PostgisGeometry StSetSrId(this PostgisGeometry geom, int srid) { throw new InvalidOperationException(); }
public static string StGeometryType(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static int StDimension(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry StStartPoint(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry STBuffer(this PostgisGeometry geom, double radius) { throw new InvalidOperationException(); }
public static bool STEquals(this PostgisGeometry geomA, PostgisGeometry geomB) { throw new InvalidOperationException(); }
public static bool STDWithin(this PostgisGeometry geom1, PostgisGeometry geom2, double distance) { throw new InvalidOperationException(); }
public static double STDistance(this PostgisGeometry geom1, PostgisGeometry geom2) { throw new InvalidOperationException(); }
public static PostgisGeometry STCentroid(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static bool STTouches(this PostgisGeometry geom1, PostgisGeometry geom2) { throw new InvalidOperationException(); }
public static int StNumGeometries(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry StPointN(this PostgisGeometry geom, int n) { throw new InvalidOperationException(); }
public static PostgisGeometry STConvexHull(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static double StY(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry STMinimumBoundingCircle(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry StEnvelope(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry STUnion(this PostgisGeometry geomA, PostgisGeometry geomB) { throw new InvalidOperationException(); }
public static bool StIsEmpty(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry STTransform(this PostgisGeometry geom, int srid) { throw new InvalidOperationException(); }
public void CopyBinaryArray(TestAtt a) { using (var c = OpenConnection()) { using (var cmd = new NpgsqlCommand("CREATE TEMPORARY TABLE testcopybinarray (g geometry[3])", c)) cmd.ExecuteNonQuery(); var t = new PostgisGeometry[3] { a.Geom, a.Geom, a.Geom }; try { using (var writer = c.BeginBinaryImport("COPY testcopybinarray (g) FROM STDIN (FORMAT BINARY)")) for (int i = 0; i < 1000; i++) writer.WriteRow(new[] {t}); } catch(Exception e) { Assert.Fail($"Copy from stdin failed with {e} at geometry {a.Geom}."); } try { using (var rdr = c.BeginBinaryExport("COPY testcopybinarray (g) TO STDOUT (FORMAT BINARY)")) for (int i = 0; i < 1000; i++) { rdr.StartRow(); Assert.IsTrue(t.SequenceEqual(rdr.Read<PostgisGeometry[]>())); } } catch(Exception e) { Assert.Fail($"Copy to stdout failed with {e} at geometry {a.Geom}."); } } }
public static bool StDisjoint(this PostgisGeometry geomA, PostgisGeometry geomB) { throw new InvalidOperationException(); }
public static PostgisGeometry STReverse(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static bool STIsSimple(this PostgisGeometry geom) { throw new InvalidOperationException(); }
public static PostgisGeometry STTranslate(this PostgisGeometry geom, double deltax, double deltay) { throw new InvalidOperationException(); }
public static byte[] StAsBinary(this PostgisGeometry geom) { throw new InvalidOperationException(); }