Coder Social home page Coder Social logo

Comments (6)

HarelM avatar HarelM commented on August 21, 2024

@airbreather @FObermaier anyone? Seems like a straight forward case, I'm not sure what I'm missing... :-(

from nettopologysuite.io.geojson.

HarelM avatar HarelM commented on August 21, 2024

Ok, Found the bug and found the solution.
It's a one line change:
Missing the following line in CoordinateConverter.CanConvert:
typeof(Coordinate).IsAssignableFrom(objectType) ||
So the function should look as follows:

        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof(Coordinate) ||
                   objectType == typeof(Coordinate[]) ||
                   objectType == typeof(List<Coordinate[]>) ||
                   objectType == typeof(List<List<Coordinate[]>>) ||
                   typeof(Coordinate).IsAssignableFrom(objectType) ||
                   typeof(IEnumerable<Coordinate>).IsAssignableFrom(objectType) ||
                   typeof(IEnumerable<IEnumerable<Coordinate>>).IsAssignableFrom(objectType) ||
                   typeof(IEnumerable<IEnumerable<IEnumerable<Coordinate>>>).IsAssignableFrom(objectType);
        }

Let me know if you need a PR for this.
I'm in the middle of the migration and it would help me a lot if you can add this and create a new Nuget Package.

Relevant test:

        [Test, GeoJsonIssueNumber(41)]
        public void Test3DPointSerialization()
        {
            var featureCollection = new FeatureCollection { new Feature(new Point(1, 2, 3), new AttributesTable()) };
            var writer = new StringWriter();
            var jsonWriter = new JsonTextWriter(writer);
            var serializer = GeoJsonSerializer.Create(new GeometryFactory(), 3);
            serializer.Serialize(jsonWriter, featureCollection);
            string json = writer.ToString();
            Assert.That(json, Is.EqualTo("{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.0,2.0,3.0]},\"properties\":{}}]}"));
        }

from nettopologysuite.io.geojson.

HarelM avatar HarelM commented on August 21, 2024

I have created the relevant pull request (#43), easier than writing what you should change :-)
Can this please please be merged and with a new NuGet package release? I really need this...

from nettopologysuite.io.geojson.

HarelM avatar HarelM commented on August 21, 2024

I have found a workaround to use the following patch until a new version will be released.

public class CoordinateConverterPatch : CoordinateConverter
    {
        public CoordinateConverterPatch() : base() { }
        public CoordinateConverterPatch(PrecisionModel precisionModel, int dimension) : base(precisionModel, dimension) { }

        public override bool CanConvert(Type objectType)
        {
            return base.CanConvert(objectType) || typeof(CoordinateZ) == objectType;
        }
    }

Which can be added to the JsonSerializer converters.
Keep me posted on the new NuGet.

from nettopologysuite.io.geojson.

airbreather avatar airbreather commented on August 21, 2024

@HarelM thanks for reporting this and for doing all the work to find a fix for it. Note that you do need to use one of the GeoJsonSerializer.Create overloads that accepts the dimension parameter, since the default dimension is 2.

2.0.1 is now available on NuGet with this fix.

from nettopologysuite.io.geojson.

HarelM avatar HarelM commented on August 21, 2024

Glad I could help, you guys are doing a great job!

from nettopologysuite.io.geojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.