예제 #1
0
        public void Constructor4()
        {
            List <GeoJsonCoordinates> sample = new List <GeoJsonCoordinates> {
                new GeoJsonCoordinates(9.536067, 55.708116),
                new GeoJsonCoordinates(9.536000, 55.708068),
                new GeoJsonCoordinates(9.536169, 55.708062)
            };

            GeoJsonMultiPoint multiPoint = new GeoJsonMultiPoint(sample);

            Assert.AreEqual(3, multiPoint.Count);

            GeoJsonCoordinates p1 = multiPoint[0];
            GeoJsonCoordinates p2 = multiPoint[1];
            GeoJsonCoordinates p3 = multiPoint[2];

            Assert.AreEqual(9.536067, p1.X, "#1 X");
            Assert.AreEqual(55.708116, p1.Y, "#1 Y");
            Assert.AreEqual(0, p1.Altitude, "#1 Altitude");

            Assert.AreEqual(9.536000, p2.X, "#2 X");
            Assert.AreEqual(55.708068, p2.Y, "#2 Y");
            Assert.AreEqual(0, p2.Altitude, "#2 Altitude");

            Assert.AreEqual(9.536169, p3.X, "#3 X");
            Assert.AreEqual(55.708062, p3.Y, "#3 Y");
            Assert.AreEqual(0, p3.Altitude, "#3 Altitude");
        }
예제 #2
0
        public void Constructor2()
        {
            double[][] array =
            {
                new [] { 9.536067, 55.708116, 1.125 },
                new [] { 9.536000, 55.708068, 2.250 },
                new [] { 9.536169, 55.708062, 4.500 }
            };

            GeoJsonMultiPoint multiPoint = new GeoJsonMultiPoint(array);

            Assert.AreEqual(3, multiPoint.Count);

            GeoJsonCoordinates p1 = multiPoint[0];
            GeoJsonCoordinates p2 = multiPoint[1];
            GeoJsonCoordinates p3 = multiPoint[2];

            Assert.AreEqual(9.536067, p1.X, "#1 X");
            Assert.AreEqual(55.708116, p1.Y, "#1 Y");
            Assert.AreEqual(1.125, p1.Altitude, "#1 Altitude");

            Assert.AreEqual(9.536000, p2.X, "#2 X");
            Assert.AreEqual(55.708068, p2.Y, "#2 Y");
            Assert.AreEqual(2.250, p2.Altitude, "#2 Altitude");

            Assert.AreEqual(9.536169, p3.X, "#3 X");
            Assert.AreEqual(55.708062, p3.Y, "#3 Y");
            Assert.AreEqual(4.500, p3.Altitude, "#3 Altitude");
        }
        //Not supportig Z and M Values
        private static EsriMultiPoint ToEsriMultiPoint(GeoJsonMultiPoint geometry, bool isLongitudeFirst, int srid, Func <IPoint, IPoint> mapFunction)
        {
            if (geometry.IsNullOrEmpty())
            {
                return(new EsriMultiPoint());
            }

            // 1400.02.03
            // number of points equals to number of geometries in multipoint
            //List<EsriPoint> points = new List<EsriPoint>(geometry.Coordinates.Length);

            //foreach (var item in geometry.Coordinates)
            //{
            //    IPoint temporaryPoint = IRI.Msh.Common.Primitives.Point.Parse(item, isLongitudeFirst);

            //    if (mapFunction != null)
            //    {
            //        temporaryPoint = mapFunction(temporaryPoint);
            //    }

            //    points.Add(new EsriPoint(temporaryPoint.X, temporaryPoint.Y, srid));
            //}

            //return new EsriMultiPoint(points.ToArray());

            return(new EsriMultiPoint(GetPoints(geometry.Coordinates, isLongitudeFirst, srid, mapFunction).ToArray()));
        }
        private void TestRoundTrip <TCoordinates>(string expected, GeoJsonMultiPoint <TCoordinates> multiPoint) where TCoordinates : GeoJsonCoordinates
        {
            var json = multiPoint.ToJson();

            Assert.AreEqual(expected, json);

            var rehydrated = BsonSerializer.Deserialize <GeoJsonMultiPoint <TCoordinates> >(json);

            Assert.AreEqual(expected, rehydrated.ToJson());
        }
        /// <summary>
        /// Parses the specified <paramref name="json"/> object into an instance deriving from <see cref="GeoJsonObject"/>.
        ///
        /// As the GeoJSON format specified the type of a
        /// </summary>
        /// <param name="json">The JSON object.</param>
        /// <returns>An instance that derives from <see cref="GeoJsonObject"/>.</returns>
        private static GeoJsonObject Parse(JObject json)
        {
            if (json == null)
            {
                return(null);
            }

            // Get the value of the "type" property
            string type = json.GetString("type");

            if (string.IsNullOrWhiteSpace(type))
            {
                throw new GeoJsonParseException("The JSON object doesn't specify a type", json);
            }

            // Parse the type into an enum
            if (EnumUtils.TryParseEnum(type, out GeoJsonType result) == false)
            {
                throw new GeoJsonParseException($"Unknown type {type}", json);
            }

            switch (result)
            {
            case GeoJsonType.Feature:
                return(GeoJsonFeature.Parse(json));

            case GeoJsonType.FeatureCollection:
                return(GeoJsonFeatureCollection.Parse(json));

            case GeoJsonType.Point:
                return(GeoJsonPoint.Parse(json));

            case GeoJsonType.LineString:
                return(GeoJsonLineString.Parse(json));

            case GeoJsonType.Polygon:
                return(GeoJsonPolygon.Parse(json));

            case GeoJsonType.MultiPoint:
                return(GeoJsonMultiPoint.Parse(json));

            //case GeoJsonType.MultiLineString:
            //    return GeoJsonMultiLineString.Parse(obj);

            case GeoJsonType.MultiPolygon:
                return(GeoJsonMultiPolygon.Parse(json));

            case GeoJsonType.GeometryCollection:
                return(GeoJsonGeometryCollection.Parse(json));

            default:
                throw new GeoJsonParseException($"Unknown type {type}", json);
            }
        }
