Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoJSON Reader and FeatureCollection json #16

Closed
shaahink opened this issue Nov 5, 2014 · 14 comments
Closed

GeoJSON Reader and FeatureCollection json #16

shaahink opened this issue Nov 5, 2014 · 14 comments
Assignees
Labels

Comments

@shaahink
Copy link

shaahink commented Nov 5, 2014

Hello,

I am having problem when I try to deserialize below FeatureCollection.

{"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]]]}}]}

According to http://geojsonlint.com/ the geoJSON is valid.

Here is the unit test:

    [Test]
    public void NtsFeatureCollectionDeserializeBug()
    {
        string geoJson = "{'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]]]}}]}".Replace("'", "\"");
        var geoJsonReader = new GeoJsonReader();
        var featureCollection =  geoJsonReader.Read<FeatureCollection>(geoJson);
        Assert.IsNotNull(featureCollection);
    }

I get this exception:

System.ArgumentException : Expected token 'geometry' not found.
at NetTopologySuite.IO.Converters.FeatureConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader)
at NetTopologySuite.IO.Converters.FeatureCollectionConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader)
at NetTopologySuite.IO.GeoJsonReader.Read(String json)
at WebCoreMap.Test.Basemap.Geo.GeoJSONTest.NtsFeatureCollectionDeserializeBug() in GeoJSONTest.cs: line 26

Thank you

@DGuidi DGuidi added the bug label Nov 5, 2014
@DGuidi DGuidi self-assigned this Nov 5, 2014
@DGuidi
Copy link
Contributor

DGuidi commented Nov 5, 2014

I try to take a look as soon as possible.

@DGuidi
Copy link
Contributor

DGuidi commented Nov 5, 2014

as suspected, reader expects "geometry" property before "properties" property.

@shaahink
Copy link
Author

shaahink commented Nov 5, 2014

I see, I am going to try with that.

On Wed Nov 05 2014 at 1:00:58 PM Diego Guidi notifications@github.com
wrote:

as suspected, reader expects "geometry" property before "properties"
property.

Reply to this email directly or view it on GitHub
#16 (comment)
.

DGuidi added a commit that referenced this issue Nov 5, 2014
@DGuidi
Copy link
Contributor

DGuidi commented Nov 5, 2014

should be fixed now

@DGuidi DGuidi closed this as completed Nov 5, 2014
@shaahink
Copy link
Author

shaahink commented Nov 5, 2014

Many thanks.
Would you please publish it to NuGet?

@DGuidi
Copy link
Contributor

DGuidi commented Nov 5, 2014

actually, no nuget release is planned yet. my suggest: "use the source", that should be close to latest nuget release.

@chadly
Copy link

chadly commented Nov 25, 2014

Any nuget release planned for this bugfix yet? I can build from source, but it would be much easier to just install a new bugfix release from nuget... 😄

@DGuidi
Copy link
Contributor

DGuidi commented Nov 25, 2014

as said here... actually, no.
We should publish newer packages only when we have new features and/or critical fix.

@jaundice
Copy link
Contributor

One thing you can try is to use a serializer, remove the broken converter and replace it (I am replacing geometry converter, you would probably replace featureconverter)
var ser = new GeoJsonSerializer();
ser.Converters.Remove(ser.Converters.FirstOrDefault(a => a is GeometryConverter));
ser.Converters.Insert(0, new TempGeometryConverter());

@xivk
Copy link
Contributor

xivk commented Jun 22, 2016

The reader still expects 'properties' to come after 'type'. It's still valid geojson if 'properties' comes before 'type'. Can we fix this?

@xivk xivk reopened this Jun 22, 2016
@DGuidi
Copy link
Contributor

DGuidi commented Jun 29, 2016

@xivk can you post some sample code? I've made some checks but I'm unable to reproduce the error...

@xivk
Copy link
Contributor

xivk commented Jun 29, 2016

It was this geojson file:

https://gist.github.com/xivk/43308e73c29356e8c17f399ba68ca196

I'm not able to create a test-project right now... on holiday sorry. But if I remember correctly this failed to deserialise. I see now that the 'properties' part is missing entirely.

@DGuidi
Copy link
Contributor

DGuidi commented Jun 29, 2016

looks that the json you posted isn't related to issue you experienced. enjoy the holiday and maybe post a unit test when you return at work :)
I suspect your error is related to this

DGuidi referenced this issue Jun 29, 2016
@DGuidi
Copy link
Contributor

DGuidi commented Jun 29, 2016

@xivk please check if 116e607 helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants