sibartlett / Geo

A geospatial library for .NET
https://www.nuget.org/packages/Geo/
GNU Lesser General Public License v3.0
176 stars 39 forks source link

Handling null geometries #11

Closed brucejames closed 9 years ago

brucejames commented 9 years ago

The GeoJSON draft spec (http://wiki.geojson.org/GeoJSON_draft_version_5) suggests that the geometry property can be null:

"A GeoJSON object with the type "Feature" represents a geometry with additional properties (referred to as a feature object below). A feature object must have a member with the name "geometry". The value of the geometry member is a geometry object as defined above or a JSON null value (as in {"type":"Feature", "properties": {"title":"empty"}, "geometry":null})."

I think the fix to support this is quite simple. Check for the null geometry in TryParseFeature as shown below:

    private bool TryParseFeature(JsonObject obj, out object result)
    {
        string typeString;
        if(TryParseTypeString(obj, out typeString) && typeString.ToLowerInvariant()== "feature")
        {
            object geometry;
            object geo = null;
            if (obj.TryGetValue("geometry", out geometry) && (geometry == null || TryParseGeometry((JsonObject)geometry, out geo)))

..etc

Regards Bruce

brucejames commented 9 years ago

Hi Simon,

That was quick!

When I get the Geo.dll from via a nugget, I don’t see the fix (Yet the file time indicates it was built today). Yet when I download the sources and build myself, all is good.

Could the package build have failed somehow?

Regards Bruce

From: Simon Bartlett [mailto:notifications@github.com] Sent: Friday, 31 October 2014 1:51 p.m. To: sibartlett/Geo Cc: Bruce James Subject: Re: [Geo] Handling null geometries (#11)

Closed #11https://github.com/sibartlett/Geo/issues/11 via 51dc4e3https://github.com/sibartlett/Geo/commit/51dc4e3e925a1cb669026074f9f21f89bbb2fb36.

— Reply to this email directly or view it on GitHubhttps://github.com/sibartlett/Geo/issues/11#event-186319151.

sibartlett commented 9 years ago

Hi Bruce,

I just tried creating a new project, retrieving the Geo from NuGet, and writing a test that deserializes a feature with a null geometry - and it all worked fine for me.

Maybe you can try again?

Simon

brucejames commented 9 years ago

Hi Simon,

Yes all is good. I tracked it down to a dud reference in one of my projects which was somehow preventing the latest nuget version from getting updated for that project. Sorry to have bothered you.

Regards Bruce

From: Simon Bartlett [mailto:notifications@github.com] Sent: Saturday, 1 November 2014 1:46 p.m. To: sibartlett/Geo Cc: Bruce James Subject: Re: [Geo] Handling null geometries (#11)

Hi Bruce,

I just tried creating a new project, retrieving the Geo from NuGet, and writing a test that deserializes a feature with a null geometry - and it all worked fine for me.

Maybe you can try again?

Simon

— Reply to this email directly or view it on GitHubhttps://github.com/sibartlett/Geo/issues/11#issuecomment-61349815.

sibartlett commented 9 years ago

No need to apologize, I was happy to help!