public virtual void  Intersection(string wktA, string wktB, PrecisionModel pm)
        {
            Console.WriteLine("Running example using Precision Model = " + pm);
            GeometryFactory fact   = new GeometryFactory(pm);
            WKTReader       wktRdr = new WKTReader(fact);

            IGeometry A = wktRdr.Read(wktA);
            IGeometry B = wktRdr.Read(wktB);
            IGeometry C = A.Intersection(B);

            Console.WriteLine("A intersection B = " + C);
        }
        public void TestIsValid()
        {
            var geom1 = _reader.Read(
                @"POLYGON((719522.38754834363 6176994.3322154824
24.194645633515528,719522.38754834374 6176994.3322154824
24.194645633477126,719522.93551468418 6176993.6599836433
23.741832765874967,719521.12955784285 6176985.9724558685
21.2264974621797,719521.72333959443 6176985.3237007372
20.768071704926587,719507.01810000045 6176973.3368000006
20.768071704926587,719502.88183502527 6176978.4322331771
24.194645633542077,719498.62799999863 6176983.6725
20.670674058571322,719512.84729999851 6176995.0215000017
20.768524674823045,719513.44049503584 6176994.3733859034
21.226497462846655,719521.884040508 6176994.949906704
23.77857112312677,719522.38754834363 6176994.3322154824 24.194645633515528))");

            Assert.IsNotNull(geom1);
            Assert.IsTrue(geom1.IsValid);

            var geom2 = _reader.Read(
                @"POLYGON((719496.72750000039 6177012.6337
21.226497462484563,719501.41240093729 6177017.249279663
23.760978631209998,719526.8258614993 6176989.4829953332
23.760978631060315,719521.72333959443 6176985.3237007372
21.226497462484563,719512.84729999851 6176995.0215000017
21.226497462560005,719496.72750000039 6177012.6337 21.226497462484563))");

            Assert.IsNotNull(geom2);
            Assert.IsTrue(geom2.IsValid);

            var expected = _reader.Read(
                @"POLYGON ((719522.3875483436 6176994.332215482 24.194645633515528,
719522.3875483437 6176994.332215482 24.194645633477126, 719526.8258614993
6176989.482995333 23.760978631060315, 719521.7233395944 6176985.323700737
21.226497462484563, 719507.0181000005 6176973.336800001 20.768071704926587,
719502.8818350253 6176978.432233177 24.194645633542077, 719498.6279999986
6176983.6725 20.670674058571322, 719512.8472999985 6176995.021500002
20.768524674823045, 719496.7275000004 6177012.6337 21.226497462484563,
719501.4124009373 6177017.249279663 23.760978631209998, 719521.8258356823
6176994.945932509, 719521.884040508 6176994.949906704 23.77857112312677,
719522.3875483436 6176994.332215482 24.194645633515528))");

            Assert.IsNotNull(expected);
            Assert.IsTrue(expected.IsValid);

            var actual = geom1.Union(geom2);

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.IsValid);

            //Assert.IsTrue(expected.EqualsExact(actual));
            Assert.IsTrue(1 - new HausdorffSimilarityMeasure().Measure(expected, actual) < 1E7);
        }
Example #3
0
        public RoundTripBase()
        {
            LayerName         = "water";
            FeatureProperties = new AttributesTable(new[]
            {
                new KeyValuePair <string, object>(UID, 123U),
                new KeyValuePair <string, object>("foo", "bar"),
                new KeyValuePair <string, object>("baz", "foo"),
            });

            FeatureGeometry = Reader.Read("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))");
        }
Example #4
0
        public void MultiPolygonCoordinatesTest()
        {
            // arrange
            var       geomety = _wktReader.Read("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))");
            const int expectedCoordinateCount = 14;

            // act
            var enumeration = geomety.Coordinates;

            // assert
            Assert.AreEqual(expectedCoordinateCount, enumeration.Count());
        }
        public void TestML()
        {
            {
                const double     scale           = 2.0E10;
                IPrecisionModel  precisionModel  = new PrecisionModel(scale);
                IGeometryFactory geometryFactory = new GeometryFactory(precisionModel);

                var reader      = new WKTReader(geometryFactory);
                var lineStringA = (ILineString)
                                  reader.Read("LINESTRING (-93.40178610435 -235.5437531975, -401.24229900825 403.69365857925)");
                var lineStringB = (ILineString)
                                  reader.Read("LINESTRING (-50.0134121926 -145.44686640725, -357.8539250965 493.7905453695)");
                var lineStringC = (ILineString)
                                  reader.Read("LINESTRING (-193.8964147753 -30.64653554935, -186.68866383205 -34.1176054623)");

                var middlePoint = (IPoint)reader.Read("POINT (-203.93366864454998 174.171839481125)");

                var lineStrings = new List <ILineString>();
                lineStrings.Add(lineStringA);
                lineStrings.Add(lineStringB);
                lineStrings.Add(lineStringC);

                var noder            = new GeometryNoder(geometryFactory.PrecisionModel);
                var nodedLineStrings = noder.Node(lineStrings.ToArray());

                var shortestDistanceToPointBeforeNoding = double.MaxValue;

                foreach (var lineString in lineStrings)
                {
                    shortestDistanceToPointBeforeNoding = Math.Min(lineString.Distance(middlePoint),
                                                                   shortestDistanceToPointBeforeNoding);
                }

                var shortestDistanceToPointAfterNoding = Double.MaxValue;

                foreach (var lineString in nodedLineStrings)
                {
                    shortestDistanceToPointAfterNoding = Math.Min(lineString.Distance(middlePoint),
                                                                  shortestDistanceToPointAfterNoding);
                }

                var difference = Math.Abs(shortestDistanceToPointAfterNoding - shortestDistanceToPointBeforeNoding);


                Console.WriteLine("Scale: {0}", scale);
                Console.WriteLine("Distance to point before noding: {0}", shortestDistanceToPointBeforeNoding);
                Console.WriteLine("Distance to point after noding:  {0}", shortestDistanceToPointAfterNoding);
                Console.WriteLine("Difference is {0} and should be lesser than {1}", difference, 1.0 / scale);

                const double roughTolerance = 10.0;
                Assert.IsTrue(difference < roughTolerance, "this difference should should be lesser than " + 1.0 / scale);
            }
        }
