Beispiel #1
0
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivant geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="totalRecordLength">Total length of the record we are about to read</param>
        /// <param name="factory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override Geometry Read(BigEndianBinaryReader file, int totalRecordLength, GeometryFactory factory)
        {
            int totalRead    = 0;
            int shapeTypeNum = ReadInt32(file, totalRecordLength, ref totalRead);

            var type = (ShapeGeometryType)EnumUtility.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString());

            if (type == ShapeGeometryType.NullShape)
            {
                return(factory.CreateMultiPoint());
            }

            if (type != ShapeType)
            {
                throw new ShapefileException(string.Format("Encountered a '{0}' instead of a  '{1}'", type, ShapeType));
            }

            // Read and for now ignore bounds.
            int bblength = GetBoundingBoxLength();

            boundingBox = new double[bblength];
            for (; boundingBoxIndex < 4; boundingBoxIndex++)
            {
                double d = ReadDouble(file, totalRecordLength, ref totalRead);
                boundingBox[boundingBoxIndex] = d;
            }

            // Read points
            int numPoints = ReadInt32(file, totalRecordLength, ref totalRead);
            var buffer    = new CoordinateBuffer(numPoints, NoDataBorderValue, true);
            var points    = new Point[numPoints];
            var pm        = factory.PrecisionModel;

            for (int i = 0; i < numPoints; i++)
            {
                double x = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
                double y = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
                buffer.AddCoordinate(x, y);
                buffer.AddMarker();
            }

            // Trond Benum: We have now read all the points, let's read optional Z and M values
            GetZMValues(file, totalRecordLength, ref totalRead, buffer);

            var sequences = buffer.ToSequences(factory.CoordinateSequenceFactory);

            for (int i = 0; i < numPoints; i++)
            {
                points[i] = factory.CreatePoint(sequences[i]);
            }

            geom = factory.CreateMultiPoint(points);

            return(geom);
        }
        public static IGeometry FromFlatbuf(Feature feature, GeometryType type, byte dimensions)
        {
            var coords          = feature.GetCoordsArray();
            var lengths         = feature.GetLengthsArray();
            var ringLengths     = feature.GetRingLengthsArray();
            var ringCounts      = feature.GetRingCountsArray();
            var sequenceFactory = new PackedCoordinateSequenceFactory();

            var factory = new GeometryFactory();

            switch (type)
            {
            case GeometryType.Point:
                return(factory.CreatePoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiPoint:
                return(factory.CreateMultiPoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.LineString:
                return(factory.CreateLineString(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiLineString:
                return(ParseFlatbufMultiLineString(lengths, coords, dimensions));

            case GeometryType.Polygon:
                return(ParseFlatbufPolygon(ringLengths, coords, dimensions));

            case GeometryType.MultiPolygon:
                return(ParseFlatbufMultiPolygon(lengths, ringLengths, ringCounts, coords, dimensions));

            default: throw new ApplicationException("FromFlatbuf: Unsupported geometry type");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Method to create a MultiPoint for testing purposes
        /// </summary>
        /// <returns>A MultiPoint</returns>
        private MultiPoint CreateTester2()
        {
            Point[] points = new Point[18];

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            points[0]  = gf.CreatePoint(new Coordinate(2, 2));
            points[1]  = gf.CreatePoint(new Coordinate(3, 3));
            points[2]  = gf.CreatePoint(new Coordinate(4, 4));
            points[3]  = gf.CreatePoint(new Coordinate(5, 5));
            points[4]  = gf.CreatePoint(new Coordinate(6, 6));
            points[5]  = gf.CreatePoint(new Coordinate(7, 7));
            points[6]  = gf.CreatePoint(new Coordinate(8, 8));
            points[7]  = gf.CreatePoint(new Coordinate(9, 7));
            points[8]  = gf.CreatePoint(new Coordinate(10, 6));
            points[9]  = gf.CreatePoint(new Coordinate(10, 5));
            points[10] = gf.CreatePoint(new Coordinate(9, 4));
            points[11] = gf.CreatePoint(new Coordinate(8, 3));
            points[12] = gf.CreatePoint(new Coordinate(7, 4));
            points[13] = gf.CreatePoint(new Coordinate(7, 5));
            points[14] = gf.CreatePoint(new Coordinate(6, 6));
            points[15] = gf.CreatePoint(new Coordinate(5, 7));
            points[16] = gf.CreatePoint(new Coordinate(4, 8));
            points[17] = gf.CreatePoint(new Coordinate(3, 9));

            MultiPoint mp = gf.CreateMultiPoint(points);

            return(mp);
        }
Beispiel #4
0
        private Feature ConvertRelation(CompleteRelation relation)
        {
            if (IsMultipolygon(relation))
            {
                return(ConvertToMultipolygon(relation));
            }

            var nodes = relation.Members.Select(m => m.Member).OfType <Node>().ToList();

            if (nodes.Any())
            {
                var multiPoint = _geometryFactory.CreateMultiPoint(nodes.Select(n => _geometryFactory.CreatePoint(ConvertNode(n))).ToArray());
                return(new Feature(multiPoint, ConvertTags(relation)));
            }

            var geometries = GetGeometriesFromWays(GetAllWays(relation));

            if (!geometries.Any())
            {
                return(null);
            }
            var jointLines = geometries.OfType <LineString>().ToList();

            jointLines.AddRange(geometries.OfType <Polygon>().Select(p => _geometryFactory.CreateLineString(p.ExteriorRing.Coordinates.ToArray()) as LineString));
            var multiLineString = _geometryFactory.CreateMultiLineString(jointLines.ToArray());

            return(new Feature(multiLineString, ConvertTags(relation)));
        }
Beispiel #5
0
        /// <summary>
        /// Method to create a MultiPoint for testing purposes
        /// </summary>
        /// <returns>A MultiPoint</returns>
        private MultiPoint CreateTester3()
        {
            Point[] points = new Point[21];

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            points[0]  = gf.CreatePoint(new Coordinate(10, 13));
            points[1]  = gf.CreatePoint(new Coordinate(11, 13));
            points[2]  = gf.CreatePoint(new Coordinate(12, 13));
            points[3]  = gf.CreatePoint(new Coordinate(13, 14));
            points[4]  = gf.CreatePoint(new Coordinate(14, 15));
            points[5]  = gf.CreatePoint(new Coordinate(15, 16));
            points[6]  = gf.CreatePoint(new Coordinate(15, 17));
            points[7]  = gf.CreatePoint(new Coordinate(15, 18));
            points[8]  = gf.CreatePoint(new Coordinate(14, 19));
            points[9]  = gf.CreatePoint(new Coordinate(13, 20));
            points[10] = gf.CreatePoint(new Coordinate(12, 21));
            points[11] = gf.CreatePoint(new Coordinate(11, 21));
            points[12] = gf.CreatePoint(new Coordinate(10, 21));
            points[13] = gf.CreatePoint(new Coordinate(9, 20));
            points[14] = gf.CreatePoint(new Coordinate(8, 19));
            points[15] = gf.CreatePoint(new Coordinate(7, 18));
            points[16] = gf.CreatePoint(new Coordinate(7, 17));
            points[17] = gf.CreatePoint(new Coordinate(7, 16));
            points[18] = gf.CreatePoint(new Coordinate(8, 15));
            points[19] = gf.CreatePoint(new Coordinate(9, 14));
            points[20] = gf.CreatePoint(new Coordinate(10, 13));

            MultiPoint mp = gf.CreateMultiPoint(points);

            return(mp);
        }
        public void TopoJsonWriterWrittenContentTest()
        {
            GeometryFactory factory = new GeometryFactory();
            IMultiPolygon   mp      = factory.CreateMultiPolygon
                                      (
                new List <IPolygon>
            {
                factory.CreatePolygon(factory.CreatePoint(10, 10),
                                      factory.CreatePoint(20, 10),
                                      factory.CreatePoint(25, 17),
                                      factory.CreatePoint(10, 10)),

                factory.CreatePolygon(factory.CreatePoint(50, 30),
                                      factory.CreatePoint(40, 20),
                                      factory.CreatePoint(20, 10),
                                      factory.CreatePoint(25, 17),
                                      factory.CreatePoint(30, 30),
                                      factory.CreatePoint(50, 30))
            }
                                      );

            Assert.AreEqual(2, mp.Count);

            IMultiPoint p = factory.CreateMultiPoint(
                new IPoint[2]
            {
                factory.CreatePoint(10, 10),
                factory.CreatePoint(23, 23)
            });

            ILineString lstr = factory.CreateLineString(
                factory.CreatePoint(50, 60),
                factory.CreatePoint(55, 60),
                factory.CreatePoint(71, 71)
                );

            List <IGeometry> geo = new List <IGeometry>()
            {
                p, lstr
            };

            string outFileName = _outputPath + ".topojson";

            TopoJsonWriter writer = new TopoJsonWriter(outFileName);

            writer.Write(mp as IGeometry);
            writer.Write(geo);
            writer.Close();

            TopoJsonReader    reader     = new TopoJsonReader(outFileName);
            IList <IGeometry> geometries = reader.ReadToEnd();

            reader.Close();

            GeometryComparer comp = new GeometryComparer();

            Assert.AreEqual(0, comp.Compare(geometries[0], mp));
            Assert.AreEqual(0, comp.Compare(geometries[1], p));
            Assert.AreEqual(0, comp.Compare(geometries[2], lstr));
        }
Beispiel #7
0
        /// <summary>
        /// Method to create a MultiPoint for testing purposes
        /// </summary>
        /// <returns>A MultiPoint</returns>
        private MultiPoint CreateTester1()
        {
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            Point[] points = new Point[23];

            for (int i = 0; i < 12; i++)
            {
                points[i] = gf.CreatePoint(new Coordinate(i, i));
            }
            points[12] = gf.CreatePoint(new Coordinate(11, 12));
            points[13] = gf.CreatePoint(new Coordinate(10, 13));
            points[14] = gf.CreatePoint(new Coordinate(9, 14));
            points[15] = gf.CreatePoint(new Coordinate(8, 15));
            points[16] = gf.CreatePoint(new Coordinate(9, 16));
            points[17] = gf.CreatePoint(new Coordinate(10, 17));
            points[18] = gf.CreatePoint(new Coordinate(11, 18));
            points[19] = gf.CreatePoint(new Coordinate(12, 19));
            points[20] = gf.CreatePoint(new Coordinate(11, 20));
            points[21] = gf.CreatePoint(new Coordinate(10, 21));
            points[22] = gf.CreatePoint(new Coordinate(9, 22));

            MultiPoint mp = gf.CreateMultiPoint(points);

            return(mp);
        }
        /// <summary>
        /// Reads a <see cref="MultiPoint"/> from the input stream.
        /// </summary>
        /// <param name="reader">The binary reader.</param>
        /// <param name="factory">The geometry factory to use for geometry creation.</param>
        /// <returns>The MultiPoint</returns>
        protected MultiPoint ReadMultiPoint(BinaryReader reader, GeometryFactory factory)
        {
            int numGeometries = reader.ReadInt32();
            var points        = new Point[numGeometries];

            ReadGeometryArray(reader, points);
            return(factory.CreateMultiPoint(points));
        }
Beispiel #9
0
        public override object?ParseLiteral(IValueNode literal)
        {
            if (literal is NullValueNode)
            {
                return(null);
            }

            if (!(literal is ObjectValueNode obj) || obj.Fields.Count < 2)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            (int typeIndex, int coordinateIndex, int crsIndex)indices =
                ParseLiteralHelper.GetFieldIndices(obj,
                                                   _typeFieldName,
                                                   _coordinatesFieldName,
                                                   _crsFieldName);

            if (indices.typeIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var type = (GeoJSONGeometryType)
                       _typeField.Type.ParseLiteral(obj.Fields[indices.typeIndex].Value);

            if (type != _geometryType || indices.coordinateIndex == -1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var coordinates = (IList <Coordinate>)
                              _coordinatesField.Type.ParseLiteral(obj.Fields[indices.coordinateIndex].Value);

            if (coordinates.Count < 1)
            {
                throw ThrowHelper.InvalidInputObjectStructure(_geometryType);
            }

            var pointCount = coordinates.Count;
            var points     = new Point[pointCount];

            for (var i = 0; i < pointCount; i++)
            {
                points[i] = new Point(coordinates[i]);
            }

            if (indices.crsIndex == -1)
            {
                return(new MultiPoint(points));
            }

            var             srid    = (int)_crsField.Type.ParseLiteral(obj.Fields[indices.crsIndex].Value);
            GeometryFactory factory = NtsGeometryServices.Instance.CreateGeometryFactory(srid);

            return(factory.CreateMultiPoint(points));
        }
Beispiel #10
0
 private static IGeometry SqlGeometryToGeometryMultiPoint(SqlGeometry geometry, GeometryFactory factory)
 {
     IPoint[] points = new IPoint[geometry.STNumGeometries().Value];
     for (int i = 1; i <= points.Length; i++)
     {
         points[i - 1] = SqlGeometryToGeometryPoint(geometry.STGeometryN(i), factory);
     }
     return(factory.CreateMultiPoint(points));
 }
            private static Geometry CreateMultiPoint(Ordinates ordinates, bool empty)
            {
                if (empty)
                {
                    return(Factory.CreateMultiPoint((CoordinateSequence)null));
                }
                int numPoints = Rnd.Next(75, 101);
                var seq       = CsFactory.Create(numPoints, ordinates);

                for (int i = 0; i < numPoints; i++)
                {
                    foreach (var o in ToOrdinateArray(ordinates))
                    {
                        seq.SetOrdinate(i, o, RandomOrdinate(o, Factory.PrecisionModel));
                    }
                }

                return(Factory.CreateMultiPoint(seq));
            }
        /// <summary>
        /// Function to read a <see cref="MultiPoint"/> from a ShapeFile stream using the specified <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader to use</param>
        /// <param name="ordinates">The ordinates to read</param>
        /// <returns>The read polygonal geometry</returns>
        public Geometry ReadMultiPoint(BinaryReader reader, Ordinates ordinates)
        {
            /*var bbox = */ ReadBoundingBox(reader); // jump boundingbox

            int numPoints = ReadNumPoints(reader);
            var buffer    = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true);

            ReadCoordinates(reader, numPoints, new[] { numPoints - 1 }, ordinates, buffer);
            return(_factory.CreateMultiPoint(buffer.ToSequence()));
        }
Beispiel #13
0
        public void TestWriteMultiPoint()
        {
            Point[] points =
            {
                _factory.CreatePoint(new CoordinateZ(10, 10, 0)),
                _factory.CreatePoint(new CoordinateZ(20, 20, 0))
            };
            var multiPoint = _factory.CreateMultiPoint(points);

            Assert.AreEqual("MULTIPOINT ((10 10), (20 20))", _writer.Write(multiPoint));
        }
Beispiel #14
0
        public void TestMultiPoint1()
        {
            Coordinates coordinates = new Coordinates();

            coordinates.Add(new Coordinate(1, 2));
            coordinates.Add(new Coordinate(1.2, 2.3));
            MultiPoint multipoint = _factory.CreateMultiPoint(coordinates);
            string     wkt        = _writer.WriteFormatted(multipoint);

            Assertion.AssertEquals("multi point", "MULTIPOINT (1 2, 1.2 2.3)", wkt);
        }
Beispiel #15
0
        public void CreateEmptyMultiPointSucceeds()
        {
            GeometryFactory factory = new GeometryFactory(
                new BufferedCoordinate2DFactory(),
                new BufferedCoordinate2DSequenceFactory());

            IMultiPoint p = factory.CreateMultiPoint();

            Assert.IsNotNull(p);
            Assert.IsTrue(p.IsEmpty);
        }
Beispiel #16
0
 private void SimplifyGeometriesCollection(List <Feature> results)
 {
     foreach (var feature in results)
     {
         if (!(feature.Geometry is GeometryCollection geometryCollection))
         {
             continue;
         }
         if (geometryCollection.Geometries.All(g => g is Point || g is MultiPoint))
         {
             var points = geometryCollection.Geometries
                          .OfType <MultiPoint>()
                          .SelectMany(mls => mls.Geometries.OfType <Point>())
                          .Concat(geometryCollection.Geometries.OfType <Point>())
                          .ToArray();
             feature.Geometry = _geometryFactory.CreateMultiPoint(points);
             continue;
         }
         var nonPointGeometries = geometryCollection.Geometries.Where(g => !(g is Point));
         if (nonPointGeometries.Count() == 1)
         {
             feature.Geometry = nonPointGeometries.First();
             continue;
         }
         if (nonPointGeometries.All(g => g is LineString || g is MultiLineString))
         {
             var lines = nonPointGeometries
                         .OfType <MultiLineString>()
                         .SelectMany(mls => mls.Geometries.OfType <LineString>())
                         .Concat(nonPointGeometries.OfType <LineString>())
                         .ToArray();
             feature.Geometry = _geometryFactory.CreateMultiLineString(lines);
             continue;
         }
         if (nonPointGeometries.All(g => g is Polygon || g is MultiPolygon))
         {
             var polygons = nonPointGeometries
                            .OfType <MultiPolygon>()
                            .SelectMany(mls => mls.Geometries.OfType <Polygon>())
                            .Concat(nonPointGeometries.OfType <Polygon>())
                            .ToArray();
             feature.Geometry = _geometryFactory.CreateMultiPolygon(polygons);
             if (!feature.Geometry.IsValid)
             {
                 feature.Attributes.AddOrUpdate(FeatureAttributes.POI_CONTAINER, false);
                 _reportLogger.LogWarning("There was a problem merging the following feature " + feature.GetTitle(Languages.HEBREW) + " (" + feature.GetId() + ") ");
             }
             continue;
         }
         _reportLogger.LogWarning("The following merge created a weird geometry: " + feature.GetTitle(Languages.HEBREW) + " (" + feature.GetId() + ") " + string.Join(", ", geometryCollection.Geometries.Select(g => g.GeometryType)));
         feature.Geometry = nonPointGeometries.FirstOrDefault();
     }
 }
        private void Run(int nPts)
        {
            var       randPts = CreateRandomPoints(nPts);
            IGeometry mp      = _geomFact.CreateMultiPoint(randPts);
            var       mbc     = new MinimumBoundingCircle(mp);
            var       centre  = mbc.GetCentre();
            double    radius  = mbc.GetRadius();

            Console.WriteLine("Testing " + nPts + " random points.  Radius = " + radius);

            checkWithinCircle(randPts, centre, radius, 0.0001);
        }
Beispiel #18
0
        public void ParseMultiPoint()
        {
            string      multipoint = "MULTIPOINT(20.564 346.3493254,45 32,23 54)";
            IMultiPoint geom       = GeometryFromWKT.Parse(multipoint) as IMultiPoint;

            Assert.IsNotNull(geom);
            Assert.AreEqual(20.564, (geom.Geometries[0] as IPoint).X);
            Assert.AreEqual(54, (geom.Geometries[2] as IPoint).Y);
            Assert.AreEqual(multipoint, geom.AsText());
            Assert.IsTrue(GeometryFromWKT.Parse("MULTIPOINT EMPTY").IsEmpty);
            Assert.AreEqual("MULTIPOINT EMPTY", GeometryFactory.CreateMultiPoint(null).AsText());
        }
        private MultiPoint ReadMultiPoint()
        {
            int nPoints = m_objReader.ReadInt32();

            Point[] points = new Point[nPoints];
            for (int i = 0; i < nPoints; i++)
            {
                BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();  // handle the byte order
                m_objReader.Order = byteOrder;

                int geomType = m_objReader.ReadInt32();
                if (geomType != 1)
                {
                    throw new GeometryIOException("The data is badly formed. "
                                                  + "A Point geometry is expected");
                }

                points[i] = ReadPoint();
            }

            return(m_objFactory.CreateMultiPoint(points));
        }
Beispiel #20
0
        internal static MultiPoint ToNTSMultiPoint(Geometries.MultiPoint multiPoint,
                                                   GeometryFactory factory)
        {
            GisSharpBlog.NetTopologySuite.Geometries.Point[] points =
                new GisSharpBlog.NetTopologySuite.Geometries.Point[multiPoint.Points.Count];
            int index = 0;

            foreach (Point point in multiPoint.Points)
            {
                points[index++] = ToNTSPoint(point, factory);
            }
            return(factory.CreateMultiPoint(points) as MultiPoint);
        }
Beispiel #21
0
        public void test_IsEmpty()
        {
            //create a new multipoint
            MultiPoint mp = CreateTester1();

            Assertion.AssertEquals("IsEmpty1: ", false, mp.IsEmpty());

            //Set multipoint to be empty to test the else
            GeometryFactory gf     = new GeometryFactory(_precMod, _sRID);
            Coordinates     coords = new Coordinates();
            MultiPoint      mp2    = gf.CreateMultiPoint(coords);

            Assertion.AssertEquals("IsEmpty2: ", true, mp2.IsEmpty());
        }
Beispiel #22
0
        private Geometry CreatePointResult(IReadOnlyCollection <Point> points)
        {
            if (points.Count == 0)
            {
                return(_geometryFactory.CreateEmpty(0));
            }
            if (points.Count == 1)
            {
                return(points.First());
            }

            var pointsArray = GeometryFactory.ToPointArray(points);

            return(_geometryFactory.CreateMultiPoint(pointsArray));
        }
Beispiel #23
0
        public void TestCreateEmpty()
        {
            CheckEmpty(Factory.CreateEmpty(Dimension.Point), typeof(Point));
            CheckEmpty(Factory.CreateEmpty(Dimension.Curve), typeof(LineString));
            CheckEmpty(Factory.CreateEmpty(Dimension.Surface), typeof(Polygon));

            CheckEmpty(Factory.CreatePoint(), typeof(Point));
            CheckEmpty(Factory.CreateLineString(), typeof(LineString));
            CheckEmpty(Factory.CreatePolygon(), typeof(Polygon));

            CheckEmpty(Factory.CreateMultiPoint(), typeof(MultiPoint));
            CheckEmpty(Factory.CreateMultiLineString(), typeof(MultiLineString));
            CheckEmpty(Factory.CreateMultiPolygon(), typeof(MultiPolygon));
            CheckEmpty(Factory.CreateGeometryCollection(), typeof(GeometryCollection));
        }
Beispiel #24
0
        /// <summary>
        /// Creates a new MultiPoint geometry from a MultiPoint shape.
        /// </summary>
        /// <param name="factory">The GeometryFactory to use to create the new shape.</param>
        /// <returns>The resulting multipoint.</returns>
        protected Geometry FromMultiPoint(GeometryFactory factory)
        {
            if (factory == null)
            {
                factory = Geometry.DefaultFactory;
            }
            var coords = new List <Coordinate>();

            foreach (var part in Range.Parts)
            {
                GetCoordinates(part, coords);
            }

            return(factory.CreateMultiPoint(coords.CastToPointArray()));
        }
Beispiel #25
0
        public void test_CompareToSameClass()
        {
            LineString ls  = SimpleOpen();
            LineString ls2 = SimpleOpen();
            LineString ls3 = SimpleClosed();

            Point[]         coords = new Point[] {};
            GeometryFactory gf     = new GeometryFactory(_precMod, _sRID);
            MultiPoint      mp     = gf.CreateMultiPoint(coords);

            Assertion.AssertEquals("CompareToSameClass-1: ", 0, ls.CompareToSameClass(ls2));
            Assertion.AssertEquals("CompareToSameClass-2: ", 1, ls.CompareToSameClass(ls3));
            Assertion.AssertEquals("CompareToSameClass-3: ", 1, ls.CompareToSameClass(mp));
            Assertion.AssertEquals("CompareToSameClass-4: ", -1, ls3.CompareToSameClass(ls));
            Assertion.AssertEquals("CompareToSameClass-5: ", -1, mp.CompareToSameClass(ls));
        }
Beispiel #26
0
        /// <summary>
        /// Transforms a <see cref="GisSharpBlog.NetTopologySuite.Geometries.MultiPoint"/>.
        /// </summary>
        /// <param name="points">MultiPoint to transform</param>
        /// <param name="transform">MathTransform</param>
        /// <returns>Transformed MultiPoint</returns>
        public static IMultiPoint TransformMultiPoint(IMultiPoint points, IMathTransform transform)
        {
            List <double[]> pointList = new List <double[]>(points.Geometries.Length);

            foreach (IPoint p in points.Geometries)
            {
                pointList.Add(ToLightStruct(p.X, p.Y));
            }
            pointList = transform.TransformList(pointList);
            IPoint[] array = new IPoint[pointList.Count];
            for (int i = 0; i < pointList.Count; i++)
            {
                array[i] = ToNTS(pointList[i][0], pointList[i][1]);
            }
            return(GeometryFactory.CreateMultiPoint(array));
        }
Beispiel #27
0
        public static void main(string[] args)
        {
            // create a factory using default values (e.g. floating precision)
            var fact = new GeometryFactory();

            var p1 = fact.CreatePoint(new Coordinate(0, 0));

            Console.WriteLine(p1);

            var p2 = fact.CreatePoint(new Coordinate(1, 1));

            Console.WriteLine(p1);

            var mpt = fact.CreateMultiPoint(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1), });

            Console.WriteLine(mpt);
        }
Beispiel #28
0
        public static IGeometry FromFlatbuf(Geometry geometry, GeometryType type)
        {
            byte dimensions = 2;
            var  factory    = new GeometryFactory();

            if (type == GeometryType.Unknown)
            {
                type = geometry.Type;
            }

            switch (type)
            {
            case GeometryType.MultiPolygon:
                int       partsLength = geometry.PartsLength;
                Polygon[] polygons    = new Polygon[partsLength];
                for (int i = 0; i < geometry.PartsLength; i++)
                {
                    polygons[i] = (Polygon)FromFlatbuf(geometry.Parts(i).Value, GeometryType.Polygon);
                }
                return(factory.CreateMultiPolygon(polygons));
            }

            var coords          = geometry.GetXyArray();
            var ends            = geometry.GetEndsArray();
            var sequenceFactory = new PackedCoordinateSequenceFactory();

            switch (type)
            {
            case GeometryType.Point:
                return(factory.CreatePoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiPoint:
                return(factory.CreateMultiPoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.LineString:
                return(factory.CreateLineString(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiLineString:
                return(ParseFlatbufMultiLineString(ends, coords, dimensions));

            case GeometryType.Polygon:
                return(ParseFlatbufPolygon(ends, coords, dimensions));

            default: throw new ApplicationException("FromFlatbuf: Unsupported geometry type");
            }
        }
Beispiel #29
0
        public void test_NumPoints()
        {
            //create a new multipoint
            MultiPoint mp = CreateTester1();

            Assertion.AssertEquals("NumPoints1: ", 23, mp.GetNumPoints());

            //Create a null coordinate to test with
            Coordinates testCoords = new Coordinates();

            //create a multipoint with a null coordinate to test else case
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            testCoords = new Coordinates();
            MultiPoint mp2 = gf.CreateMultiPoint(testCoords);

            Assertion.AssertEquals("NumPoints2: ", 0, mp2.GetNumPoints());
        }
Beispiel #30
0
        /// <summary>
        /// Method to create a MultiPoint for testing purposes
        /// </summary>
        /// <returns>A MultiPoint</returns>
        private MultiPoint CreateTester4()
        {
            Point[] points = new Point[32];

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            points[0]  = gf.CreatePoint(new Coordinate(2, 2));
            points[1]  = gf.CreatePoint(new Coordinate(3, 1));
            points[2]  = gf.CreatePoint(new Coordinate(4, 2));
            points[3]  = gf.CreatePoint(new Coordinate(5, 3));
            points[4]  = gf.CreatePoint(new Coordinate(6, 4));
            points[5]  = gf.CreatePoint(new Coordinate(7, 5));
            points[6]  = gf.CreatePoint(new Coordinate(7, 6));
            points[7]  = gf.CreatePoint(new Coordinate(7, 7));
            points[8]  = gf.CreatePoint(new Coordinate(7, 8));
            points[9]  = gf.CreatePoint(new Coordinate(7, 9));
            points[10] = gf.CreatePoint(new Coordinate(6, 10));
            points[11] = gf.CreatePoint(new Coordinate(5, 11));
            points[12] = gf.CreatePoint(new Coordinate(6, 12));
            points[13] = gf.CreatePoint(new Coordinate(7, 13));
            points[14] = gf.CreatePoint(new Coordinate(8, 14));
            points[15] = gf.CreatePoint(new Coordinate(9, 13));
            points[16] = gf.CreatePoint(new Coordinate(10, 12));
            points[17] = gf.CreatePoint(new Coordinate(10, 11));
            points[18] = gf.CreatePoint(new Coordinate(10, 10));
            points[19] = gf.CreatePoint(new Coordinate(10, 9));
            points[20] = gf.CreatePoint(new Coordinate(9, 8));
            points[21] = gf.CreatePoint(new Coordinate(8, 7));
            points[22] = gf.CreatePoint(new Coordinate(7, 7));
            points[23] = gf.CreatePoint(new Coordinate(6, 7));
            points[24] = gf.CreatePoint(new Coordinate(5, 8));
            points[25] = gf.CreatePoint(new Coordinate(4, 8));
            points[26] = gf.CreatePoint(new Coordinate(3, 7));
            points[27] = gf.CreatePoint(new Coordinate(2, 6));
            points[28] = gf.CreatePoint(new Coordinate(1, 5));
            points[29] = gf.CreatePoint(new Coordinate(2, 4));
            points[30] = gf.CreatePoint(new Coordinate(1, 3));
            points[31] = gf.CreatePoint(new Coordinate(2, 2));

            MultiPoint mp = gf.CreateMultiPoint(points);

            return(mp);
        }