コード例 #1
0
        public void WhenArrayOfJsonObjectArraysPropertyInGeoJsonThenReadable()
        {
            const string geojsonString     = @"
{
  ""type"":""FeatureCollection"",
  ""features"":[
    {
      ""type"":""Feature"",
      ""geometry"":{
        ""type"":""Point"",
        ""coordinates"":[1.0,2.0]
      },
      ""properties"":{
        ""foo"":[
          {
            ""xyz"":[
                {""zee"":""xyz""},
                {""hay"":""zus""}
            ]
          }
        ]
      }
    }
  ]
}
";
            var          featureCollection = _reader.Read <FeatureCollection>(geojsonString);

            Assert.AreEqual(1, featureCollection.Count);
        }
コード例 #2
0
        private static FeatureCollection FeatureCollection(string geoJson)
        {
            var reader = new GeoJsonReader();

            var featureCollection = new FeatureCollection();

            try
            {
                featureCollection =
                    reader.Read <FeatureCollection>(geoJson);
                if (featureCollection.Count == 0)
                {
                    var feature =
                        reader.Read <Feature>(geoJson);
                    featureCollection.Add(feature);
                }
            }
            catch (Exception)
            {
                var feature =
                    reader.Read <Feature>(geoJson);
                featureCollection.Add(feature);
            }
            return(featureCollection);
        }
コード例 #3
0
ファイル: AssertGeo.cs プロジェクト: emij/OpenLR
        /// <summary>
        /// Compares two linestrings.
        /// </summary>
        /// <param name="geoJsonActual"></param>
        /// <param name="geoJson"></param>
        public static void AreEqual(string geoJsonActual, string geoJson, double delta)
        {
            var geoJsonReader = new GeoJsonReader();
            var actual        = geoJsonReader.Read <IGeometry>(geoJsonActual);
            var expected      = geoJsonReader.Read <IGeometry>(geoJson);

            AssertGeo.AreEqual(actual, expected, delta);
        }
コード例 #4
0
        public void valid_geojson_feature_collection_should_be_serialized()
        {
            const string json = @"
{
	""type"" : ""FeatureCollection"",
	""features"" : [{
			""type"" : ""Feature"",
			""properties"" : {},
			""geometry"" : {
				""type"" : ""Polygon"",
				""coordinates"" : [[[-2.537841796875, 53.50111704294316], [-2.537841796875, 54.226707764386695], [-1.0986328125, 54.226707764386695], [-1.0986328125, 53.50111704294316], [-2.537841796875, 53.50111704294316]]]
			}
		}, {
			""type"" : ""Feature"",
			""properties"" : {},
			""geometry"" : {
				""type"" : ""Polygon"",
				""coordinates"" : [[[-2.724609375, 52.34205163638784], [-2.724609375, 53.08082737207479], [-0.9667968749999999, 53.08082737207479], [-0.9667968749999999, 52.34205163638784], [-2.724609375, 52.34205163638784]]]
			}
		}
	]
}
";
            GeoJsonReader reader = new GeoJsonReader();            
            FeatureCollection coll = reader.Read<FeatureCollection>(json);
            Assert.That(coll, Is.Not.Null);
            Assert.That(coll.Count, Is.EqualTo(2));
        }
コード例 #5
0
        public static FeatureCollection LoadFeatureCollectionFromGeoJsonString(string geoJson)
        {
            var reader            = new GeoJsonReader();
            var featureCollection = reader.Read <FeatureCollection>(geoJson);

            return(featureCollection);
        }
コード例 #6
0
        public static string[] ConvertGeoJsonLineStringsToWgs84(string[] geoJsonLineStrings)
        {
            if (geoJsonLineStrings == null)
            {
                return(null);
            }

            var geoJsonReader = new GeoJsonReader();
            var geoJsonWriter = new GeoJsonWriter();

            List <string> result = new();

            foreach (var inputGeoJson in geoJsonLineStrings)
            {
                var line = geoJsonReader.Read <LineString>("{ \"type\": \"LineString\",\"coordinates\":" + inputGeoJson + " }");

                foreach (var coord in line.Coordinates)
                {
                    var conversionResult = UTM32WGS84Converter.ConvertFromUTM32NToWGS84(coord.X, coord.Y);
                    coord.X = conversionResult[0];
                    coord.Y = conversionResult[1];
                }

                var newGeoJson = geoJsonWriter.Write(line);

                newGeoJson = newGeoJson.Replace("{\"type\":\"LineString\",\"coordinates\":", "");
                newGeoJson = newGeoJson.Replace("}", "");

                result.Add(newGeoJson);
            }

            return(result.ToArray());
        }
