SharpMap as WMS server and Google Map projection like

Mar 22, 2010 at 4:03 PM
Edited Mar 22, 2010 at 5:18 PM
Ciao, i would like to display map using open layer using a projection like Google Map. I've a world map stored into SQL 2008 but with srid 4326 using the Geographic Coordinate System datum WGS84 inside a "Geometry" column.. I saw the transformation routine wgs84toGoogle in this forums but even if i try to use i cannot render map.... i try even on a win form usig the GetMap method directly.... nothing to do! Does i need to change the SRID? but i saw that the official SRID for "Google map projection" is not included into sql2008! :( Any other suggestion? Many Thanks Alberto
Mar 25, 2010 at 4:47 PM

It was a stupid question?  Or there is no answere?

Mar 25, 2010 at 11:33 PM

can you post the code you are using?

Coordinator
Mar 26, 2010 at 7:53 AM

Hello Alberto, ghelobytes,

the reason you don't see anything on your map is that there is an error in Proj.NET's MathTransform.Inverse() function. The returned Transformation is ok, but the original Transformation is screwed up.

As a quick solution to the problem replace every call to

... someTransformation.MathTransform.Inverse() ...;  

with

someTransformation.MathTransform.Invert();
... someTransformation.MathTransform() ...; //without Inverse()
someTransformation.MathTransform.Invert();

Hth FObermaier

Mar 26, 2010 at 10:41 AM
Edited Mar 26, 2010 at 1:28 PM

But in my map i never cal method Iverse() nor Ivert();   

It should be possible that SharpMap internally do this?

 

i'm using this code:

 

        /// <summary>

        /// Returns the Base Layer Map of the world taken from DB

        /// </summary>

        /// <returns></returns>

        public static VectorLayer BuildWorldLayer()

        {

            SharpMap.Layers.VectorLayer worldLayer = new SharpMap.Layers.VectorLayer("world");

            SharpMap.Data.Providers.SqlServer2008 sql2008

                = new SharpMap.Data.Providers.SqlServer2008(KTMapConfiguration.MapDbConnectionString, "dbo.World", "geom", "oid");

 

 

            worldLayer.DataSource = sql2008;

            worldLayer.MaxVisible = 400;

            worldLayer.MinVisible = 0;

            worldLayer.SRID = 4326;

 

            worldLayer.CoordinateTransformation = wgs84toGoogle();

            return worldLayer;

        }

 

 

 

 

        public static ICoordinateTransformation wgs84toGoogle()
        {
            CoordinateSystemFactory csFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
            IGeographicCoordinateSystem wgs84 = csFac.CreateGeographicCoordinateSystem(
              "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
              new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)
            );
            List<ProjectionParameter> parameters = new List<ProjectionParameter>();
            parameters.Add(new ProjectionParameter("semi_major", 6378137.0));
            parameters.Add(new ProjectionParameter("semi_minor", 6378137.0));
            parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0));
            parameters.Add(new ProjectionParameter("central_meridian", 0.0));
            parameters.Add(new ProjectionParameter("scale_factor", 1.0));
            parameters.Add(new ProjectionParameter("false_easting", 0.0));
            parameters.Add(new ProjectionParameter("false_northing", 0.0));
            IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);
            IProjectedCoordinateSystem epsg900913 = csFac.CreateProjectedCoordinateSystem(
              "Google Mercator", wgs84, projection, LinearUnit.Metre,
              new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));
            return ctFac.CreateFromCoordinateSystems(wgs84, epsg900913);
        }

        public static ICoordinateTransformation wgs84toGoogle()

        {

            CoordinateSystemFactory csFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

 

            IGeographicCoordinateSystem wgs84 = csFac.CreateGeographicCoordinateSystem(

              "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,

              new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)

            );

 

            List<ProjectionParameter> parameters = new List<ProjectionParameter>();

            parameters.Add(new ProjectionParameter("semi_major", 6378137.0));

            parameters.Add(new ProjectionParameter("semi_minor", 6378137.0));

            parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0));

            parameters.Add(new ProjectionParameter("central_meridian", 0.0));

            parameters.Add(new ProjectionParameter("scale_factor", 1.0));

            parameters.Add(new ProjectionParameter("false_easting", 0.0));

            parameters.Add(new ProjectionParameter("false_northing", 0.0));

            IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);

 

            IProjectedCoordinateSystem epsg900913 = csFac.CreateProjectedCoordinateSystem(

 

              "Google Mercator", wgs84, projection, LinearUnit.Metre,

              new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

 

            return ctFac.CreateFromCoordinateSystems(wgs84, epsg900913);

        }

 