Example #6
0
        private static void RunBoundaryTest(string wkt, IBoundaryNodeRule bnRule, string wktExpected)
        {
            var g        = rdr.Read(wkt);
            var expected = rdr.Read(wktExpected);

            var op       = new BoundaryOp(g, bnRule);
            var boundary = op.GetBoundary();

            boundary.Normalize();
            //    System.out.println("Computed Boundary = " + boundary);
            Assert.IsTrue(boundary.EqualsExact(expected));
        }
Example #7
0
    private DataTable GetShapeTable(string sql, OgcGeometryType geometryType)
    {
        DataTable table = null;

        using (OleDbConnection connection = AppContext.GetDatabaseConnection())
        {
            table = new DataTable();

            using (OleDbDataAdapter adapter = new OleDbDataAdapter(sql, connection))
            {
                adapter.Fill(table);
            }

            table.Columns["Shape"].ColumnName = "ShapeString";

            switch (geometryType)
            {
            case OgcGeometryType.Point: table.Columns.Add("Shape", typeof(IPoint)); break;

            case OgcGeometryType.LineString: table.Columns.Add("Shape", typeof(IMultiLineString)); break;

            case OgcGeometryType.Polygon: table.Columns.Add("Shape", typeof(IMultiPolygon)); break;
            }

            WKTReader wktReader = new WKTReader();

            foreach (DataRow row in table.Rows)
            {
                switch (geometryType)
                {
                case OgcGeometryType.Point:
                    row["Shape"] = (IPoint)wktReader.Read((string)row["ShapeString"]);
                    break;

                case OgcGeometryType.LineString:
                    ILineString      lineString      = (ILineString)wktReader.Read((string)row["ShapeString"]);
                    IMultiLineString multiLineString = new MultiLineString(new ILineString[] { lineString });
                    row["Shape"] = multiLineString;
                    break;

                case OgcGeometryType.Polygon:
                    IPolygon      polygon      = (IPolygon)wktReader.Read((string)row["ShapeString"]);
                    IMultiPolygon multiPolygon = new MultiPolygon(new IPolygon[] { polygon });
                    row["Shape"] = multiPolygon;
                    break;
                }
            }

            table.Columns.Remove("ShapeString");
        }

        return(table);
    }
        public void Test1()
        {
            IGeometry geom = _wktReader.Read("POLYGON ((0 0, 0 10, 4 10, 4 8, 6 8, 6 10, 10 10, 10 0, 0 0))");
            DelaunayTriangulationBuilder dtb = new DelaunayTriangulationBuilder();

            dtb.SetSites(geom);
            IMultiLineString resultEdges = dtb.GetEdges(geom.Factory);

            Console.WriteLine(resultEdges.AsText());
            IGeometryCollection resultTriangles = dtb.GetTriangles(geom.Factory);

            Console.WriteLine(resultTriangles.AsText());
        }
Example #9
0
        public virtual void  Difference(string wktA, string wktB, PrecisionModel pm)
        {
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("Running example using Precision Model = " + pm);
            var gs     = new NtsGeometryServices(pm);
            var wktRdr = new WKTReader(gs);

            var A = wktRdr.Read(wktA);
            var B = wktRdr.Read(wktB);
            var C = A.Difference(B);

            Console.WriteLine("A intersection B = " + C);
        }
Example #10
0
        public void Test1()
        {
            var geom = _wktReader.Read("POLYGON ((0 0, 0 10, 4 10, 4 8, 6 8, 6 10, 10 10, 10 0, 0 0))");
            var dtb  = new DelaunayTriangulationBuilder();

            dtb.SetSites(geom);
            var resultEdges = dtb.GetEdges(geom.Factory);

            Console.WriteLine(resultEdges.AsText());
            var resultTriangles = dtb.GetTriangles(geom.Factory);

            Console.WriteLine(resultTriangles.AsText());
        }