コード例 #7
0
        public void geojson_should_serialize_nested_objects()
        {
            const string      json   = @"
{
  ""type"": ""FeatureCollection"",
  ""features"": [
    {
      ""type"": ""Feature"",
      ""geometry"": {
        ""type"": ""Point"",
        ""coordinates"": [
          1.0,
          2.0
        ]
      },
      ""properties"": {
        ""foo"": {
          ""bar"": ""xyz""
        }
      }
    }
  ]
}
";
            GeoJsonReader     reader = new GeoJsonReader();
            FeatureCollection coll   = reader.Read <FeatureCollection>(json);

            Assert.IsNotNull(coll);

            GeoJsonWriter writer = new GeoJsonWriter();
            string        s      = writer.Write(coll);

            Assert.IsNotNull(s);
        }
コード例 #8
0
        public void geojson_feature_with_fid_should_be_serialized()
        {
            const string json   = @"
{
	""type"" : ""FeatureCollection"",
	""totalFeatures"" : 5,
	""features"" : [{
			""type"" : ""Feature"",
			""id"" : ""vfs_kommun.256"",
			""geometry"" : null,
			""properties"" : {
				""kommunnamn"" : ""Karlskrona""
			}
		}
	]
}
";
            var          reader = new GeoJsonReader();
            var          coll   = reader.Read <FeatureCollection>(json);

            Assert.That(coll, Is.Not.Null);
            Assert.That(coll.Count, Is.EqualTo(1));

            var feature = coll[0];

            Assert.That(feature.Geometry, Is.Null);
            Assert.That(feature.Attributes, Is.Not.Null);
            Assert.That(feature.Attributes.TryGetId(out object id));
            Assert.That(id, Is.EqualTo("vfs_kommun.256"));
        }
コード例 #9
0
        public void geojson_should_deserialize_a_feature_with_geometrycollection()
        {
            const string  json     = @"
{
    ""type"": ""Feature"",
    ""geometry"": {
        ""type"": ""GeometryCollection"",
        ""geometries"": [ 
            {
                ""type"":""Polygon"",
                ""coordinates"":[[[1.0,1.0],[1.0,2.0],[2.0,2.0],[1.0,1.0]]]
            },
            {
                ""type"":""Point"",
                ""coordinates"":[100.0,100.0]
            },
            {
                ""type"":""Polygon"",
                ""coordinates"":[[[201.0,201.0],[201.0,202.0],[202.0,202.0],[201.0,201.0]]]
            }
        ]
    },
    ""properties"": {
    }
}
";
            GeoJsonReader reader   = new GeoJsonReader();
            Feature       geometry = reader.Read <Feature>(json);

            Assert.IsNotNull(geometry);
        }
コード例 #10
0
        public void If_json_is_invalid_ending_then_should_throw_exception()
        {
            const string geojson = "{\"type\": \"Point\",\"coordinates\": [10, 20]";

            Should.Throw <ArgumentException>(() => GeoJsonReader.Read(geojson))
            .Message.ShouldBe("Invalid json object!");
        }
コード例 #11
0
        public void If_json_is_valid_multipolygon_with_hole_then_should_return_correct_multipolygon()
        {
            const string geojson   = @"{
                ""type"": ""MultiPolygon"", 
                ""coordinates"": [
                    [
                        [[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]]
                    ]
                ]
            }";
            var          expectGeo = new MultiPolygon(new List <Polygon>
            {
                new Polygon(new List <Point> {
                    new Point(40, 40), new Point(20, 45), new Point(45, 30), new Point(40, 40)
                }),
                new Polygon(new List <LineString>
                {
                    new LineString(new List <Point> {
                        new Point(20, 35), new Point(10, 30), new Point(10, 10), new Point(30, 5), new Point(45, 20), new Point(20, 35)
                    }),
                    new LineString(new List <Point> {
                        new Point(30, 20), new Point(20, 15), new Point(20, 25), new Point(30, 20)
                    })
                })
            });

            var resultGeo = GeoJsonReader.Read(geojson);

            resultGeo.ShouldBe(expectGeo);
        }
