Beispiel #1
0
        private void DoMinimumBoundingCircleTest(string wkt, string expectedWKT, Coordinate expectedCentre, double expectedRadius)
        {
            var      mbc          = new MinimumBoundingCircle(reader.Read(wkt));
            var      exPts        = mbc.GetExtremalPoints();
            Geometry actual       = geometryFactory.CreateMultiPointFromCoords(exPts);
            double   actualRadius = mbc.GetRadius();
            var      actualCentre = mbc.GetCentre();
            //Console.WriteLine("   Centre = " + actualCentre + "   Radius = " + actualRadius);

            var  expected = reader.Read(expectedWKT);
            bool isEqual  = actual.Equals(expected);

            // need this hack because apparently equals does not work for MULTIPOINT EMPTY
            if (actual.IsEmpty && expected.IsEmpty)
            {
                isEqual = true;
            }
            if (!isEqual)
            {
                Console.WriteLine("Actual = " + actual + ", Expected = " + expected);
            }
            Assert.IsTrue(isEqual);

            if (expectedCentre != null)
            {
                Assert.IsTrue(expectedCentre.Distance(actualCentre) < TOLERANCE);
            }
            if (expectedRadius >= 0)
            {
                Assert.IsTrue(Math.Abs(expectedRadius - actualRadius) < TOLERANCE);
            }
        }
        private MultiPoint CreateMultiPoint(int dim, int lrs, Decimal[] elemInfo, int elemIndex, List <Coordinate> coords)
        {
            int      sOffset        = StartingOffset(elemInfo, elemIndex);
            SdoEType etype          = EType(elemInfo, elemIndex);
            int      interpretation = Interpretation(elemInfo, elemIndex);

            if (!(sOffset >= 1) || !(sOffset <= coords.Count))
            {
                throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset +
                                            " inconsistent with ORDINATES length " + coords.Count);
            }
            if (etype != SdoEType.Coordinate)
            {
                throw new ArgumentException("ETYPE " + etype + " inconsistent with expected POINT");
            }
            if (!(interpretation > 1))
            {
                return(null);
            }

            int len = dim + lrs;

            int start = (sOffset - 1) / len;
            int end   = start + interpretation;

            var points = _factory.CreateMultiPointFromCoords(SubArray(coords, start, end));

            return(points);
        }
Beispiel #3
0
        private Geometry BoundaryMultiLineString(MultiLineString mLine)
        {
            if (_geom.IsEmpty)
            {
                return(GetEmptyMultiPoint());
            }

            var bdyPts = ComputeBoundaryCoordinates(mLine);

            // return Point or MultiPoint
            if (bdyPts.Length == 1)
            {
                return(_geomFact.CreatePoint(bdyPts[0]));
            }
            // this handles 0 points case as well
            return(_geomFact.CreateMultiPointFromCoords(bdyPts));
        }
        /// <summary>
        /// Creates a Point using the next token in the stream.
        /// </summary>
        /// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text
        /// format. The next tokens must form a &lt;Point Text&gt;.</param>
        /// <param name="factory">The factory to create the result geometry</param>
        /// <returns>Returns a Point specified by the next token in
        /// the stream.</returns>
        /// <remarks>
        /// ParseException is thrown if an unexpected token is encountered.
        /// </remarks>
        private static MultiPoint ReadMultiPointText(WktStreamTokenizer tokenizer, GeometryFactory factory)
        {
            string nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(factory.CreateMultiPointFromCoords((Coordinate[])null));
            }

            var points = new List <Coordinate>();

            points.Add(new Coordinate(GetNextNumber(tokenizer), GetNextNumber(tokenizer)));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                points.Add(new Coordinate(GetNextNumber(tokenizer), GetNextNumber(tokenizer)));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(factory.CreateMultiPointFromCoords(points.ToArray()));
        }
        /// <summary>
        /// Reads an array of <see cref="Geometry"/>s from JSON
        /// </summary>
        /// <param name="reader">The reader</param>
        /// <param name="objectType">The object type</param>
        /// <param name="existingValue">The existing value</param>
        /// <param name="serializer">The serializer</param>
        /// <returns>The geometry array read</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            //reader.Read();
            //if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "geometries"))
            //    throw new Exception();
            reader.Read();
            if (reader.TokenType != JsonToken.StartArray)
            {
                throw new Exception();
            }

            reader.Read();
            var geoms = new List <Geometry>();

            while (reader.TokenType != JsonToken.EndArray)
            {
                var obj          = (JObject)serializer.Deserialize(reader);
                var geometryType = (GeoJsonObjectType)Enum.Parse(typeof(GeoJsonObjectType), obj.Value <string>("type"), true);

                switch (geometryType)
                {
                case GeoJsonObjectType.Point:
                    geoms.Add(_factory.CreatePoint(ToCoordinate(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.LineString:
                    geoms.Add(_factory.CreateLineString(ToCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.Polygon:
                    geoms.Add(CreatePolygon(ToListOfCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.MultiPoint:
                    geoms.Add(_factory.CreateMultiPointFromCoords(ToCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.MultiLineString:
                    geoms.Add(CreateMultiLineString(ToListOfCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.MultiPolygon:
                    geoms.Add(CreateMultiPolygon(ToListOfListOfCoordinates(obj.Value <JArray>("coordinates"), reader.Culture)));
                    break;

                case GeoJsonObjectType.GeometryCollection:
                    throw new NotSupportedException();
                }

                reader.Read();
            }

            return(geoms);
        }
Beispiel #6
0
        private void Run(int nPts)
        {
            var      randPts = CreateRandomPoints(nPts);
            Geometry mp      = _geomFact.CreateMultiPointFromCoords(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 #7
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.CreateMultiPointFromCoords(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1), });

            Console.WriteLine(mpt);
        }
Beispiel #8
0
 /// <summary>
 /// Transforms a <see cref="NetTopologySuite.Geometries.MultiPoint"/>.
 /// </summary>
 /// <param name="points">MultiPoint to transform</param>
 /// <param name="transform">MathTransform</param>
 /// <param name="targetFactory">The factory to create the target geometry</param>
 /// <returns>Transformed MultiPoint</returns>
 public static MultiPoint TransformMultiPoint(MultiPoint points, MathTransform transform, GeometryFactory targetFactory)
 {
     return(targetFactory.CreateMultiPointFromCoords(TransformCoordinates(points.Coordinates, transform)));
 }