Example #11
0
        public void Buffer()
        {
            var geometry = reader.Read(
                @"POLYGON((719068.76798974432 6178827.370335687 31.0995,719070.73569863627 6178830.5852228012 31.0995,719076.87100000086 6178826.8299 31.0995,719078.2722488807 6178825.9722172953 31.0995,719076.30480000074 6178822.7577000009 31.0995,719068.76798974432 6178827.370335687 31.0995))");

            Assert.IsNotNull(geometry);
            Assert.IsTrue(geometry.IsValid);

            var buffered = geometry.Buffer(0.01);

            Assert.IsNotNull(buffered);
            Assert.IsTrue(buffered.IsValid);
            Assert.IsFalse(buffered.EqualsExact(geometry));
        }
Example #12
0
        private List <JObject> FilterPosition(List <JObject> batch, double minX, double minY, double maxX, double maxY)
        {
            var      filteredBatch   = new List <JObject>();
            var      geometryFactory = new GeometryFactory();
            Geometry point;
            var      rdr         = new WKTReader(geometryFactory);
            var      boundingBox = new NetTopologySuite.Geometries.Envelope(minX, maxX, minY, maxY);

            //Check if bounding box was provided, if there are no values present then return original batch
            if (minX == 0)
            {
                return(batch);
            }
            else
            {
                foreach (var document in batch)
                {
                    try
                    {
                        foreach (var jp in document.Properties().ToList())
                        {
                            if (jp.Name == "byg404Koordinat")
                            {
                                point = rdr.Read(jp.Value.ToString());
                                if (boundingBox.Intersects(point.EnvelopeInternal))
                                {
                                    filteredBatch.Add(document);
                                }
                            }
                            else if (jp.Name == "tek109Koordinat")
                            {
                                point = rdr.Read(jp.Value.ToString());
                                if (boundingBox.Intersects(point.EnvelopeInternal))
                                {
                                    filteredBatch.Add(document);
                                }
                            }
                        }
                    }
                    catch (NetTopologySuite.IO.ParseException e)
                    {
                        _logger.LogError("Error writing data: {0}.", e.GetType().Name);
                        _logger.LogInformation(document.ToString());
                        break;
                    }
                }

                return(filteredBatch);
            }
        }
        public void TestManyIdenticalPoints()
        {
            Coordinate[] pts = new Coordinate[100];
            for (int i = 0; i < 99; i++)
            {
                pts[i] = new Coordinate(0, 0);
            }
            pts[99] = new Coordinate(1, 1);
            ConvexHull ch               = new ConvexHull(pts, _geometryFactory);
            IGeometry  actualGeometry   = ch.GetConvexHull();
            IGeometry  expectedGeometry = _reader.Read("LINESTRING (0 0, 1 1)");

            Assert.IsTrue(actualGeometry.EqualsExact(expectedGeometry));
        }