コード例 #12
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            GeoJsonReader geoReadert = new GeoJsonReader();
            JObject       obj        = JObject.Load(reader);
            AO_JSON_site  ao         = new AO_JSON_site();

            ao.Cells                  = new AO_JSON_Cells();
            ao.Cells.ADRES            = (string)obj["Cells"]["ADRES"];
            ao.Cells.DDOC             = (string)obj["Cells"]["DDOC"];
            ao.Cells.DMT              = (string)obj["Cells"]["DMT"];
            ao.Cells.DREG             = (string)obj["Cells"]["DREG"];
            ao.Cells.global_id        = (int)obj["global_id"];
            ao.Cells.KAD_KV           = (int)obj["Cells"]["KAD_KV"];
            ao.Cells.KAD_RN           = (int)obj["Cells"]["KAD_RN"];
            ao.Cells.KAD_ZU           = (int)obj["Cells"]["KAD_ZU"];
            ao.Cells.KRT              = (string)obj["Cells"]["KRT"];
            ao.Cells.NDOC             = (string)obj["Cells"]["NDOC"];
            ao.Cells.NREG             = (int)obj["Cells"]["NREG"];
            ao.Cells.SOOR             = (string)obj["Cells"]["SOOR"];
            ao.Cells.STRT             = (string)obj["Cells"]["STRT"];
            ao.Cells.system_object_id = (String)obj["Cells"]["system_object_id"];
            ao.Cells.TDOC             = (string)obj["Cells"]["TDOC"];
            ao.Cells.UNOM             = (int)obj["Cells"]["UNOM"];
            ao.Cells.VLD              = (string)obj["Cells"]["VLD"];
            ao.Cells.VYVAD            = (string)obj["Cells"]["VYVAD"];
            if (obj["Cells"]["geoData"] == null)
            {
                ao.Cells.geoData = null;
            }
            else
            {
                ao.Cells.geoData = geoReadert.Read <NetTopologySuite.Geometries.Geometry>(obj["Cells"]["geoData"].ToString());
            }
            return(ao);
        }
コード例 #13
0
 public static byte[] FromGeoJson(string geojson)
 {
     var reader = new GeoJsonReader();
     var fc = reader.Read<FeatureCollection>(geojson);
     var bytes = FeatureCollectionConversions.ToFlatGeobuf(fc);
     return bytes;
 }
コード例 #14
0
        public static FeatureCollection GetFeatureCollection(string geojson)
        {
            var reader   = new GeoJsonReader();
            var features = reader.Read <FeatureCollection>(geojson);

            return(features);
        }
コード例 #15
0
        public void valid_geojson_feature_collection_should_be_serialized()
        {
            const string      json   = @"
{
	""type"" : ""FeatureCollection"",
	""features"" : [{
			""type"" : ""Feature"",
			""properties"" : {},
			""geometry"" : {
				""type"" : ""Polygon"",
				""coordinates"" : [[[-2.537841796875, 53.50111704294316], [-2.537841796875, 54.226707764386695], [-1.0986328125, 54.226707764386695], [-1.0986328125, 53.50111704294316], [-2.537841796875, 53.50111704294316]]]
			}
		}, {
			""type"" : ""Feature"",
			""properties"" : {},
			""geometry"" : {
				""type"" : ""Polygon"",
				""coordinates"" : [[[-2.724609375, 52.34205163638784], [-2.724609375, 53.08082737207479], [-0.9667968749999999, 53.08082737207479], [-0.9667968749999999, 52.34205163638784], [-2.724609375, 52.34205163638784]]]
			}
		}
	]
}
";
            GeoJsonReader     reader = new GeoJsonReader();
            FeatureCollection coll   = reader.Read <FeatureCollection>(json);

            Assert.That(coll, Is.Not.Null);
            Assert.That(coll.Count, Is.EqualTo(2));
        }