Coordinator
Mar 26, 2010 at 11:56 AM

yes, sharpmap does it internally.

FObermaier

Mar 26, 2010 at 1:29 PM

Ok, so there is a workaround to make it running?   

Coordinator
Mar 26, 2010 at 2:13 PM

there is no patch available, the workaroud is outlined in my previous post.
This involves compiling sharpmap yourself, which is strongly suggested anyway.

Hth FObermaier

Mar 26, 2010 at 3:02 PM

Ok i found in VectorLayer.cs

 

 

            if (CoordinateTransformation != null)
                envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform.Inverse());

            if (CoordinateTransformation != null)

                envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform.Inverse());

and in Label Layer the usage of MathTransorm.Inverse();
 
in which way you think is better to change!?

 

Mar 26, 2010 at 3:59 PM
Edited Mar 26, 2010 at 4:18 PM

I've tried this:

 

            //if (CoordinateTransformation != null)
            //    envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform.Inverse());
            if (CoordinateTransformation != null)
            {
                CoordinateTransformation.MathTransform.Invert();
                envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform );
                CoordinateTransformation.MathTransform.Invert();
            }

 

            //if (CoordinateTransformation != null)

            //    envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform.Inverse());

 

            if (CoordinateTransformation != null)

            {

                CoordinateTransformation.MathTransform.Invert();

                envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform );

                CoordinateTransformation.MathTransform.Invert();

            }

 

 

....but doesn't work :(   

 

but ok anyway i'm already building Sharp Map by myself but not Proj.NET    if i get the latest version i get the proj.net 1.2  but some workspace on sharp map must be changed in order to run with proj.net  

IS IT CORRECT??

 

Coordinator
Mar 26, 2010 at 4:22 PM

Do you still get a blank map?

If you want to use the latest Proj.Net, you have to change the namespaces (see this)

cheers FObermaier

Mar 26, 2010 at 4:35 PM

 

Regarding PROJ reference...   

"In order to keep in sync with Proj.Net I suggest updating Proj.Net assembly and follow the namespace changes."...

You mean to change the namespace UNDER the SharpMap Project or change the namespace under the ProJ Project?  which is the best way?

 

And...   yes ;( i get blank map again......

 

 

Mar 26, 2010 at 4:43 PM

but in the end.... 

the method i'm using...   that i took from this forum:

public static ICoordinateTransformation wgs84toGoogle() 

has the correct parameters ??  

Mar 27, 2010 at 8:45 AM

Can you post a sample WKT geometry from your database?

Something like POINT(121 14)...

Mar 27, 2010 at 9:46 AM
Edited Mar 27, 2010 at 9:52 AM

unfortunally today i've not the code nor the data.

Anyway i saw that even the BOX obtained with this slide of code:

envelope = GeometryTransform.TransformBox(envelope, CoordinateTransformation.MathTransform );

is already too strange !   and the query on the data enveloped by this box returns NO DATA....  (so this is the main reason because i don't see anything)

Ciao

Alberto 

 

 

p.s. so...  is it correct the transofrmation that i'm appling? 

Mar 27, 2010 at 9:59 AM
Edited Mar 27, 2010 at 10:00 AM

p.s. the transformation i'm using is:

so... i'm asking if it is this code that has problems!?

 

public static ICoordinateTransformation wgs84toGoogle()
{           
  CoordinateSystemFactory csFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();
  CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

  IGeographicCoordinateSystem wgs84 = csFac.CreateGeographicCoordinateSystem(
    "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
    new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)
  );

  List<ProjectionParameter> parameters = new List<ProjectionParameter>();
  parameters.Add(new ProjectionParameter("semi_major", 6378137.0));
  parameters.Add(new ProjectionParameter("semi_minor", 6378137.0));
  parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0));
  parameters.Add(new ProjectionParameter("central_meridian", 0.0));
  parameters.Add(new ProjectionParameter("scale_factor", 1.0));
  parameters.Add(new ProjectionParameter("false_easting", 0.0));
  parameters.Add(new ProjectionParameter("false_northing", 0.0));
  IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);

  IProjectedCoordinateSystem epsg900913 = csFac.CreateProjectedCoordinateSystem(

    "Google Mercator", wgs84, projection, LinearUnit.Metre,
new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

  return ctFac.CreateFromCoordinateSystems(wgs84, epsg900913);
}