Example #14
0
 public static Func <IOpenSearchResultItem, bool> GetGeometryValidator(Feature feature)
 {
     return((IOpenSearchResultItem item)
            =>
     {
         var geom = item.FindGeometry();
         if (geom == null)
         {
             log.WarnFormat("No geometry found for item {0}", item.Identifier);
             return false;
         }
         return feature.Geometry.Buffer(0.5).Intersects(wktreader.Read(geom.ToWkt()));
     });
 }
        public void expected_exception_using_difference()
        {
            var reader = new WKTReader();
            var g1     = reader.Read(
                @"MULTIPOLYGON (((-6254384.9272019733 -2428784.4316727975, -6254448.2889524475 -2428784.4324241709, -6254399.1165902149 -2428657.1297944547, -6254384.9272019733 -2428784.4316727975)), ((-6254289.7647291981 -2428374.0280918181, -6254076.9438697845 -2428906.9316744655, -6254243.0436896412 -2428910.1951122279, -6254417.483366685 -2428913.62240691, -6254463.6874999283 -2428837.6061908188, -6254325.4337456506 -2428846.8321458441, -6254362.340771623 -2428561.9206525073, -6254289.7647291981 -2428374.0280918181)), ((-6254073.3327726927 -2428940.0660867151, -6254140.5877170712 -2429108.987212894, -6254344.0507978722 -2429034.4355382724, -6254399.2597350832 -2428943.6043894938, -6254073.3327726927 -2428940.0660867151)), ((-6254753.3077126574 -2428361.1156448247, -6254698.72562374 -2428213.1250561425, -6254332.4671062678 -2428330.1534979446, -6254488.1171720289 -2428797.4138724417, -6254753.3077126574 -2428361.1156448247)), ((-6254004.2787381727 -2428950.0691508525, -6254318.7635007482 -2428263.0369477733, -6254122.8733536266 -2428231.3153878264, -6253776.8295307625 -2428881.4327149931, -6251457.7266220115 -2428679.5463844533, -6251326.4963204153 -2429188.8054935131, -6253531.782834392 -2429376.9298687372, -6254004.2787381727 -2428950.0691508525)))");

            Assert.IsNotNull(g1);
            Assert.IsTrue(g1.IsValid);
            var g2 = reader.Read(
                @"MULTIPOLYGON (((-6254444.050800845 -2428784.4323739046, -6254448.2889524437 -2428784.4324241676, -6254444.0508008441 -2428773.4602475408, -6254438.6335666114 -2428759.4355366551, -6254428.97697854 -2428734.4355366575, -6254419.3203904629 -2428709.4355366589, -6254419.0508008488 -2428708.7375944532, -6254409.6638023909 -2428684.4355366575, -6254400.0072143227 -2428659.435536663, -6254399.1165902093 -2428657.1297944514, -6254398.85958637 -2428659.4355366565, -6254396.07302336 -2428684.4355366593, -6254394.0508008441 -2428702.5781598496, -6254393.2864603419 -2428709.4355366584, -6254390.499897331 -2428734.4355366556, -6254387.7133343164 -2428759.4355366491, -6254384.9272019733 -2428784.4316727975, -6254394.0508008422 -2428784.4317809842, -6254419.0508008394 -2428784.4320774451, -6254444.050800845 -2428784.4323739046)), ((-6254444.0507973628 -2428859.4355378593, -6254444.0507973656 -2428869.9129937063, -6254450.4191986173 -2428859.43553786, -6254463.6874999283 -2428837.6061908188, -6254444.0507973628 -2428838.9165880294, -6254419.0507973675 -2428840.58488903, -6254394.0507973628 -2428842.253190022, -6254369.0507973591 -2428843.9214910129, -6254344.0507973544 -2428845.5897920118, -6254325.4337456506 -2428846.8321458441, -6254327.0395844625 -2428834.4355378533, -6254330.2780485861 -2428809.4355378528, -6254333.5165127087 -2428784.4355378593, -6254336.7549768286 -2428759.4355378575, -6254339.993440954 -2428734.4355378621, -6254343.231905072 -2428709.4355378593, -6254344.0507973712 -2428703.1139278188, -6254346.4703691984 -2428684.4355378631, -6254349.70883332 -2428659.4355378686, -6254352.9472974436 -2428634.4355378672, -6254356.1857615709 -2428609.4355378728, -6254359.42422569 -2428584.4355378705, -6254362.340771623 -2428561.9206525073, -6254361.3808624921 -2428559.4355378714, -6254351.7242744239 -2428534.4355378784, -6254344.0507973786 -2428514.5696261721, -6254342.0676863473 -2428509.4355378719, -6254332.4110982772 -2428484.435537877, -6254322.7545102052 -2428459.435537877, -6254319.0507973842 -2428449.846973083, -6254319.0507973833 -2428459.4355378728, -6254319.0507973805 -2428449.8469730811, -6254313.09792213 -2428434.435537878, -6254303.4413340567 -2428409.4355378794, -6254294.050797388 -2428385.124319992, -6254293.7847459819 -2428384.4355378775, -6254289.7647291981 -2428374.0280918181, -6254285.6084020734 -2428384.4355378742, -6254275.6243793406 -2428409.4355378747, -6254269.0507973833 -2428425.8957917569, -6254265.6403566087 -2428434.4355378747, -6254255.6563338693 -2428459.4355378691, -6254245.6723111346 -2428484.4355378696, -6254244.0507973777 -2428488.4958094717, -6254235.6882884027 -2428509.4355378668, -6254225.7042656615 -2428534.4355378617, -6254219.0507973675 -2428551.0958271823, -6254215.7202429362 -2428559.4355378626, -6254205.7362201922 -2428584.4355378547, -6254195.752197451 -2428609.4355378523, -6254194.0507973619 -2428613.6958449022, -6254185.7681747228 -2428634.4355378537, -6254175.7841519862 -2428659.4355378547, -6254169.0507973526 -2428676.2958626165, -6254165.8001292506 -2428684.4355378463, -6254155.8161065178 -2428709.4355378477, -6254145.8320837785 -2428734.4355378472, -6254144.050797347 -2428738.8958803294, -6254135.84806104 -2428759.4355378412, -6254125.8640383054 -2428784.4355378421, -6254119.0507973451 -2428801.49589804, -6254115.8800155725 -2428809.4355378379, -6254105.8959928416 -2428834.4355378356, -6254095.9119701013 -2428859.4355378351, -6254094.0507973349 -2428864.0959157594, -6254085.9279473675 -2428884.4355378319, -6254076.9438697845 -2428906.9316744655, -6254094.0507973265 -2428907.2677819543, -6254119.05079733 -2428907.758968187, -6254144.0507973321 -2428908.2501544147, -6254169.0507973339 -2428908.7413406391, -6254194.05079734 -2428909.2325268677, -6254204.3834856767 -2428909.4355378374, -6254219.0507973414 -2428909.7237130953, -6254243.0436896412 -2428910.1951122279, -6254244.050797346 -2428910.2148993253, -6254269.0507973451 -2428910.7060855534, -6254294.0507973488 -2428911.1972717838, -6254319.0507973544 -2428911.6884580115, -6254344.050797347 -2428912.1796442387, -6254369.0507973535 -2428912.6708304686, -6254394.05079736 -2428913.1620166982, -6254417.4833666813 -2428913.6224069092, -6254419.05079736 -2428911.0436300607, -6254420.0282270536 -2428909.4355378519, -6254435.2237128373 -2428884.4355378575, -6254444.0507973637 -2428869.9129937077, -6254444.0507973628 -2428859.4355378593)), ((-6254753.3077126583 -2428361.11564482, -6254752.6880535092 -2428359.4355383315, -6254744.050797944 -2428336.0170037593, -6254743.4675197275 -2428334.4355383296, -6254734.24698594 -2428309.4355383338, -6254725.0264521576 -2428284.4355383362, -6254719.050797943 -2428268.2335093888, -6254715.8059183694 -2428259.4355383315, -6254706.5853845831 -2428234.4355383338, -6254698.72562374 -2428213.1250561425, -6254694.0507979412 -2428214.6187758865, -6254669.0507979458 -2428222.6068796609, -6254644.050797943 -2428230.5949834352, -6254632.0311903935 -2428234.4355383315, -6254619.0507979337 -2428238.583087205, -6254594.0507979393 -2428246.5711909803, -6254569.0507979374 -2428254.5592947542, -6254553.7898433041 -2428259.4355383259, -6254544.0507979337 -2428262.5473985276, -6254519.0507979309 -2428270.5355022973, -6254494.0507979263 -2428278.5236060717, -6254475.5484962119 -2428284.4355383213, -6254469.0507979272 -2428286.5117098419, -6254444.0507979225 -2428294.4998136181, -6254419.0507979235 -2428302.4879173888, -6254397.30714911 -2428309.435538311, -6254394.0507979216 -2428310.4760211641, -6254369.0507979179 -2428318.4641249366, -6254344.0507979142 -2428326.452228711, -6254332.4671062678 -2428330.1534979446, -6254333.8935055509 -2428334.4355383092, -6254342.2213070495 -2428359.4355383092, -6254344.0507979114 -2428364.9276566892, -6254350.5491085406 -2428384.4355383068, -6254358.8769100271 -2428409.4355383008, -6254367.2047115248 -2428434.4355383045, -6254369.0507979132 -2428439.9774763263, -6254375.5325130168 -2428459.4355383017, -6254383.86031451 -2428484.435538304, -6254392.1881159982 -2428509.4355383022, -6254394.0507979095 -2428515.0272959573, -6254400.515917493 -2428534.4355383036, -6254408.8437189814 -2428559.4355383026, -6254417.1715204753 -2428584.4355383003, -6254419.0507979095 -2428590.0771155925, -6254425.4993219655 -2428609.4355382971, -6254433.8271234594 -2428634.4355382989, -6254442.1549249552 -2428659.4355382989, -6254444.0507979048 -2428665.126935224, -6254450.4827264436 -2428684.435538298, -6254458.8105279356 -2428709.4355382957, -6254467.138329424 -2428734.4355382966, -6254469.050797902 -2428740.1767548565, -6254475.4661309179 -2428759.4355382994, -6254483.7939324081 -2428784.435538291, -6254488.1171720307 -2428797.4138724436, -6254494.0507978983 -2428787.6517201238, -6254496.0056557087 -2428784.4355382938, -6254511.2011414906 -2428759.4355382947, -6254519.0507979058 -2428746.521083768, -6254526.396627279 -2428734.4355383012, -6254519.0507979058 -2428734.4355382971, -6254526.39662728 -2428734.4355382989, -6254541.5921130609 -2428709.4355382994, -6254544.05079791 -2428705.3904474066, -6254556.7875988465 -2428684.4355383022, -6254569.0507979142 -2428664.2598110475, -6254571.98308463 -2428659.4355383059, -6254587.178570414 -2428634.4355383134, -6254594.0507979151 -2428623.1291746926, -6254602.3740561949 -2428609.4355383073, -6254617.5695419768 -2428584.43553831, -6254619.0507979207 -2428581.9985383344, -6254632.7650277568 -2428559.4355383161, -6254632.7650277615 -2428559.4355383161, -6254644.0507979263 -2428540.867901979, -6254647.9605135452 -2428534.4355383152, -6254663.1559993327 -2428509.4355383157, -6254669.0507979244 -2428499.7372656157, -6254678.3514851155 -2428484.4355383227, -6254693.5469708946 -2428459.4355383213, -6254694.0507979318 -2428458.6066292617, -6254694.0507979346 -2428434.4355383264, -6254708.7424566783 -2428434.435538318, -6254719.0507979384 -2428417.4759929045, -6254723.9379424639 -2428409.4355383255, -6254739.1334282458 -2428384.435538332, -6254744.0507979393 -2428376.3453565422, -6254753.3077126583 -2428361.11564482)), ((-6254708.7424566783 -2428434.4355383241, -6254694.0507979346 -2428434.4355383264, -6254694.0507979328 -2428458.6066292622, -6254708.7424566783 -2428434.4355383241)), ((-6254399.2597350832 -2428943.6043894938, -6254394.0507978816 -2428943.5478406339, -6254394.0507978844 -2428952.1742655579, -6254399.2597350832 -2428943.6043894938)), ((-6254369.05079788 -2428993.3049019151, -6254374.4417694416 -2428984.435538277, -6254369.0507978806 -2428984.435538278, -6254374.4417694416 -2428984.4355382761, -6254389.6372552253 -2428959.4355382812, -6254394.0507978816 -2428952.1742655588, -6254394.0507978816 -2428943.5478406339, -6254369.05079788 -2428943.2764375918, -6254344.0507978778 -2428943.0050345478, -6254319.05079788 -2428942.7336315047, -6254294.0507978769 -2428942.4622284621, -6254269.0507978741 -2428942.1908254218, -6254244.05079787 -2428941.9194223764, -6254219.0507978722 -2428941.648019332, -6254194.0507978741 -2428941.3766162931, -6254169.0507978676 -2428941.1052132491, -6254144.0507978639 -2428940.8338102074, -6254119.0507978648 -2428940.5624071644, -6254094.0507978611 -2428940.2910041185, -6254073.3327726927 -2428940.0660867151, -6254081.0446049273 -2428959.4355382626, -6254090.9982066322 -2428984.4355382607, -6254094.05079786 -2428992.1025901404, -6254100.951808339 -2429009.4355382593, -6254110.9054100439 -2429034.4355382589, -6254119.0507978583 -2429054.8939312571, -6254120.859011746 -2429059.4355382561, -6254130.8126134519 -2429084.4355382607, -6254140.5877170712 -2429108.987212894, -6254144.0507978536 -2429107.718292403, -6254169.0507978592 -2429098.557948139, -6254194.05079786 -2429089.397603869, -6254207.59304438 -2429084.4355382607, -6254219.0507978648 -2429080.237259604, -6254244.0507978629 -2429071.0769153368, -6254269.0507978685 -2429061.9165710746, -6254275.8219211269 -2429059.435538271, -6254294.05079787 -2429052.7562268032, -6254319.05079787 -2429043.5958825387, -6254344.0507978722 -2429034.4355382724, -6254359.246283656 -2429009.4355382756, -6254369.05079788 -2428993.3049019151)))");

            Assert.IsNotNull(g2);
            Assert.IsTrue(g2.IsValid);
            Assert.Throws <TopologyException>(() => g1.Difference(g2));
        }
