ProjNet reference

Topics: SharpMap v0.9 / v1.x
Editor
Feb 28, 2012 at 10:57 PM

Hi guys

I have updated the Sharpmap's source code in my project to changeset 95933.

Now I'm having issues with ProjNet.dll from ExternalReferences. It throws an exception doing on the fly reprojections in this line of code:

CoordinateTransformation.MathTransform.Invert();

It is trying to read a file in folder D:\Development\Codeplex\ProjNet\Sharpmap.CoordinateSystems... which doesnt exists.

Should I get another dll? or change my code to DotSpatialProjections?

Here the stack trace:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotImplementedException: No se puede implementar el método o la operación.

Source Error:

Line 227:            {
Line 228:#if !DotSpatialProjections
Line 229:                CoordinateTransformation.MathTransform.Invert();
Line 230:                envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform);
Line 231:                CoordinateTransformation.MathTransform.Invert();


Source File: G:\trabajos\PROYECTOS\GIS\SharpMap\Layers\VectorLayer.cs Line: 229

Stack Trace:

[NotImplementedException: No se puede implementar el método o la operación.]
   ProjNet.CoordinateSystems.Transformations.GeographicTransform.Invert() in D:\Development\Codeplex\Proj.Net\SharpMap.CoordinateSystems\CoordinateSystems\Transformations\GeographicTransform.cs:139
   ProjNet.CoordinateSystems.Transformations.ConcatenatedTransform.Invert() in D:\Development\Codeplex\Proj.Net\SharpMap.CoordinateSystems\CoordinateSystems\Transformations\ConcatenatedTransform.cs:110
   SharpMap.Layers.VectorLayer.Render(Graphics g, Map map) in G:\trabajos\PROYECTOS\GIS\SharpMap\Layers\VectorLayer.cs:229
   SharpMap.Map.RenderMap(Graphics g) in G:\trabajos\PROYECTOS\GIS\SharpMap\Map\Map.cs:370
   SharpMap.Map.GetMap() in G:\trabajos\PROYECTOS\GIS\SharpMap\Map\Map.cs:224
   SharpMap.Web.UI.Ajax.AjaxMapControl.GenerateMap() in G:\trabajos\PROYECTOS\GIS\SharpMap.UI\Web\UI\Ajax\AjaxMapControl.cs:365
   SharpMap.Web.UI.Ajax.AjaxMapControl.GenerateClientScripts() in G:\trabajos\PROYECTOS\GIS\SharpMap.UI\Web\UI\Ajax\AjaxMapControl.cs:423
   SharpMap.Web.UI.Ajax.AjaxMapControl.CreateChildControls() in G:\trabajos\PROYECTOS\GIS\SharpMap.UI\Web\UI\Ajax\AjaxMapControl.cs:353
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

Thanks 

carjona

Coordinator
Feb 29, 2012 at 7:24 AM

You are problably using a Conversion that is not invertable by Proj.NET (for example some transformations to and from the Google Mercator have this issue).

You can create the inverse transformation yourself and assign it to the ReverseCoordianteTransformation on the VectorLayer and it should work.

Developer
Feb 29, 2012 at 7:30 AM

you can check the sharpmap.demo.wms project where you can find a sample about how to define a CoordinateConversion and a InverseConversion.

Anyway, playing with compilation macros you can activate DotSpatial as coordinate converter, that can fix your error.

Editor
Mar 1, 2012 at 12:43 PM

petlof: You are right. The problem happened when trying to transform from WGS 84 / UTM zone 20S to Google Mercator

D_Guidi: I will try DotSpatial

Thank you all !

 

Editor
Mar 13, 2012 at 11:50 PM

It would be nice to have an example in HOW TO apply on the fly transformations with DotSpatial, like the one for Proj.NET: http://sharpmap.codeplex.com/wikipage?title=Apply%20on%20the%20fly%20transformation%20to%20a%20layer

Also, is not that straightforward to work with DotSpatial. Besides changing Sharpmap`s project compilation macro to MapBox DotSpatialProjections, there are many errors to check, maybe because DotSpatial.Projections.dll changes.

Editor
Mar 14, 2012 at 4:03 PM

By the way...

This is the code that worked for me in SharpMap.Demo.Wms project to reproject EPSG:4326 to EPSG:900913 (Google Mercator) using DotSpatial.Projections

 public static DotSpatial.Projections.ICoordinateTransformation LatLonToGoogleDotSpatial()
        {
            string projectionWkt = @"PROJCS[""Popular Visualisation CRS / Mercator"", 
                    GEOGCS[""Popular Visualisation CRS"", 
                    DATUM[""Popular Visualisation Datum"", 
                    SPHEROID[""Popular Visualisation Sphere"", 6378137, 0, AUTHORITY[""EPSG"",7059]],
                    TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[""EPSG"",6055]],
                    PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"", ""8901""]], 
                    UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9102""]], 
                    AXIS[""E"", EAST], 
                    AXIS[""N"", NORTH], 
                    AUTHORITY[""EPSG"",4055]], 
                   PROJECTION[""Mercator""], 
                   PARAMETER[""False_Easting"", 0], 
                   PARAMETER[""False_Northing"", 0], 
                   PARAMETER[""Central_Meridian"", 0], 
                   PARAMETER[""Latitude_of_origin"", 0], 
                   UNIT[""metre"", 1, AUTHORITY[""EPSG"", ""9001""]], 
                   AXIS[""East"", EAST], 
                   AXIS[""North"", NORTH], 
                   AUTHORITY[""EPSG"",900913]]";

            DotSpatial.Projections.ProjectionInfo wgs84 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            DotSpatial.Projections.ProjectionInfo sphericalMercator = new DotSpatial.Projections.ProjectionInfo();
            sphericalMercator.ParseEsriString(projectionWkt);
            string x = sphericalMercator.ToEsriString();
            DotSpatial.Projections.CoordinateTransformation transform = new DotSpatial.Projections.CoordinateTransformation();
            transform.Source = wgs84;
            transform.Target = sphericalMercator;
            return transform;
        }
public static Map OpenLayers()
        {
            DotSpatial.Projections.ICoordinateTransformation transformation = LatLonToGoogleDotSpatial();
            HttpContext context = HttpContext.Current;
            Map map = new Map(new Size(1, 1));

            IDictionary<string, LayerData> dict = NyC;
            foreach (string layer in dict.Keys)
            {
                string format = String.Format("~/App_Data/nyc/{0}.shp", layer);
                string path = context.Server.MapPath(format);
                if (!File.Exists(path))
                    throw new FileNotFoundException("file not found", path);

                LayerData data = dict[layer];
                ShapeFile dataSource = new ShapeFile(path, true) { SRID = 900913 };
                VectorLayer item = new VectorLayer(layer, dataSource)
                {
                    Style = (VectorStyle)data.Style,
                    SmoothingMode = SmoothingMode.AntiAlias,
                    CoordinateTransformation = transformation
                };
                map.Layers.Add(item);
            }
            return map;
        }
Editor
Mar 14, 2012 at 7:43 PM

I realized that IT IS easy to work with DotSpatial.Projections. I thought that compilation macro had to be changed only in SharpMap project but it also needs to be changed in every project.

The only changes I saw in DotSpatial.Projections library was:

AutorithyCode --> EpsgCode

ReadEsriString --> ParseEsriString