From 1035839ad440abd9feb77136dfb7e9531889e2de Mon Sep 17 00:00:00 2001 From: Grzegorz Osimowicz Date: Thu, 8 Aug 2024 15:51:38 +0200 Subject: [PATCH] Fixed saving and loading multipoint geometry with only one point --- .../OracleGeometryReader.cs | 13 ++++++++++--- .../OracleGeometryWriter.cs | 2 +- src/NetTopologySuite.IO.Oracle/Sdo/SdoEType.cs | 1 + test/NetTopologySuite.IO.Oracle.Test/OracleTest.cs | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/NetTopologySuite.IO.Oracle/OracleGeometryReader.cs b/src/NetTopologySuite.IO.Oracle/OracleGeometryReader.cs index 808293b..006e72a 100644 --- a/src/NetTopologySuite.IO.Oracle/OracleGeometryReader.cs +++ b/src/NetTopologySuite.IO.Oracle/OracleGeometryReader.cs @@ -72,6 +72,11 @@ public Geometry Read(SdoGeometry geom) var factory = _services.CreateGeometryFactory(srid); var retVal = Create(factory, gType, point, geom.ElemArray, geom.OrdinatesArray); + + if (retVal == null) + { + return null; + } retVal.SRID = srid; return retVal; @@ -271,7 +276,9 @@ private GeometryCollection CreateCollection(GeometryFactory factory, int dim, in } break; - + case SdoEType.Multipoint: + geom = CreateMultiPoint(factory, dim, lrs, elemInfo, i, coords); + break; case SdoEType.Line: geom = CreateLine(factory, dim, lrs, elemInfo, i, coords); @@ -403,9 +410,9 @@ private MultiPoint CreateMultiPoint(GeometryFactory factory, int dim, int lrs, d if (!(sOffset >= 1) || !(sOffset <= coords.Count)) throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset + " inconsistent with ORDINATES length " + coords.Count); - if (etype != SdoEType.Coordinate) + if (etype != SdoEType.Coordinate && etype != SdoEType.Multipoint) throw new ArgumentException("ETYPE " + etype + " inconsistent with expected POINT"); - if (!(interpretation > 1)) + if (interpretation == 0) { return null; } diff --git a/src/NetTopologySuite.IO.Oracle/OracleGeometryWriter.cs b/src/NetTopologySuite.IO.Oracle/OracleGeometryWriter.cs index 4acc32d..dc24490 100644 --- a/src/NetTopologySuite.IO.Oracle/OracleGeometryWriter.cs +++ b/src/NetTopologySuite.IO.Oracle/OracleGeometryWriter.cs @@ -264,7 +264,7 @@ private static int ProcessMultiPoint(MultiPoint multiPoint, int dimension, List< // just ProcessPoint for each point, since that would append to elemInfoList multiple // times. instead, elemInfoList gets incremented just once. *shrugs*. elemInfoList.Add(pos); - elemInfoList.Add((int)SdoEType.Coordinate); + elemInfoList.Add((int)SdoEType.Multipoint); elemInfoList.Add(cnt); for (int i = 0; i < cnt; i++) diff --git a/src/NetTopologySuite.IO.Oracle/Sdo/SdoEType.cs b/src/NetTopologySuite.IO.Oracle/Sdo/SdoEType.cs index 04573d2..7188df7 100644 --- a/src/NetTopologySuite.IO.Oracle/Sdo/SdoEType.cs +++ b/src/NetTopologySuite.IO.Oracle/Sdo/SdoEType.cs @@ -8,6 +8,7 @@ internal enum SdoEType Coordinate = 1, Line = 2, Polygon = 3, + Multipoint = 4, PolygonExterior = 1003, PolygonInterior = 2003 diff --git a/test/NetTopologySuite.IO.Oracle.Test/OracleTest.cs b/test/NetTopologySuite.IO.Oracle.Test/OracleTest.cs index 6154b70..6a0de6c 100644 --- a/test/NetTopologySuite.IO.Oracle.Test/OracleTest.cs +++ b/test/NetTopologySuite.IO.Oracle.Test/OracleTest.cs @@ -38,6 +38,7 @@ public void CCWTestsOnPolygon() [TestCase("POINT(10 10)", 4326)] [TestCase("POINT Z(10 10 0)", -1)] [TestCase("POINT Z(10 10 20)", -1)] + [TestCase("MULTIPOINT(11 12)", -1)] [TestCase("MULTIPOINT(11 12, 20 20)", -1)] [TestCase("MULTIPOINT Z(11 12 12, 20 20 20)", -1)] [TestCase("LINESTRING(10 10,20 20,50 50,34 34)", -1)] @@ -82,6 +83,7 @@ public void BasicConversion(string wkt, int srid) /// /// /// + [TestCase("GEOMETRYCOLLECTION(MULTIPOINT(11 12))", "GEOMETRYCOLLECTION(MULTIPOINT(11 12))", - 1)] [TestCase("GEOMETRYCOLLECTION(MULTIPOINT(11 12, 20 20))", "GEOMETRYCOLLECTION(MULTIPOINT(11 12, 20 20))", - 1)] [TestCase("GEOMETRYCOLLECTION(MULTIPOLYGON(((10 10,20 10,20 20,10 20,10 10),(5 5,5 6,6 6,6 5,5 5)),((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5))))", "GEOMETRYCOLLECTION(POLYGON((10 10,20 10,20 20,10 20,10 10),(5 5,5 6,6 6,6 5,5 5)),POLYGON((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5)))", - 1)] [TestCase("GEOMETRYCOLLECTION(MULTILINESTRING((10 10,20 10,20 20,10 20,10 10),(5 5,5 6,6 6,6 5,5 5)))", "GEOMETRYCOLLECTION(LINESTRING(10 10,20 10,20 20,10 20,10 10),LINESTRING(5 5,5 6,6 6,6 5,5 5))", -1)]