コード例 #16
0
        public void geojson_feature_with_fid_should_be_serialized()
        {
            const string json = @"
{
	""type"" : ""FeatureCollection"",
	""totalFeatures"" : 5,
	""features"" : [{
			""type"" : ""Feature"",
			""id"" : ""vfs_kommun.256"",
			""geometry"" : null,
			""properties"" : {
				""kommunnamn"" : ""Karlskrona""
			}
		}
	]
}
";
            GeoJsonReader reader = new GeoJsonReader();
            FeatureCollection coll = reader.Read<FeatureCollection>(json);
            Assert.That(coll, Is.Not.Null);
            Assert.That(coll.Count, Is.EqualTo(1));

            IFeature feature = coll[0];
            Assert.That(feature.Geometry, Is.Null);
            Assert.That(feature.Attributes, Is.Not.Null);
            Assert.That(feature.Attributes.Exists("id"), Is.True);
            Assert.That(feature.Attributes["id"], Is.EqualTo("vfs_kommun.256"));
        }
コード例 #17
0
        public void geojson_feature_with_both_id_and_null_crs_should_be_serialized()
        {
            const string      json   = @"
{
	""type"" : ""FeatureCollection"",
	""totalFeatures"" : 5,
	""features"" : [{
			""type"" : ""Feature"",
			""id"" : ""vfs_kommun.256"",
			""geometry"" : null,
			""properties"" : {
				""kommunnamn"" : ""Karlskrona""
			}
		}
	],
	""crs"" : null
}
";
            GeoJsonReader     reader = new GeoJsonReader();
            FeatureCollection coll   = reader.Read <FeatureCollection>(json);

            Assert.That(coll, Is.Not.Null);
            Assert.That(coll.CRS, Is.Null);
            Assert.That(coll.Count, Is.EqualTo(1));

            IFeature feature = coll[0];

            Assert.That(feature.Geometry, Is.Null);
            Assert.That(feature.Attributes, Is.Not.Null);
            Assert.That(feature.Attributes.Exists("id"), Is.True);
            Assert.That(feature.Attributes["id"], Is.EqualTo("vfs_kommun.256"));
        }
コード例 #18
0
        protected override IEnumerable <GeoArea> Load(string textData)
        {
            var reader   = new GeoJsonReader();
            var features = reader.Read <FeatureCollection>(textData);
            var result   = new List <GeoArea>();

            ProcessFeatures(features, result);

            var min = Geo.Project(new GeoPoint()
            {
                Lat = features.BoundingBox.MinY, Lng = features.BoundingBox.MinX
            });
            var max = Geo.Project(new GeoPoint()
            {
                Lat = features.BoundingBox.MaxY, Lng = features.BoundingBox.MaxX
            });

            ViewBox = new Rect2D
            {
                X      = min.X,
                Y      = max.Y,
                Width  = (max.X - min.X),
                Height = (min.Y - max.Y)
            };

            return(result);
        }
コード例 #19
0
        public void GeoJsonReaderReadContentTest()
        {
            //test 1st input file
            GeoJsonReader reader = new GeoJsonReader(_inputFilePaths[0]);

            IGeometry result = reader.Read();

            Assert.IsInstanceOf(typeof(IGeometryCollection <IGeometry>), result);

            IGeometryCollection <IGeometry> collection = result as IGeometryCollection <IGeometry>;

            Assert.IsTrue(collection[0] is IPoint);
            Assert.IsTrue((collection[0] as IPoint).Coordinate == new Coordinate(1, 1, 9));

            Assert.IsTrue(collection[1] is IMultiLineString);
            Assert.AreEqual((collection[1] as IMultiLineString).Count, 2);
            ILineString lstr = (collection[1] as IMultiLineString)[1];

            Assert.AreEqual(5, lstr.Coordinates.Count);
            Assert.AreEqual(lstr.Coordinates[0], new Coordinate(401, 28));
            Assert.AreEqual(lstr.Coordinates[1], new Coordinate(36, 12));
            Assert.AreEqual(lstr.Coordinates[2], new Coordinate(100, 37));
            Assert.AreEqual(lstr.Coordinates[3], new Coordinate(49, 46));
            Assert.AreEqual(lstr.Coordinates[4], new Coordinate(28, 34));

            Assert.IsTrue(collection[2] is IMultiPolygon);
            Assert.AreEqual(2, (collection[2] as IMultiPolygon).Count);

            Assert.IsTrue(reader.EndOfStream);
            Assert.AreEqual(0, reader.ReadToEnd().Count);

            reader.Close();
        }