Mar 27, 2010 at 11:18 AM

I used wgs84toGoogle() with shape file before and it works fine.

Have you tried commenting the line

 

worldLayer.MaxVisible = 400;

and zooming to the extent with ZoomToExtent()?

 

 

Coordinator
Mar 27, 2010 at 8:09 PM
Edited Mar 27, 2010 at 8:18 PM

Hello sandex, ghelobytes,

here is a modified sample from the WinFormsSample project (TileLayer.cs). I added wgs84 rivers shapefile to display above the tiles.

 

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using ProjNet.CoordinateSystems;
using ProjNet.CoordinateSystems.Transformations;
using SharpMap.CoordinateSystems;
using SharpMap.CoordinateSystems.Transformations;
using SharpMap.Data.Providers;
using SharpMap.Layers;
using BruTile;
using BruTile.Web;
using SharpMap;
using SharpMap.Geometries;

namespace WinFormSamples.Samples
{
    

    class TileLayerSample
    {
        public static Map InitializeMap()
        {
            Map map = new Map();
            TileLayer tileLayer = new TileLayer(new TileSourceOsm(), "OSM");
            map.Layers.Add(tileLayer);

            //Set up datasource
            ShapeFile sf = new ShapeFile("GeoData/World/rivers.shp", true);
            Debug.Assert(sf.CoordinateSystem != null);

            ICoordinateSystem csWM = new CoordinateSystemFactory().CreateFromWkt(
                @"PROJCS[""Mercator Spheric"", GEOGCS[""WGS84basedSpheric_GCS"",
DATUM[""WGS84basedSpheric_Datum"", 
SPHEROID[""WGS84based_Sphere"", 6378137, 0], 
TOWGS84[0, 0, 0, 0, 0, 0, 0]], 
PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"", ""8901""]],
UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9102""]], 
AXIS[""E"", EAST], 
AXIS[""N"", NORTH]], 
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]]");
            /*                                  ;
            @"PROJCS[""Mercator Spheric"", GEOGCS[""WGS84basedSpheric_GCS""," +
            @"DATUM[""WGS84basedSpheric_Datum"", SPHEROID[""WGS84based_Sphere"", 6378137, 0], TOWGS84[0, 0, 0, 0, 0, 0, 0]]," +
            @"PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"", ""8901""]]," +
            @"UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9102""]]," +
            @"AXIS[""E"", EAST], AXIS[""N"", NORTH]]," +
            @"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]]" );
            */
            ICoordinateTransformation ct =
                new CoordinateTransformationFactory().CreateFromCoordinateSystems(sf.CoordinateSystem, csWM);
            //Set up a river layer
            VectorLayer layRivers = new VectorLayer("Rivers");
            //Set the datasource to a shapefile in the App_data folder

            layRivers.DataSource = new ShapeFile("GeoData/World/rivers.shp", true);
            //Define a blue 1px wide pen
            layRivers.Style.Line = new Pen(Color.Blue, 1);
            layRivers.SRID = 4326;
            layRivers.CoordinateTransformation = ct;

            map.Layers.Add(layRivers);

            //map.ZoomToBox(tileLayer.Envelope);
            map.ZoomToExtents();
            return map;
        }
    }
}

 

If you use gdalrasterlayer, you may have two more places to change CoordinateTransfrom.MathTransform.Inverse()

As an alternative to change these passages in SharpMap you can apply the provided patch for Proj.Net.

If you still have problems, could you post samples of you strange coordinates?

Hth FObermaier

 

Mar 28, 2010 at 5:07 AM

@FObermaier,

Your patch solved my problem on coordinate transformation. I used to do the transformation point by point.

Now I can simply use Layer.CoordinateTransformation = transformation.