Example #16
0
        /// <summary>
        ///
        /// </summary>
        public virtual void Run()
        {
            var wktRdr = new WKTReader();

            string wktA = "POLYGON((40 100, 40 20, 120 20, 120 100, 40 100))";
            string wktB = "LINESTRING(20 80, 80 60, 100 140)";
            var    A    = wktRdr.Read(wktA);
            var    B    = wktRdr.Read(wktB);
            var    C    = A.Intersection(B);

            Console.WriteLine("A = " + A);
            Console.WriteLine("B = " + B);
            Console.WriteLine("A intersection B = " + C);
            Console.WriteLine("A relate C = " + A.Relate(B));
        }
        public void UnionPolygons()
        {
            var wktReader = new WKTReader(new GeometryFactory(new PrecisionModel(1000)));

            var polygon1 = wktReader.Read("POLYGON((0 0,1 1,1 -1,0 0))");
            var polygon2 = wktReader.Read("POLYGON((1 1,2 0,1 -1,1 1))");

            var union = polygon1.Union(polygon2);

            var wkt = new WKTWriter().Write(union);

            Trace.WriteLine(wkt);

            Assert.AreEqual("POLYGON((0 0,1 1,2 0,1 -1,0 0))", wkt, "polygons are merged");
        }
        public void TestGetGeometryN()
        {
            MultiPoint m = (MultiPoint)reader.Read("MULTIPOINT(1.111 2.222, 3.333 4.444, 3.333 4.444)");
            IGeometry  g = m.GetGeometryN(1);

            Assert.IsTrue(g is Point);
            Point      p = (Point)g;
            Coordinate externalCoordinate = new Coordinate();
            Coordinate internaCoordinate  = p.Coordinate;

            externalCoordinate.X = internaCoordinate.X;
            externalCoordinate.Y = internaCoordinate.Y;
            Assert.AreEqual(3.333, externalCoordinate.X, 1E-10);
            Assert.AreEqual(4.444, externalCoordinate.Y, 1E-10);
        }
        private void CheckIntersectionNone(string wkt1, string wkt2)
        {
            var l1 = (LineString)_reader.Read(wkt1);
            var l2 = (LineString)_reader.Read(wkt2);
            var pt = new[]
            {
                l1.GetCoordinateN(0), l1.GetCoordinateN(1),
                l2.GetCoordinateN(0), l2.GetCoordinateN(1)
            };

            CheckIntersection(pt, 0, null, 0);
        }
        private static bool TestWktWkb(int number, IGeometryFactory factory, string wkt, string wkb)
        {
            WKTReader r       = new WKTReader(factory);
            IGeometry wktGeom = r.Read(wkt);
            WKBReader s       = new WKBReader(factory);
            IGeometry wkbGeom = s.Read(WKBReader.HexToBytes(wkb));

            try
            {
                Assert.AreEqual(wkb, WKBWriter.ToHex(wktGeom.AsBinary()), "wkb's don't match");
                Assert.IsTrue(DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9, number + ": DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9");
                if (!wktGeom.EqualsExact(wkbGeom))
                {
                    Assert.AreEqual(wkt, wktGeom.AsText(), number + ": wkt.Equals(wktGeom.AsText())");
                    var wktGeom2 = s.Read(wktGeom.AsBinary());
                    Assert.AreEqual(wkt, wktGeom2.AsText(), number + ": wkt.Equals(wktGeom2.AsText())");
                    var diff = wkbGeom.Difference(wktGeom);
                    Assert.IsTrue(false, number + ": wktGeom.EqualsExact(wkbGeom)\n" + diff.AsText());
                }
                return(false);
            }
            catch (AssertionException ex)
            {
                Console.WriteLine(ex.Message);
                return(true);
            }
        }
