Ejemplo n.º 1
0
        public void TestIssue83()
        {
            var geoJson = @"{ ""type"": ""Feature"", 
                              ""geometry"": { ""type"": ""Point"", ""coordinates"": [10.0, 60.0] }, 
                              ""id"": 1, 
                             ""properties"": { ""Name"": ""test"" } }";

            var     s = new GeoJsonSerializer();
            Feature f = null;

            Assert.DoesNotThrow(() =>
                                f = s.Deserialize <Feature>(new JsonTextReader(new StringReader(geoJson)))
                                );

            Assert.IsNotNull(f, "f != null");
            Assert.IsTrue(FeatureExtensions.HasID(f), "f.HasID()");
            Assert.AreEqual(1, FeatureExtensions.ID(f), "f.ID != 1");

            var sb = new StringBuilder();
            var tw = new JsonTextWriter(new StringWriter(sb));

            s.Serialize(tw, f);
            var geoJsonRes = sb.ToString();

            CompareJson(geoJson, geoJsonRes);
        }
        public void TestWhenFeatureCollectionHasBBox()
        {
            const string geoJsonString     = @"
{
  ""type"":""FeatureCollection"",
  ""features"":[ 
  { 
      ""geometry"":{ 
          ""type"":""Point"", 
          ""coordinates"":[ -6.09, 4.99 ]
      }, 
      ""type"":""Feature"", 
      ""properties"":{
          ""prop1"":[ ""a"", ""b"" ] 
      }, 
      ""id"":1 
  } ], 
  ""bbox"":[ -8.59, 4.35, -2.49, 10.73 ] 
}";
            var          featureCollection = new GeoJsonReader().Read <FeatureCollection>(geoJsonString);

            Assert.AreEqual(1, featureCollection.Count);
            Assert.That(FeatureExtensions.HasID(featureCollection[0]));
            var res = new GeoJsonWriter().Write(featureCollection);

            CompareJson(geoJsonString, res);
        }
        public void TestReaderFailsToParseProperties()
        {
            const string geojson = @"{
  ""type"": ""Feature"",
  ""geometry"": {
    ""type"": ""Point"",
    ""coordinates"": [
      12.5851472,
      55.68323837
    ]
  },
  ""crs"": {
    ""type"": ""name"",
    ""properties"": {
      ""name"": ""EPSG:4326""
    }
  },
  ""properties"": {
    ""id"": ""0a3f507a-b2e6-32b8-e044-0003ba298018"",
    ""status"": 1,
    ""vejkode"": ""4112"",
    ""vejnavn"": ""Landgreven"",
    ""adresseringsvejnavn"": ""Landgreven"",
    ""husnr"": ""10"",
    ""supplerendebynavn"": null,
    ""postnr"": ""1301"",
    ""postnrnavn"": ""København K"",
    ""kommunekode"": ""0101""
  }
}";

            Feature f = null;

            Assert.That(() => f = new GeoJsonReader().Read <Feature>(geojson), Throws.Nothing);
            Assert.That(f.Attributes, Is.Not.Null);
            Assert.That(f.Attributes.Count, Is.EqualTo(10));
            Assert.That(FeatureExtensions.HasID(f), Is.True);
            Assert.That(FeatureExtensions.ID(f), Is.EqualTo("0a3f507a-b2e6-32b8-e044-0003ba298018"));
        }
Ejemplo n.º 4
0
        public void TestIssue88WithoutAdditionalProperties()
        {
            string expectedJson = @"
{
	""id"" : ""00000000-0000-0000-0000-000000000000"",
	""type"" : ""Feature"",
	""geometry"" : null,
	""properties"" : {
		""yesNo 1"" : false,
		""date 1"" : ""2016-02-16T00:00:00""
	}
}
";

            GeoJsonSerializer serializer = new GeoJsonSerializer();
            Feature           feat       = null;

            Assert.DoesNotThrow(() =>
            {
                using (JsonReader reader = new JsonTextReader(new StringReader(expectedJson)))
                    feat = serializer.Deserialize <Feature>(reader);
            });

            Assert.IsNotNull(feat);
            Assert.IsTrue(FeatureExtensions.HasID(feat));
            Assert.AreEqual("00000000-0000-0000-0000-000000000000", FeatureExtensions.ID(feat));
            IGeometry geometry = feat.Geometry;

            Assert.IsNull(geometry);
            IAttributesTable attributes = feat.Attributes;

            Assert.IsNotNull(attributes);
            Assert.AreEqual(3, attributes.Count);
            Assert.AreEqual(FeatureExtensions.ID(feat), attributes["id"]);
            Assert.AreEqual(false, attributes["yesNo 1"]);
            Assert.AreEqual(DateTime.Parse("2016-02-16T00:00:00", CultureInfo.InvariantCulture), attributes["date 1"]);
        }