But I'm still getting the error "Only 2 dimensions are supported for points".

For now, I commented the line where the error is raised (Point.cs) but I would really like to get to the bottom of this.

 

@sandex

I tried creating a new Table and inserted a single point using this:

 

INSERT INTO SpatialTable (GeomCol1)
VALUES (geometry::STGeomFromText('POINT (2.2944851 48.8582494)', 4326));

plus the patch provided by FObermaier, everything seems to work fine. 

The coordinate by the way should point to Eiffel Tower in Paris.

 

 

Mar 29, 2010 at 7:33 AM
ghelobytes wrote:

I used wgs84toGoogle() with shape file before and it works fine.

Have you tried commenting the line

 

worldLayer.MaxVisible = 400;

and zooming to the extent with ZoomToExtent()?

 

 

Hi, i'm trying to comment this row....   then i'll try even your TileLayerSample.

Many thanks!

Mar 29, 2010 at 8:12 AM

i got exactly the same issue...

throw new Exception("Only 2 dimensions are supported for points");

It seems that a point has 3 coordinate. 

this happen with the transformation from fobermaier:

 

               @"PROJCS[""Mercator Spheric"", GEOGCS[""WGS84basedSpheric_GCS"",
DATUM[""WGS84basedSpheric_Datum"", 
SPHEROID[""WGS84based_Sphere"", 6378137, 0], 
TOWGS84[0, 0, 0, 0, 0, 0, 0]], 
PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"", ""8901""]],
UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9102""]], 
AXIS[""E"", EAST], 
AXIS[""N"", NORTH]], 
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]]");

Anyway now i'll make some more rigorouse test.  And i'll include better the version of proj i'm using and if i've mod the sharpmap VectorLayer.CS or not...
Coordinator
Mar 29, 2010 at 8:29 AM

sorry, I forgot to mention that I changed the sanity check to

if (point.Length < 2)
throw new Exception("At least 2 dimensions are needed for points (only two will be used)");

The third dimension is needed/created somewhere along the transformation path and not discarded in the end.

Hth FObermaier

 

 

Mar 29, 2010 at 8:41 AM
Edited Mar 29, 2010 at 9:40 AM

Anyway this is a set of data which i whish to display in mercator projection...  it is the EUROPE country lines

 

