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 support #1638

Closed
janusw opened this issue Jun 10, 2022 · 9 comments
Closed

GeoJSON support #1638

janusw opened this issue Jun 10, 2022 · 9 comments

Comments

@janusw
Copy link
Member

janusw commented Jun 10, 2022

It would be very useful if Mapsui had intrinsic support for the GeoJSON format.

To implement this, one could simply set up a GeoJsonProvider (implementing the IProvider) interface, much like the ShapeFile or WmsProvider. This would read & parse a GeoJSON file (could be a local file or remote URL) and spit out the corresponding list of features, which could then be rendered via some layer.

Any comments on this idea or how to implement it? I am slightly surprised that no one has started this kind of thing yet :D

@janusw
Copy link
Member Author

janusw commented Jun 10, 2022

I'll note that there seem to be two geojson files in the repository:

... but apparently they're not being used anywhere.

Fun fact on the side: Opening the first link actually visualizes the city pins on a (mapbox) world map, so apparently GitHub itself has GeoJSON support ;)
With the second link this does not work though, probably because of the differing file extension.

@charlenni
Copy link
Member

Isn't it possible to use the NTS extension NetTopologySuite.IO.GeoJSON to read all the data and then show on a map?

@pauldendulk
Copy link
Member

Isn't it possible to use the NTS extension NetTopologySuite.IO.GeoJSON to read all the data and then show on a map?

That looks like a good option.

@janusw
Copy link
Member Author

janusw commented Jun 12, 2022

Isn't it possible to use the NTS extension NetTopologySuite.IO.GeoJSON to read all the data and then show on a map?

Yes, good point. That would already cover a big part of my proposed GeoJsonProvider. Then one probably only needs a thin wrapper that translates from NetTopologySuite.Features.IFeature to Mapsui.Nts.GeometryFeature or so.

@pauldendulk
Copy link
Member

ah yes. I have not looked into NetTopologySuite.Features.IFeature at all so far. I assume there are other NTS data sources that use it as well. The namespace NetTopologySuite.Features is not included anywhere in Mapsui. Perhaps it is possible to resolve this with a ToMapsui extension method.

@jamesmontemagno
Copy link

I am curious about supporting locating a geojson file. I have one sitting around and I am currently having to use the geojson.net nuget to read in the FeatureCollection and then convert it to mapsui geometry, but they are basically all the same names/object types, so would be nice to just throw in a json file and then create the layers.

@janusw
Copy link
Member Author

janusw commented Dec 15, 2022

I actually ended up using the NetTopologySuite.IO.GeoJSON nuget to read a FeatureCollection from the geojson string:

            NetTopologySuite.Features.FeatureCollection fc;

            var serializer = GeoJsonSerializer.Create();
            using (var stringReader = new StringReader(geoJson))
            using (var jsonReader = new JsonTextReader(stringReader))
            {
                fc = serializer.Deserialize<NetTopologySuite.Features.FeatureCollection>(jsonReader);
            }

Then I convert this to a list of GeometryFeatures manually (with a custom style) and display those via a MemoryLayer.

@jamesmontemagno, I assume this is basically the same thing that you do. And yes, I agree it would be nice to have some sort of convenience wrapper in Mapsui for this kind of functionality (maybe via a GeoJsonProvider as propsed above)?

@jamesmontemagno
Copy link

Yup that is what i did basically. I guess that one is built in already as a dependency so maybe i will try that out.

@pauldendulk
Copy link
Member

GeoJSON support was added by @inforithmics in Mapsui.Extension. See the online sample by selecting 'GeoJson' under 'Data Formats'.

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

No branches or pull requests

4 participants