This project has moved. For the latest updates, please go here.

From GeoJSON/Text to Polygon/Multipolygon

Topics: General Topics
Jun 16, 2016 at 11:17 AM
I habe a textfile with GeoJSON Polygons and Multipolygons (1 row -> 1 Poly/Multipoly). How can I generate a VectorLayer with all these geometries dynamically (read the file -> render a map) for a WinForm-App? Can anybody post some example code.... I try for a week but i dont get it.
Thanks a lot...
Jun 16, 2016 at 2:01 PM
Could you post an excerpt of the data you want to display?
Jun 16, 2016 at 9:13 PM
Edited Jun 16, 2016 at 9:13 PM
Yes, i can: (its just one example, in reality the GeoJSON is generate dynamically.)

I'm on the way to split the coordinates and ignore the GeoJSON structure... but then, I have a problem with Multipolygons. I have a really deep problem to generate code for that, so i hope you can Show me a good solution with sample code :-) For Points i solved the problem by using just the x-y-coordinates.

thanks for all,
Jun 17, 2016 at 6:53 AM
Edited Jun 17, 2016 at 9:00 AM
You need to install the following NuGet package
public void TestGeoJson(System.Collections.Generic.IEnumerable<string> jsons)
    var gjr = new NetTopologySuite.IO.GeoJsonReader();

    var geom = jsons.Select(json => gjr.Read<GeoAPI.Geometries.IGeometry>(json)).ToList();

    var fp = new SharpMap.Data.Providers.GeometryFeatureProvider(geom);
    var l = new SharpMap.Layers.VectorLayer("geojson", fp);
    l.CoordinateTransformation = new 
    l.Style = SharpMap.Styles.VectorStyle.CreateRandomPolygonalStyle();
    using (var m = new SharpMap.Map())
        m.Layers.Add(new SharpMap.Layers.TileLayer(
                BruTile.Predefined.KnownTileSource.OpenCycleMapTransport), "OSM" ));
        m.BackColor = System.Drawing.Color.White;
        m.Zoom *= 1.2;

        using (var image = m.GetMap())