Luxembourg                                                                                                                                                                                                                                                      POLYGON ((5.7830381393432617 49.527271270751953, 5.9633331298828125 49.488319396972656, 5.9813880920410156 49.448318481445312, 6.1652770042419434 49.504711151123047, 6.3622207641601562 49.459980010986328, 6.3724989891052246 49.590259552001953, 6.5105547904
Macedonia                                                                                                                                                                                                                                                       POLYGON ((20.58964729309082 41.884552001953125, 20.51416015625 41.727760314941406, 20.555269241333008 41.584709167480469, 20.462490081787109 41.5536003112793, 20.562210083007812 41.40386962890625, 20.493320465087891 41.327480316162109, 20.597490310668945 4
Moldova                                                                                                                                                                                                                                                         POLYGON ((26.635000228881836 48.240871429443359, 26.7077693939209 48.253318786621094, 26.894439697265625 48.2047004699707, 27.00054931640625 48.155540466308594, 27.164440155029297 47.967758178710938, 27.238330841064453 47.785259246826172, 27.28944015502929
Monaco                                                                                                                                                                                                                                                          POLYGON ((7.3911871910095215 43.728031158447266, 7.3919000625610352 43.728900909423828, 7.3961000442504883 43.730598449707031, 7.4008002281188965 43.731399536132812, 7.406099796295166 43.731399536132812, 7.4107999801635742 43.732200622558594, 7.41499996185
Montenegro                                                                                                                                                                                                                                                      POLYGON ((19.069999694824276 43.508598327636719, 19.053899765014705 43.535598754882869, 19.011699676513672 43.556098937988338, 18.9869003295899 43.522201538085994, 18.949399948120117 43.509399414062614, 18.956699371338004 43.454399108886776, 19.02309989929
Netherlands                                                                                                                                                                                                                                                     MULTIPOLYGON (((4.2300119400024414 51.357219696044922, 4.2108330726623535 51.372489929199219, 3.9819440841674805 51.407211303710938, 3.9613890647888184 51.369709014892578, 3.8327779769897461 51.341648101806641, 3.6011109352111816 51.391929626464844, 3.4433
Norway                                                                                                                                                                                                                                                          MULTIPOLYGON (((15.477780342102051 68.877761840820312, 15.573060035705566 68.965812683105469, 15.541939735412598 69.012191772460938, 15.623889923095703 68.98052978515625, 15.863889694213867 69.026092529296875, 16.08860969543457 69.157760620117188, 16.15389
Poland                                                                                                                                                                                                                                                          POLYGON ((19.665630340576172 54.466911315917969, 19.636510848999023 54.4710693359375, 19.624469757080078 54.461490631103516, 19.439210891723633 54.395809173583984, 19.004020690917969 54.342628479003906, 18.721939086914062 54.376380920410156, 18.58527946472
Portugal                                                                                                                                                                                                                                                        MULTIPOLYGON (((-25.385000228881836 37.712211608886719, -25.160560607910156 37.746379852294922, -25.131950378417969 37.805271148681641, -25.142219543457031 37.842769622802734, -25.323329925537109 37.8638801574707, -25.577499389648438 37.82720947265625, -25
Romania                                                                                                                                                                                                                                                         POLYGON ((26.316379547119141 48.186370849609375, 26.272220611572266 48.076099395751953, 26.159160614013672 47.984989166259766, 26.011100769042969 47.979419708251953, 25.468330383300781 47.929710388183594, 25.230270385742188 47.881370544433594, 25.123880386
San Marino                                                                                                                                                                                                                                                      POLYGON ((12.407695770263672 43.913787841796875, 12.408300399780273 43.912200927734375, 12.409999847412109 43.909198760986328, 12.412199974060059 43.906101226806641, 12.416399955749512 43.904701232910156, 12.421699523925781 43.905300140380859, 12.425600051
Slovakia                                                                                                                                                                                                                                                        POLYGON ((16.944860458374023 48.616500854492188, 16.896390914916992 48.487209320068359, 16.856109619140625 48.419151306152344, 16.840829849243164 48.36859130859375, 16.94972038269043 48.278041839599609, 16.976680755615234 48.174179077148438, 17.06809997558
Slovenia                                                                                                                                                                                                                                                        POLYGON ((16.026939392089844 46.661369323730469, 15.649439811706543 46.709709167480469, 15.500829696655273 46.618038177490234, 15.105270385742188 46.657199859619141, 14.870550155639648 46.615821838378906, 14.814720153808594 46.512760162353516, 14.594160079
Spain                                                                                                                                                                                                                                                           MULTIPOLYGON (((-14.333060264587402 28.0444393157959, -14.140279769897461 28.183610916137695, -13.95028018951416 28.224720001220703, -13.844169616699219 28.402219772338867, -13.855830192565918 28.478609085083008, -13.820560455322266 28.577220916748047, -13
Svalbard                                                                                                                                                                                                                                                        MULTIPOLYGON (((25.030000686645508 76.43914794921875, 25.582220077514648 76.706649780273438, 25.515270233154297 76.710533142089844, 25.413890838623047 76.68414306640625, 25.065280914306641 76.530532836914062, 24.941389083862305 76.443862915039062, 25.03000
Sweden                                                                                                                                                                                                                                                          MULTIPOLYGON (((11.465000152587891 58.06610107421875, 11.806389808654785 58.120540618896484, 11.814720153808594 58.177490234375, 11.736669540405273 58.281650543212891, 11.671640396118164 58.276210784912109, 11.655280113220215 58.231380462646484, 11.5761098
Switzerland                                                                                                                                                                                                                                                     POLYGON ((9.540410041809082 47.266975402832031, 9.6052761077880859 47.359989166259766, 9.6649990081787109 47.381370544433594, 9.6536102294921875 47.455539703369141, 9.55825424194336 47.504070281982422, 9.5676116943359375 47.543918609619141, 9.2616653442382
Ukraine                                                                                                                                                                                                                                                         POLYGON ((23.592084884643555 51.528278350830078, 23.671379089355469 51.431659698486328, 23.632219314575195 51.307758331298828, 23.749439239501953 51.207489013671875, 23.973049163818359 50.944149017333984, 24.144710540771484 50.858039855957031, 24.130550384
United Kingdom                                                                                                                                                                                                                                                  MULTIPOLYGON (((-6.2649998664855957 56.258880615234375, -5.8602781295776367 56.3519401550293, -5.8405561447143555 56.308879852294922, -5.70222282409668 56.359149932861328, -5.703333854675293 56.375541687011719, -5.7872228622436523 56.367771148681641, -5.66
Yugoslavia                                                                                                                                                                                                                                                      POLYGON ((20.072723388671989 42.558441162109375, 20.168600082397575 42.506938934326172, 20.252220153808707 42.324428558349666, 20.35165977478033 42.324428558349666, 20.526100158691406 42.211650848388729, 20.620830535888729 41.949710845947266, 20.5896472930

 

Luxembourg                                                                                                                                                                                                                                                      POLYGON ((5.7830381393432617 49.527271270751953, 5.9633331298828125 49.488319396972656, 5.9813880920410156 49.448318481445312, 6.1652770042419434 49.504711151123047, 6.3622207641601562 49.459980010986328, 6.3724989891052246 49.590259552001953, 6.5105547904
Macedonia                                                                                                                                                                                                                                                       POLYGON ((20.58964729309082 41.884552001953125, 20.51416015625 41.727760314941406, 20.555269241333008 41.584709167480469, 20.462490081787109 41.5536003112793, 20.562210083007812 41.40386962890625, 20.493320465087891 41.327480316162109, 20.597490310668945 4
Moldova                                                                                                                                                                                                                                                         POLYGON ((26.635000228881836 48.240871429443359, 26.7077693939209 48.253318786621094, 26.894439697265625 48.2047004699707, 27.00054931640625 48.155540466308594, 27.164440155029297 47.967758178710938, 27.238330841064453 47.785259246826172, 27.28944015502929
Monaco                                                                                                                                                                                                                                                          POLYGON ((7.3911871910095215 43.728031158447266, 7.3919000625610352 43.728900909423828, 7.3961000442504883 43.730598449707031, 7.4008002281188965 43.731399536132812, 7.406099796295166 43.731399536132812, 7.4107999801635742 43.732200622558594, 7.41499996185
Montenegro                                                                                                                                                                                                                                                      POLYGON ((19.069999694824276 43.508598327636719, 19.053899765014705 43.535598754882869, 19.011699676513672 43.556098937988338, 18.9869003295899 43.522201538085994, 18.949399948120117 43.509399414062614, 18.956699371338004 43.454399108886776, 19.02309989929
Netherlands                                                                                                                                                                                                                                                     MULTIPOLYGON (((4.2300119400024414 51.357219696044922, 4.2108330726623535 51.372489929199219, 3.9819440841674805 51.407211303710938, 3.9613890647888184 51.369709014892578, 3.8327779769897461 51.341648101806641, 3.6011109352111816 51.391929626464844, 3.4433
Norway                                                                                                                                                                                                                                                          MULTIPOLYGON (((15.477780342102051 68.877761840820312, 15.573060035705566 68.965812683105469, 15.541939735412598 69.012191772460938, 15.623889923095703 68.98052978515625, 15.863889694213867 69.026092529296875, 16.08860969543457 69.157760620117188, 16.15389
Poland                                                                                                                                                                                                                                                          POLYGON ((19.665630340576172 54.466911315917969, 19.636510848999023 54.4710693359375, 19.624469757080078 54.461490631103516, 19.439210891723633 54.395809173583984, 19.004020690917969 54.342628479003906, 18.721939086914062 54.376380920410156, 18.58527946472
Portugal                                                                                                                                                                                                                                                        MULTIPOLYGON (((-25.385000228881836 37.712211608886719, -25.160560607910156 37.746379852294922, -25.131950378417969 37.805271148681641, -25.142219543457031 37.842769622802734, -25.323329925537109 37.8638801574707, -25.577499389648438 37.82720947265625, -25
Romania                                                                                                                                                                                                                                                         POLYGON ((26.316379547119141 48.186370849609375, 26.272220611572266 48.076099395751953, 26.159160614013672 47.984989166259766, 26.011100769042969 47.979419708251953, 25.468330383300781 47.929710388183594, 25.230270385742188 47.881370544433594, 25.123880386
San Marino                                                                                                                                                                                                                                                      POLYGON ((12.407695770263672 43.913787841796875, 12.408300399780273 43.912200927734375, 12.409999847412109 43.909198760986328, 12.412199974060059 43.906101226806641, 12.416399955749512 43.904701232910156, 12.421699523925781 43.905300140380859, 12.425600051
Slovakia                                                                                                                                                                                                                                                        POLYGON ((16.944860458374023 48.616500854492188, 16.896390914916992 48.487209320068359, 16.856109619140625 48.419151306152344, 16.840829849243164 48.36859130859375, 16.94972038269043 48.278041839599609, 16.976680755615234 48.174179077148438, 17.06809997558
Slovenia                                                                                                                                                                                                                                                        POLYGON ((16.026939392089844 46.661369323730469, 15.649439811706543 46.709709167480469, 15.500829696655273 46.618038177490234, 15.105270385742188 46.657199859619141, 14.870550155639648 46.615821838378906, 14.814720153808594 46.512760162353516, 14.594160079
Spain                                                                                                                                                                                                                                                           MULTIPOLYGON (((-14.333060264587402 28.0444393157959, -14.140279769897461 28.183610916137695, -13.95028018951416 28.224720001220703, -13.844169616699219 28.402219772338867, -13.855830192565918 28.478609085083008, -13.820560455322266 28.577220916748047, -13
Svalbard                                                                                                                                                                                                                                                        MULTIPOLYGON (((25.030000686645508 76.43914794921875, 25.582220077514648 76.706649780273438, 25.515270233154297 76.710533142089844, 25.413890838623047 76.68414306640625, 25.065280914306641 76.530532836914062, 24.941389083862305 76.443862915039062, 25.03000
Sweden                                                                                                                                                                                                                                                          MULTIPOLYGON (((11.465000152587891 58.06610107421875, 11.806389808654785 58.120540618896484, 11.814720153808594 58.177490234375, 11.736669540405273 58.281650543212891, 11.671640396118164 58.276210784912109, 11.655280113220215 58.231380462646484, 11.5761098
Switzerland                                                                                                                                                                                                                                                     POLYGON ((9.540410041809082 47.266975402832031, 9.6052761077880859 47.359989166259766, 9.6649990081787109 47.381370544433594, 9.6536102294921875 47.455539703369141, 9.55825424194336 47.504070281982422, 9.5676116943359375 47.543918609619141, 9.2616653442382
Ukraine                                                                                                                                                                                                                                                         POLYGON ((23.592084884643555 51.528278350830078, 23.671379089355469 51.431659698486328, 23.632219314575195 51.307758331298828, 23.749439239501953 51.207489013671875, 23.973049163818359 50.944149017333984, 24.144710540771484 50.858039855957031, 24.130550384
United Kingdom                                                                                                                                                                                                                                                  MULTIPOLYGON (((-6.2649998664855957 56.258880615234375, -5.8602781295776367 56.3519401550293, -5.8405561447143555 56.308879852294922, -5.70222282409668 56.359149932861328, -5.703333854675293 56.375541687011719, -5.7872228622436523 56.367771148681641, -5.66
Yugoslavia                                                                                                                                                                                                                                                      POLYGON ((20.072723388671989 42.558441162109375, 20.168600082397575 42.506938934326172, 20.252220153808707 42.324428558349666, 20.35165977478033 42.324428558349666, 20.526100158691406 42.211650848388729, 20.620830535888729 41.949710845947266, 20.5896472930

 

And i'm tryng to expose via WMS Service ...

public void ProcessRequest (HttpContext context)

    {
         
        string url = (context.Request.Url.Query.Length > 0 ?
           context.Request.Url.AbsoluteUri.Replace(context.Request.Url.Query, "") : context.Request.Url.AbsoluteUri);
        
        SharpMap.Web.Wms.Capabilities.WmsServiceDescription description =
            new SharpMap.Web.Wms.Capabilities.WmsServiceDescription("Map Server", url);

        description.Abstract = "Map Server maintained by xxx";
        description.Keywords = new string[3];
        description.Keywords[0] = "Word Map";
       
        description.MaxWidth = 1500; //Set image request size width
        description.MaxHeight = 1500; //Set image request size height

        SharpMap.Map myMap = new SharpMap.Map();       

        myMap.Layers.Add(KT.Map.GIS.LayersHelper.BuildWorldLayer());
                        
        SharpMap.Web.Wms.WmsServer.ParseQueryString(myMap, description);        
    }

 

It works perfectly if i didn't add transformations inside the "Build World Layer" layer factory...

 

Here is the code of BuildWorldLayer()

        /// <summary>
        /// Returns the Base Layer Map of the world taken from DB
        /// </summary>
        /// <returns></returns>
        public static VectorLayer BuildWorldLayer()
        {
            SharpMap.Layers.VectorLayer worldLayer = new SharpMap.Layers.VectorLayer("world");
            SharpMap.Data.Providers.SqlServer2008 sql2008
                = new SharpMap.Data.Providers.SqlServer2008(KTMapConfiguration.MapDbConnectionString, "dbo.Europe", "geom", "oid");

            
            worldLayer.DataSource = sql2008;
            //worldLayer.MaxVisible = 400;
            //worldLayer.MinVisible = 0;
            worldLayer.SRID = 4326;

            //worldLayer.CoordinateTransformation = wgs84toGoogle();

            worldLayer.Theme = new SharpMap.Rendering.Thematics.CustomTheme(getCountryStyle);

            return worldLayer;
        }

 

When i comment the transformation all works correctly..  but when i use the transformation:

 

        public static ICoordinateTransformation wgs84toGoogle()
        {            
            CoordinateSystemFactory csFac = new CoordinateSystemFactory();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

            IGeographicCoordinateSystem wgs84 = csFac.CreateGeographicCoordinateSystem(
              "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
              new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East));

            ICoordinateSystem csWM = new CoordinateSystemFactory().CreateFromWkt(
                @"PROJCS[""Mercator Spheric"", GEOGCS[""WGS84basedSpheric_GCS"",
                DATUM[""WGS84basedSpheric_Datum"", 
                SPHEROID[""WGS84based_Sphere"", 6378137, 0], 
                TOWGS84[0, 0, 0, 0, 0, 0, 0]], 
                PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"", ""8901""]],
                UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9102""]], 
                AXIS[""E"", EAST], 
                AXIS[""N"", NORTH]], 
                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]]");

            ICoordinateTransformation ct =
             new CoordinateTransformationFactory().CreateFromCoordinateSystems(wgs84, csWM);

            return ct;
	}

It doesn't work... it seems that the transformation doesn't work...  but i'm using the patched version of the PROJ.NET ConcatenatedTransform 

from http://projnet.codeplex.com/WorkItem/View.aspx?WorkItemId=9090

 

 

 

 

This is just to clarify better my actual context...    

 

Then i try to get a map around this box:  "-54.51703125,3.53985937500001 77.31890625,95.825015625"

But after i make the Transformation of this box  ( inside  public override void Render(Graphics g, Map map)  of the Vector Layer i've added.....)

the envelope become: "-0.000489734824166966,3.20134077107358E-05 0.000694567552357794,0.000866612192650383"

 

Then when it execute the intersection query for the data...

Collection<Geometry> geoms = DataSource.GetGeometriesInView(envelope);

no data is obtained...    so i've still issue on the transformation of the coordinate of the envelop....   

And...  no data is obtained from DB...  so..   which is the error?

The original BOX dimension must be set in METERS? or id DEGREES?

Thanks

alberto

 

 

Coordinator
Mar 29, 2010 at 11:29 AM

Alberto,

your BoundingBox for ZoomToBox must be in Mercator Spheric coordinate system.

If you only have the WGS84 BoundingBox then use SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformBox(,) to do that.

Hth FObermaier

 

Mar 29, 2010 at 1:05 PM

OK!    So,  with a Windows Form.

Using the Proj.NET Patch it is running!       

Using Open Layer and using Sharp Map as WMS Server i didn't found a confiugration @ the moment that is running....    but i'll investigate more!

So, first of all thanks to Fobermaier and all the other guys that gives supports on this forum!    

Very very very very good job!

 

Alberto.