6

The following piece of code worked with an older version of DotSpatial.

public static Geometry Project_EPSG25832_To_EPSG3857(byte[] wkb, int SRID)
    {
        NetTopologySuite.IO.WKBReader reader = new NetTopologySuite.IO.WKBReader();
        Geometry geom = (Geometry)reader.Read(wkb);

        var epsg25832 = new DotSpatial.Projections.ProjectionInfo();
        var epsg3857 = new DotSpatial.Projections.ProjectionInfo();
        epsg25832.ParseEsriString(ESRI_EPSG_25832);
        epsg3857.ParseEsriString(ESRI_EPSG_3857);

        Geometry transformedGeom = (Geometry)DotSpatial.Projections.GeometryTransform.TransformGeometry(geom, epsg25832, epsg3857, NetTopologySuite.NtsGeometryServices.Instance.CreateGeometryFactory());

        return transformedGeom;
    }

I had to upgrade the DotSpatial suite to the latest version and now the above code breaks. It seems the "DotSpatial.Projections.GeometryTransform" class doesn't exist any more.

I can't seem to find anything similar in the new version of DotSpatial except for this method

Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);

...but it takes an array of points...

Anybody know of a nice and easy way of coming from a WKB to an array of points, or maybe there is another library that is easier to use in .NET/C#??

  • 1
    You mix DotSpatial and NetTopologySuite. Is this by intention? – Wernfried Domscheit Aug 5 '15 at 8:34
3

This is the code I ended up using:

public static Geometry Project_EPSG25832_To_EPSG3857(byte[] wkb)
        {
            NetTopologySuite.IO.WKBReader reader = new NetTopologySuite.IO.WKBReader();
            Geometry geom = (Geometry)reader.Read(wkb);

            double[] pointArray = new double[geom.Coordinates.Count() * 2];
            double[] zArray = new double[1];
            zArray[0] = 1;

            int counterX = 0;
            int counterY = 1;
            foreach (var coordinate in geom.Coordinates)
            {
                pointArray[counterX] = coordinate.X;
                pointArray[counterY] = coordinate.Y;

                counterX = counterX + 2;
                counterY = counterY + 2;
            }

            var epsg25832 = new DotSpatial.Projections.ProjectionInfo();
            var epsg3857 = new DotSpatial.Projections.ProjectionInfo();
            epsg25832.ParseEsriString(ESRI_EPSG_25832);
            epsg3857.ParseEsriString(ESRI_EPSG_3857);

            DotSpatial.Projections.Reproject.ReprojectPoints(pointArray, zArray, epsg25832, epsg3857, 0, (pointArray.Length / 2));

            counterX = 0;
            counterY = 1;
            foreach (var coordinate in geom.Coordinates)
            {
                coordinate.X = pointArray[counterX];
                coordinate.Y = pointArray[counterY];

                counterX = counterX + 2;
                counterY = counterY + 2;
            }
            **geom.GeometryChanged();**
            return geom;
        }
|improve this answer|||||
2

Where is the problem, simply use this:

double lat = 8.654;
double lon = 38.123;

double[] xy = new double[2] { lat, lon };
double[] z = new double[1] { 1234.5 };

Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);

Console.WriteLine(String.Foramt("New Lat/Lon = {0}/{1}", xy[0], xy[1]));
|improve this answer|||||
1

You can also use the Proj4 library. I think the number of supported projections is bigger than in all others. As far as I know the supported number of projections in NetTopologySuite is very limited.

There is a wrapper available in order to use Proj4 in C#: http://ftp.dfg.ca.gov/Public/BDB/Tools/proj4/

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.