コード例 #20
0
        public void Feature()
        {
            var reader = new GeoJsonReader();

            Assert.AreEqual(@"{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[0,0]},""properties"":null,""id"":""test-id""}",
                            new Feature(new Point(0, 0))
            {
                Id = "test-id"
            }.ToGeoJson()
                            );

            Assert.AreEqual(@"{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[0,0]},""properties"":null,""id"":""test-id""}",
                            new Feature(new Point(0, 0), new Dictionary <string, object>())
            {
                Id = "test-id"
            }.ToGeoJson()
                            );

            var feature = new Feature(new Point(0, 0), new Dictionary <string, object>()
            {
                { "name", "test" }
            })
            {
                Id = "test-id"
            };

            Assert.AreEqual(@"{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[0,0]},""properties"":{""name"":""test""},""id"":""test-id""}",
                            feature.ToGeoJson()
                            );

            var feature2 = (Feature)reader.Read(feature.ToGeoJson());

            Assert.AreEqual(feature.Id, feature2.Id);
            Assert.AreEqual(feature.Geometry, feature2.Geometry);
        }
コード例 #21
0
        public void geojson_should_deserialize_a_feature_with_geometrycollection()
        {
            const string json = @"
{
    ""type"": ""Feature"",
    ""geometry"": {
        ""type"": ""GeometryCollection"",
        ""geometries"": [ 
            {
                ""type"":""Polygon"",
                ""coordinates"":[[[1.0,1.0],[1.0,2.0],[2.0,2.0],[1.0,1.0]]]
            },
            {
                ""type"":""Point"",
                ""coordinates"":[100.0,100.0]
            },
            {
                ""type"":""Polygon"",
                ""coordinates"":[[[201.0,201.0],[201.0,202.0],[202.0,202.0],[201.0,201.0]]]
            }
        ]
    },
    ""properties"": {
    }
}
";
            GeoJsonReader reader = new GeoJsonReader();
            Feature geometry = reader.Read<Feature>(json);
            Assert.IsNotNull(geometry);
        }
コード例 #22
0
        public void If_json_is_valid_multipolygon_then_should_return_correct_multipolygon()
        {
            const string geojson   = @"{
                ""type"": ""MultiPolygon"", 
                ""coordinates"": [
                    [
                        [[30, 20], [45, 40], [10, 40], [30, 20]]
                    ], 
                    [
                        [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]
                    ]
                ]
            }";
            var          expectGeo = new MultiPolygon(new List <Polygon>
            {
                new Polygon(new List <Point> {
                    new Point(30, 20), new Point(45, 40), new Point(10, 40), new Point(30, 20)
                }),
                new Polygon(new List <Point> {
                    new Point(15, 5), new Point(40, 10), new Point(10, 20), new Point(5, 10), new Point(15, 5)
                })
            });

            var resultGeo = GeoJsonReader.Read(geojson);

            resultGeo.Equals(expectGeo).Should().BeTrue();
        }