Example #21
0
    private HitType MarkupHitTest(Markup markup, IGeometry g, double distance, double scale)
    {
        WKTReader wktReader = new WKTReader();
        IGeometry geometry  = wktReader.Read(markup.Shape);

        HitType hitType = HitType.None;

        if (geometry.OgcGeometryType != OgcGeometryType.Point || String.IsNullOrEmpty(markup.Text))
        {
            if ((g is IPoint && geometry.Distance(g) <= distance) || (!(g is IPoint) && geometry.Intersects(g)))
            {
                hitType = geometry.OgcGeometryType == OgcGeometryType.Point && markup.Measured.HasValue && markup.Measured == 1 ? HitType.Coordinate : HitType.Shape;
            }
        }
        else
        {
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(10, 10));

            Coordinate           origin   = ((IPoint)geometry).Coordinate;
            System.Drawing.SizeF textSize = graphics.MeasureString(markup.Text, AppContext.AppSettings.MarkupFont);

            Envelope box = new Envelope(new Coordinate(origin.X, origin.Y), new Coordinate(origin.X + textSize.Width * scale, origin.Y + textSize.Height * scale));

            if (box.ToPolygon().Intersects(g))
            {
                hitType = HitType.Text;
            }
        }

        return(hitType);
    }
Example #22
0
        private static byte[] ConvertWKTToWKB(string wkt)
        {
            var writer = new WKBWriter();
            var reader = new WKTReader();

            return(writer.Write(reader.Read(wkt)));
        }
