From GeoJSON/Text to Polygon/Multipolygon

Topics: General Topics
Jun 16 at 11:17 AM
Hi,
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...
Coordinator
Jun 16 at 2:01 PM
Could you post an excerpt of the data you want to display?
Jun 16 at 9:13 PM
Edited Jun 16 at 9:13 PM
Yes, i can: http://www.file-upload.net/download-11684485/testdata.txt.html (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,
almaz26
Coordinator
Jun 17 at 6:53 AM
Edited Jun 17 at 9:00 AM
You need to install the following NuGet package
NetTopologySuite.IO.GeoJson
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 
        ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(
            ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84,
            ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
    l.Style = SharpMap.Styles.VectorStyle.CreateRandomPolygonalStyle();
            
    using (var m = new SharpMap.Map())
    {
        m.Layers.Add(new SharpMap.Layers.TileLayer(
            BruTile.Predefined.KnownTileSources.Create(
                BruTile.Predefined.KnownTileSource.OpenCycleMapTransport), "OSM" ));
        m.Layers.Add(l);
        m.BackColor = System.Drawing.Color.White;
        m.ZoomToBox(l.Envelope);
        m.Zoom *= 1.2;

        using (var image = m.GetMap())
        {
            image.Save("GeoJsonExample.png");
        }
    }
}