コード例 #23
0
        private Dictionary <long, (IFeature feature, long parent)> LoadBoundaries()
        {
            var boundaries = new Dictionary <long, (IFeature feature, long parent)>();

            // read all boundaries from geojson.
            var geoJsonReader = new GeoJsonReader();

            foreach (var file in Directory.EnumerateFiles(_configuration.DataPath, "*.geojson"))
            {
                var features = geoJsonReader.Read <FeatureCollection>(
                    File.ReadAllText(file));

                foreach (var feature in features)
                {
                    if (feature.Attributes == null)
                    {
                        continue;
                    }
                    if (!feature.Attributes.Exists("id"))
                    {
                        continue;
                    }

                    var idValue = feature.Attributes["id"];
                    if (!(idValue is long))
                    {
                        continue;
                    }
                    var id = (long)idValue;

                    var parentId = -1L;
                    if (feature.Attributes.Exists("parents"))
                    {
                        var parents = feature.Attributes["parents"];
                        if (parents is string parentString &&
                            !string.IsNullOrWhiteSpace(parentString))
                        {
                            var parentSplit = parentString.Split(',');
                            if (parentSplit.Length > 0)
                            {
                                foreach (var parentIdString in parentSplit)
                                {
                                    if (!long.TryParse(parentIdString, NumberStyles.Any,
                                                       System.Globalization.CultureInfo.InvariantCulture, out parentId))
                                    {
                                        parentId = -1;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    boundaries[id] = (feature, parentId);
                }
            }

            return(boundaries);
        }
コード例 #24
0
        private FeatureCollection GetFeaturesFromCollection(Dataset dataset)
        {
            string json       = System.IO.File.ReadAllText(dataset.Provider.Data);
            var    reader     = new GeoJsonReader();
            var    collection = reader.Read <FeatureCollection>(json);

            return(collection);
        }
コード例 #25
0
ファイル: MappingProfile.cs プロジェクト: Jawohi/src
        public Geometry Convert(string sourceMember, ResolutionContext context)
        {
            var      reader  = new GeoJsonReader();
            var      feature = reader.Read <Feature>(sourceMember);
            Geometry geo     = feature.Geometry.Normalized().Reverse();

            return(geo);
        }
コード例 #26
0
        public void howto_deserialize_geometries()
        {
            GeoJsonReader reader = new GeoJsonReader();
            IGeometry     actual = reader.Read <GeometryCollection>(serializedCollection);

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.EqualsExact(collection), Is.True);
        }
コード例 #27
0
        public void Point()
        {
            var reader = new GeoJsonReader();
            var geo    = new Point(0, 0);

            Assert.AreEqual(@"{""type"":""Point"",""coordinates"":[0,0]}", geo.ToGeoJson());
            Assert.AreEqual(geo, reader.Read(geo.ToGeoJson()));
        }
コード例 #28
0
        public void GeoJsonReaderHandleUnsupportedCrsTest()
        {
            GeoJsonReader reader = new GeoJsonReader(_invalidInputJsonFilePath);

            Assert.Throws <InvalidDataException>(() => reader.Read());

            reader.Close();
        }
コード例 #29
0
 private void ConvertGeoJSONToGeometry_Click(object sender, RoutedEventArgs e)
 {
     //引用NetTopologySuite.IO.GeoJSON
     //https://github.com/NetTopologySuite/NetTopologySuite.IO.GeoJSON
     String        geoJSONText = GetTxtFromFile();
     GeoJsonReader reader      = new GeoJsonReader();
     var           geometry    = reader.Read <NetTopologySuite.Geometries.Geometry>(geoJSONText);
 }
コード例 #30
0
        /// <summary>
        /// The get all device location.
        /// </summary>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <FeatureCollection> GetAllDeviceLocation()
        {
            var reader = new GeoJsonReader();

            if (!Barrel.Current.IsExpired(nameof(GetAllDeviceLocation)))
            {
                var cachedData = Barrel.Current.Get <string>(nameof(GetAllDeviceLocation));
                var resultData = reader.Read <FeatureCollection>(cachedData);
                return(resultData);
            }
            var data = await Constant.DeviceGeoJsonApi.GetStringAsync();

            var result = reader.Read <FeatureCollection>(data);

            Barrel.Current.Add(nameof(GetAllDeviceLocation), data, TimeSpan.FromDays(1));
            return(result);
        }
コード例 #31
0
        public static byte[] Serialize(string geojson)
        {
            var reader = new GeoJsonReader();
            var fc     = reader.Read <FeatureCollection>(geojson);
            var bytes  = FeatureCollectionConversions.Serialize(fc, GeometryType.Unknown);

            return(bytes);
        }
コード例 #32
0
ファイル: GeoJsonConversions.cs プロジェクト: pka/flatgeobuf
        public static async Task <byte[]> SerializeAsync(string geojson)
        {
            var reader = new GeoJsonReader();
            var fc     = reader.Read <FeatureCollection>(geojson);
            var bytes  = await FeatureCollectionConversions.SerializeAsync(fc, GeometryType.Unknown);

            return(bytes);
        }
コード例 #33
0
ファイル: GeometryConverter.cs プロジェクト: bertt/pointer
        public static IGeometry GetGeoApiGeometry(IGeometryObject geom)
        {
            var       geomtype   = geom.Type;
            var       geomstring = JsonConvert.SerializeObject(geom);
            var       reader     = new GeoJsonReader();
            IGeometry pandGeom;

            if (geomtype == GeoJSON.Net.GeoJSONObjectType.MultiPolygon)
            {
                pandGeom = reader.Read <NetTopologySuite.Geometries.MultiPolygon>(geomstring);
            }
            else
            {
                pandGeom = reader.Read <NetTopologySuite.Geometries.Polygon>(geomstring);
            }
            return(pandGeom);
        }
コード例 #34
0
        public void GeoJsonReaderReadFeatureCollectionTest()
        {
            const string json = "{\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":\"value1\"}}],\"type\":\"FeatureCollection\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"name1\"}}}";
            GeoJsonReader reader = new GeoJsonReader();
            FeatureCollection result = reader.Read<FeatureCollection>(json);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.IsNotNull(result.CRS);
            Assert.IsInstanceOf(typeof(NamedCRS), result.CRS);
            Assert.AreEqual(CRSTypes.Name, result.CRS.Type);
            NamedCRS crs = (NamedCRS)result.CRS;
            Assert.AreEqual("name1", crs.Properties["name"]);
        }
コード例 #35
0
        /// <summary>
        /// Creates the processor that belongs to this data.
        /// </summary>
        /// <returns></returns>
        public override ProcessorBase CreateProcessor()
        {
            // parse geojson file.
            using(var geoJSONFile = new FileInfo(this.GeoJSONFile).OpenText())
            {
                string geoJson = geoJSONFile.ReadToEnd();
                var geoJsonReader = new GeoJsonReader();

                var featureCollection = geoJsonReader.Read<FeatureCollection>(geoJson) as FeatureCollection;

                foreach (var feature in featureCollection.Features)
                {
                    return new ProcessorFeedFilter()
                    { // create a bounding box filter.
                        Filter = new GTFS.Filters.GTFSFeedStopsFilter((s) =>
                        {
                            return feature.Geometry.Covers(new Point(new Coordinate(s.Longitude, s.Latitude)));
                        })
                    };
                }
            }
            throw new Exception("No geometries found in GeoJSON");
        }
コード例 #36
0
        public void geojson_feature_with_null_crs_should_be_serialized()
        {
            const string json = @"
{
	""type"" : ""FeatureCollection"",
	""totalFeatures"" : 5,
	""features"" : [{
			""type"" : ""Feature"",
			""geometry"" : null,
			""properties"" : {
				""kommunnamn"" : ""Karlskrona""
			}
		}
	],
	""crs"" : null
}
";
            GeoJsonReader reader = new GeoJsonReader();
            FeatureCollection coll = reader.Read<FeatureCollection>(json);
            Assert.That(coll, Is.Not.Null);
            Assert.That(coll.CRS, Is.Null);
            Assert.That(coll.Count, Is.EqualTo(1));
        }
コード例 #37
0
        public void GeoJsonDeserializeFeatureCollectionTest()
        {
            const string json = @"
{
  ""type"": ""FeatureCollection"",
  ""features"": [
    {
      ""type"": ""Feature"",
      ""geometry"": {
        ""type"": ""Point"",
        ""coordinates"": [
          1.0,
          2.0
        ]
      },
      ""properties"": {
        ""foo"": {
          ""bar"": ""xyz""
        }
      }
    }
  ]
}
";
            GeoJsonReader reader = new GeoJsonReader();
            FeatureCollection coll = reader.Read<FeatureCollection>(json);
            Assert.IsNotNull(coll);
            Assert.AreEqual(1, coll.Count);
            IFeature feature = coll[0];

            Assert.IsNotNull(feature);
            Assert.AreEqual(1, feature.Attributes.Count);

            var gjs = new GeoJsonWriter();
            gjs.Write(coll);
        }
コード例 #38
0
 public async Task<List<Feature>> Search(string searchTerm, string fieldName)
 {
     if (string.IsNullOrWhiteSpace(searchTerm))
     {
         return new List<Feature>();
     }
     var field = "properties." + fieldName;
     var response = await _elasticClient.SearchAsync<object>(
         s => s.Size(NUMBER_OF_RESULTS)
             .TrackScores()
             .Sort(f => f.Descending("_score"))
             .Query(
                 q => q.FunctionScore(
                     fs => fs.Query(
                         iq => iq.DisMax(
                             dm => dm.Queries(
                                 dmq => dmq.MultiMatch(
                                     mm => mm.Query(searchTerm)
                                         .Fields(f => f.Fields(field, "properties.name*", "properties._name"))
                                         .Type(TextQueryType.BestFields)
                                         .Fuzziness(Fuzziness.Auto)
                                 ),
                                 dmq => dmq.Match(
                                     m => m.Query(searchTerm)
                                         .Boost(1.2)
                                         .Field(new Field { Name = field })
                                 )
                             )
                         )
                     ).Functions(fn => fn.FieldValueFactor(f => f.Field("properties.search_factor")))
                 )
             )
     );
     var reader = new GeoJsonReader();
     return response.Documents.Select(d => reader.Read<Feature>(d.ToString())).ToList();
 }
コード例 #39
0
 public async Task<List<Feature>> GetHighways(LatLng northEast, LatLng southWest)
 {
     var response = await _elasticClient.SearchAsync<object>(
         s => s.Index(OSM_HIGHWAYS_INDEX).Size(5000).Query(
             q => q.GeoShapeEnvelope(
                 e => e.Coordinates(new List<GeoCoordinate>
                     {
                         new GeoCoordinate(southWest.lat, northEast.lng),
                         new GeoCoordinate(northEast.lat, southWest.lng)
                     }).Field("geometry")
                     .Relation(GeoShapeRelation.Intersects)
             )
         )
     );
     var reader = new GeoJsonReader();
     return response.Documents.Select(d => reader.Read<Feature>(d.ToString())).ToList();
 }
コード例 #40
0
ファイル: GeoJsonHelper.cs プロジェクト: shaahink/GeoToolkit
        private static FeatureCollection FeatureCollection(string geoJson)
        {
            var reader = new GeoJsonReader();

            var featureCollection = new FeatureCollection();

            try
            {
                featureCollection =
                    reader.Read<FeatureCollection>(geoJson);
                if (featureCollection.Count == 0)
                {
                    var feature =
                        reader.Read<Feature>(geoJson);
                    featureCollection.Add(feature);
                }
            }
            catch (Exception)
            {
                var feature =
                    reader.Read<Feature>(geoJson);
                featureCollection.Add(feature);
            }
            return featureCollection;
        }
コード例 #41
0
 public void howto_deserialize_geometries()
 {
     GeoJsonReader reader = new GeoJsonReader();
     IGeometry actual = reader.Read<GeometryCollection>(serializedCollection);
     Assert.That(actual, Is.Not.Null);
     Assert.That(actual.EqualsExact(collection), Is.True);
 }
コード例 #42
0
        public void geojson_feature_without_additional_fields_should_be_serialized()
        {
            const string json = @"
{
	""type"" : ""FeatureCollection"",
	""totalFeatures"" : 1,
	""features"" : [{
			""type"" : ""Feature"",
			""id"" : ""Road.1249"",
			""geometry"" : {
				""type"" : ""MultiLineString"",
				""coordinates"" : [[[1610822.0864005657, 7249990.524654245], [1610819.2585326964, 7250021.630828278], [1611733.0938508697, 7250797.447679726]]]
			},
			""properties"" : {
				""road_id"" : 173922
			}
		}
	],
	""crs"" : {
		""type"" : ""name"",
		""properties"" : {
			""name"" : ""urn:ogc:def:crs:EPSG::2400""
		}
	}
}
";
            GeoJsonReader reader = new GeoJsonReader();
            FeatureCollection coll = reader.Read<FeatureCollection>(json);
            Assert.That(coll, Is.Not.Null);
            Assert.That(coll.CRS, Is.Not.Null);
            Assert.That(coll.Count, Is.EqualTo(1));

            IFeature feature = coll[0];
            Assert.That(feature.Geometry, Is.Not.Null);
            Assert.That(feature.Attributes, Is.Not.Null);
            Assert.That(feature.Attributes.Exists("id"), Is.True);
            Assert.That(feature.Attributes["id"], Is.EqualTo("Road.1249"));
            Assert.That(feature.Attributes.Exists("road_id"), Is.True);
            Assert.That(feature.Attributes["road_id"], Is.EqualTo(173922));
        }
コード例 #43
-1
        public void geojson_should_serialize_an_array_witn_a_single_item()
        {
            const string json = @"
{
  ""type"": ""FeatureCollection"",
  ""features"": [
    {
      ""type"": ""Feature"",
      ""geometry"": {
        ""type"": ""Point"",
        ""coordinates"": [
          1.0,
          2.0
        ]
      },
      ""properties"": {
        ""foo"": [
            {
              ""zee1"": ""xyz1""
            }
          ]
      }
    }
  ]
}
";
            GeoJsonReader reader = new GeoJsonReader();
            FeatureCollection coll = reader.Read<FeatureCollection>(json);
            Assert.IsNotNull(coll);

            GeoJsonWriter writer = new GeoJsonWriter();
            string s = writer.Write(coll);
            Assert.IsNotNull(s);
        }