Example #23
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject obj = JObject.Load(reader);

            //check if the value is empty
            if (obj.Count > 0)
            {
                var srid = obj["srid"].Value <int>();
                var wkt  = obj["wellKnownText"].Value <string>();

                try
                {
                    WKTReader wKTReader = new WKTReader();
                    wKTReader.DefaultSRID = srid;
                    wKTReader.RepairRings = true;

                    var geom = wKTReader.Read(wkt);

                    return(geom);
                }
                catch (Exception e)
                {
                    string stack = e.StackTrace;
                }

                return(null);
            }
            else
            {
                return(null);
            }
        }
Example #24
0
 /// <summary>
 /// geohash,Unnamed: 0,disttoP,Plat,Plon,rel_dist_std,rel_dist_max,rel_cog_std,rel_cog_max,rel_sog_std,rel_sog_max,g1lat,g1lon,
 /// g2lat,g2lon,significance,lat,lon,dist_std_left,dist_std_right,dist_max_left,dist_max_right,bbox,geometry
 /// </summary>
 public DeviationCellCsvClassMap()
 {
     Map(m => m.GeoHash).Name("geohash");
     //Map(m => m.NormalRouteId).ConvertUsing(row => row.GetField<string>("normal_route_id").Split("_")[0]);
     Map(m => m.DistToP).Name("disttoP");
     //Map(m => m.PPoint).ConvertUsing(row =>
     //{
     //	var p = new Point(
     //				new Coordinate(
     //					Double.Parse(row.GetField("Plon"), CultureInfo.InvariantCulture),
     //					Double.Parse(row.GetField("Plat"), CultureInfo.InvariantCulture)));
     //	p.SRID = 4326;
     //	return p;
     //});
     Map(m => m.RelDistStd).Name("rel_dist_std");
     Map(m => m.RelDistMax).Name("rel_dist_max");
     Map(m => m.RelCogStd).Name("rel_cog_std");
     Map(m => m.RelCogMax).Name("rel_cog_max");
     Map(m => m.RelSogStd).Name("rel_sog_std");
     Map(m => m.RelSogMax).Name("rel_sog_max");
     //Map(m => m.G1).ConvertUsing(row =>
     //{
     //	var p = new Point(
     //				new Coordinate(
     //					Double.Parse(row.GetField("g1lon"), CultureInfo.InvariantCulture),
     //					Double.Parse(row.GetField("g1lat"), CultureInfo.InvariantCulture)));
     //	p.SRID = 4326;
     //	return p;
     //});
     //Map(m => m.G2).ConvertUsing(row =>
     //{
     //	var p = new Point(
     //				new Coordinate(
     //					Double.Parse(row.GetField("g2lon"), CultureInfo.InvariantCulture),
     //					Double.Parse(row.GetField("g2lat"), CultureInfo.InvariantCulture)));
     //	p.SRID = 4326;
     //	return p;
     //});
     Map(m => m.DataCount).Name("datacount");
     //Map(m => m.Position).ConvertUsing(row =>
     //{
     //	var p = new Point(
     //				new Coordinate(
     //					Double.Parse(row.GetField("lon"), CultureInfo.InvariantCulture),
     //					Double.Parse(row.GetField("lat"), CultureInfo.InvariantCulture)));
     //	p.SRID = 4326;
     //	return p;
     //});
     Map(m => m.DistStdLeft).Name("dist_std_left");
     Map(m => m.DistStdRight).Name("dist_std_right");
     Map(m => m.DistMaxLeft).Name("dist_max_left");
     Map(m => m.DistMaxRight).Name("dist_max_right");
     Map(m => m.Geom).Convert(args =>
     {
         var wktReader = new WKTReader();
         var p         = wktReader.Read(args.Row.GetField("geometry"));
         p.SRID        = 4326;
         return(p);
     });
 }
