SharpMap Converters GeoAPI

Topics: Algorithms, SharpMap Project, SharpMap v0.9 / v1.x
Developer
Jan 21, 2011 at 2:57 AM

Hi, I think that the SharpMap Library should have a generic converter to the GeoAPI Geometries.

I know that to have that, SharpMap need to references GeoAPI.DLL and NetTopologySuite.Dll.

I've made a Class that can be used to convert SharpMapGeometries and vice-versa.

I will post the code here.

 

thank you

Ricardo

Developer
Jan 21, 2011 at 2:58 AM

This File is called: GeoAPIConverter.cs



using System;
using System.Collections.Generic;
using System.Text;
using GisSharpBlog.NetTopologySuite.IO;

namespace SharpMap.Converters
{
    public static class GeoAPINTS
    {
        public static GeoAPI.Geometries.IGeometry SharpMapToGeoAPI(SharpMap.Geometries.Geometry geom)
        {
            WKBReader reader = new GisSharpBlog.NetTopologySuite.IO.WKBReader();
            return reader.Read(SharpMap.Converters.WellKnownBinary.GeometryToWKB.Write(geom));
        }

        public static SharpMap.Geometries.Geometry GeoAPIToSharpMap(GeoAPI.Geometries.IGeometry geom)
        {
            WKBWriter writer = new WKBWriter();
            return SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse(writer.Write(geom));
        }

        public static SharpMap.Geometries.BoundingBox GeoAPIToBoundingBox(GeoAPI.Geometries.IGeometry geom)
        {
            return GeoAPIToSharpMap(geom).GetBoundingBox();
        }
    }
}

Coordinator
Jan 21, 2011 at 7:44 AM

Hello cofee,

thanks for sharing this. For your information:

There is a sharpmap branch (v0.9.5) that has full GeoAPI/NTS integration.

The branch V0.9.5-Deltares is a massive enhancement of that branch.

Hth FObermaier

Developer
Jan 21, 2011 at 9:37 AM
FObermaier wrote:

The branch V0.9.5-Deltares is a massive enhancement of that branch.

Did you mean the 0.9.5-DeltaShell branch? In the svn I don't see any other branch with the given name

Developer
Jan 21, 2011 at 9:39 AM
cofee wrote:

This File is called: GeoAPIConverter.cs



using System;
using System.Collections.Generic;
using System.Text;
using GisSharpBlog.NetTopologySuite.IO;

namespace SharpMap.Converters
{
    public static class GeoAPINTS
    {
        public static GeoAPI.Geometries.IGeometry SharpMapToGeoAPI(SharpMap.Geometries.Geometry geom)
        {
            WKBReader reader = new GisSharpBlog.NetTopologySuite.IO.WKBReader();
            return reader.Read(SharpMap.Converters.WellKnownBinary.GeometryToWKB.Write(geom));
        }

        public static SharpMap.Geometries.Geometry GeoAPIToSharpMap(GeoAPI.Geometries.IGeometry geom)
        {
            WKBWriter writer = new WKBWriter();
            return SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse(writer.Write(geom));
        }

        public static SharpMap.Geometries.BoundingBox GeoAPIToBoundingBox(GeoAPI.Geometries.IGeometry geom)
        {
            return GeoAPIToSharpMap(geom).GetBoundingBox();
        }
    }
}

I think that it's relatively simple to modify the actual NTSConverter, to be able to manage GeoAPI interfaces instead of NTS objects

Coordinator
Jan 21, 2011 at 10:22 AM
D_Guidi wrote:
FObermaier wrote:

The branch V0.9.5-Deltares is a massive enhancement of that branch.

Did you mean the 0.9.5-DeltaShell branch? In the svn I don't see any other branch with the given name

yes, it's named V0.9.5-Deltares.

Developer
Jan 21, 2011 at 10:58 AM

@cofee: see patch 8154 in http://sharpmap.codeplex.com/SourceControl/list/patches and please give some feedback

Developer
Jan 21, 2011 at 11:01 AM

@FObermaier: I don't see any V0.9.5-Deltares branch using svnbridge, maybe I must try using a TFS client

Coordinator
Jan 21, 2011 at 11:42 AM

seems I've lost my head this morning, it is V0.9.5-Deltashell

Sorry for the confusion

FObermaier

Developer
Jan 21, 2011 at 11:46 AM
Edited Jan 21, 2011 at 12:09 PM

> it is V0.9.5-Deltashell

happy to see that ;)

WOW :-) full of nteresting things ;)