예제 #6
0
        public void ToJson1()
        {
            GeoJsonMultiPoint mp = new GeoJsonMultiPoint {
                new GeoJsonCoordinates(10, 40),
                new GeoJsonCoordinates(40, 30),
                new GeoJsonCoordinates(20, 20),
                new GeoJsonCoordinates(30, 10)
            };

            Assert.AreEqual(4, mp.Count);

            Assert.AreEqual("{\"type\":\"MultiPoint\",\"coordinates\":[[10.0,40.0],[40.0,30.0],[20.0,20.0],[30.0,10.0]]}", mp.ToJson(Formatting.None));
        }
예제 #7
0
        /// <inheritdoc />
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }
            if (reader.TokenType != JsonToken.StartObject)
            {
                return(null);
            }

            JObject obj = JObject.Load(reader);

            string type = obj.Value <string>("type");

            switch (type?.ToLower())
            {
            case "feature":
                return(GeoJsonFeature.Parse(obj));

            case "featurecollection":
                return(GeoJsonFeatureCollection.Parse(obj));

            case "point":
                return(GeoJsonPoint.Parse(obj));

            case "multipoint":
                return(GeoJsonMultiPoint.Parse(obj));

            case "linestring":
                return(GeoJsonLineString.Parse(obj));

            case "multilinestring":
                return(GeoJsonMultiLineString.Parse(obj));

            case "polygon":
                return(GeoJsonPolygon.Parse(obj));

            case "multipolygon":
                return(GeoJsonMultiPolygon.Parse(obj));

            default:
                if (objectType == typeof(GeoJsonProperties))
                {
                    return(ReadJsonProperties(reader));
                }
                throw new GeoJsonParseException($"Unknown shape: {type}", obj);
            }
        }
예제 #8
0
        private static void AddMultiPoint(SqlGeometryBuilder builder, GeoJsonMultiPoint geometry, bool isLongitudeFirst)
        {
            builder.BeginGeometry(OpenGisGeometryType.MultiPoint);

            foreach (var item in geometry.Coordinates)
            {
                builder.BeginGeometry(OpenGisGeometryType.Point);

                var temporaryPoint = IRI.Msh.Common.Primitives.Point.Parse(item, isLongitudeFirst);

                builder.BeginFigure(temporaryPoint.X, temporaryPoint.Y);

                builder.EndFigure();

                builder.EndGeometry();
            }

            builder.EndGeometry();
        }
예제 #9
0
        public void Deserialize1()
        {
            GeoJsonMultiPoint mp = JsonConvert.DeserializeObject <GeoJsonMultiPoint>("{\"type\":\"MultiPoint\",\"coordinates\":[[10.0,40.0],[40.0,30.0],[20.0,20.0],[30.0,10.0]]}");

            Assert.AreEqual(4, mp.Count);

            GeoJsonCoordinates p1 = mp[0];
            GeoJsonCoordinates p2 = mp[1];
            GeoJsonCoordinates p3 = mp[2];
            GeoJsonCoordinates p4 = mp[3];

            Assert.AreEqual(10, p1.X, "#1 X");
            Assert.AreEqual(40, p1.Y, "#1 Y");

            Assert.AreEqual(40, p2.X, "#2 X");
            Assert.AreEqual(30, p2.Y, "#2 Y");

            Assert.AreEqual(20, p3.X, "#3 X");
            Assert.AreEqual(20, p3.Y, "#3 Y");

            Assert.AreEqual(30, p4.X, "#4 X");
            Assert.AreEqual(10, p4.Y, "#4 Y");
        }
예제 #10
0
 private void SerializeDerivedMembers(BsonSerializationContext context, GeoJsonMultiPoint <TCoordinates> value)
 {
     SerializeCoordinates(context, value.Coordinates);
 }
예제 #11
0
 /// <summary>
 /// Serializes a value.
 /// </summary>
 /// <param name="context">The serialization context.</param>
 /// <param name="args">The serialization args.</param>
 /// <param name="value">The value.</param>
 protected override void SerializeValue(BsonSerializationContext context, BsonSerializationArgs args, GeoJsonMultiPoint <TCoordinates> value)
 {
     _helper.SerializeMembers(context, value, SerializeDerivedMembers);
 }
예제 #12
0
        public void Constructor1()
        {
            GeoJsonMultiPoint multiPoint = new GeoJsonMultiPoint();

            Assert.AreEqual(0, multiPoint.Count);
        }