Example #25
0
        public void FromXML(XmlReader reader)
        {
            if (reader.IsStartElement("Feature"))
            {
                reader.ReadStartElement("Feature");

                //Read the geometry
                if (reader.IsStartElement("Geometry"))
                {
                    reader.ReadStartElement("Geometry");
                    string    wkt       = reader.ReadString();
                    WKTReader wktReader = new WKTReader();
                    Shape = wktReader.Read(wkt);
                    reader.ReadEndElement();//Read [Geometry] end
                }

                //Read the attributes
                if (Attributes != null)
                {
                    Attributes.FromXML(reader);
                }
                else
                {
                    throw new NullReferenceException("Cannot read attribute values into feature. The [Attributes] property is NULL.");
                }

                reader.ReadEndElement();//Read [Feature] end
            }
        }
        private IGeometry GetSampleGeometry()
        {
            String wkt;

            // triangle
            //wkt ="POLYGON (( 233 221, 210 172,  262 181, 233 221  ))";

            //star polygon with hole
            wkt =
                "POLYGON ((260 400, 220 300, 80 300, 180 220, 40 200, 180 160, 60 20, 200 80, 280 20, 260 140, 440 20, 340 180, 520 160, 280 220, 460 340, 300 300, 260 400), (260 320, 240 260, 220 220, 160 180, 220 160, 200 100, 260 160, 300 140, 320 180, 260 200, 260 320))";

            //star polygon with NO hole
            // wkt ="POLYGON ((260 400, 220 300, 80 300, 180 220, 40 200, 180 160, 60 20, 200 80, 280 20, 260 140, 440 20, 340 180, 520 160, 280 220, 460 340, 300 300, 260 400))";

            //star polygon with NO hole, 10x size
            // wkt ="POLYGON ((2600 4000, 2200 3000, 800 3000, 1800 2200, 400 2000, 1800 1600, 600 200, 2000 800, 2800 200, 2600 1400, 4400 200, 3400 1800, 5200 1600, 2800 2200, 4600 3400, 3000 3000, 2600 4000))";

            IGeometry g = null;

            try
            {
                g = WktReader.Read(wkt);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                _testFailed = true;
            }
            return(g);
        }
Example #27
0
        public void TestPolygonEmpty()
        {
            var reader = new WKTReader();
            var geom   = reader.Read("POLYGON EMPTY");

            CheckWkbGeometry(geom.AsBinary(), "POLYGON EMPTY");
        }
Example #28
0
        /// <summary>
        /// Translates a geometry WKT string to a NetTopology geometry
        /// </summary>
        /// <param name="geomWKT">Geometry Well Known Text</param>
        /// <param name="srid">SRID of geomtery (defaults to 4326)</param>
        /// <returns>NetTopology IGeometry instance</returns>
        public static IGeometry ParseWKTAsGeometry(string geomWKT, int srid = WGS84_SRID)
        {
            IGeometry geometry = _wktReader.Read(geomWKT);

            geometry.SRID = srid;
            return(geometry);
        }
Example #29
0
        public static byte[] ConvertWkttoWkb(string wkt)
        {
            WKBWriter writer = new WKBWriter();
            WKTReader reader = new WKTReader();

            return(writer.Write(reader.Read(wkt)));
        }
Example #30
0
        private static void TestReaderInThreadedContext(object info)
        {
            object[] parameters = (object[])info;
            string[] wkts       = (string[])parameters[0];
            var      waitHandle = (AutoResetEvent)parameters[1];

            int[] srids = (int[])parameters[2];
            int   jobId = (int)parameters[3];

            for (int i = 0; i < 1000; i++)
            {
                string wkt    = wkts[Rnd.Next(0, wkts.Length)];
                var    reader = new WKTReader();
                var    geom   = reader.Read(wkt);
                Assert.NotNull(geom);
                foreach (int srid in srids)
                {
                    geom.SRID = srid;
                    Assert.AreEqual(geom.SRID, srid);
                    Assert.AreEqual(geom.Factory.SRID, srid);
                }
            }

            Console.WriteLine("ThreadId {0} finished Job {1}", Thread.CurrentThread.ManagedThreadId, jobId);
            waitHandle.Set();
        }