Overlay shp file or shp file in database over Google Maps

Topics: Data Access, General Topics, SharpMap v2.0
May 11, 2011 at 4:03 PM

Can anyone point me to an example of doing this?

I found the following:

private static Map InitializeMapGoogle(GoogleMapType mt)
    Map map = new Map();

    GoogleRequest req;
    ITileSource tileSource;
    TileLayer tileLayer;
    if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels))
        req = new GoogleRequest(GoogleMapType.GoogleSatellite);
        tileSource = new GoogleTileSource(req);
        tileLayer = new TileLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite);
        req = new GoogleRequest(GoogleMapType.GoogleLabels);
        tileSource = new GoogleTileSource(req);
        mt = GoogleMapType.GoogleLabels;
        req = new GoogleRequest(mt);
        tileSource = new GoogleTileSource(req);

    tileLayer = new TileLayer(tileSource, "TileLayer - " + mt);
    return map;
However, GoogleRequest, ITileSource, and GoogleMapType aren't defined anywhere.  Am I missing an using?
May 11, 2011 at 4:05 PM
Edited May 11, 2011 at 4:18 PM

Nevermind, I forgot to reference the BruTile.dll.

Now I have a few questions.  I am calling InitializeMapGoogle(Google.MapType.GoogleSatellite) but the if statement check is failing every time?  Also, if I exclude the if/else statement and just run the condition in the if statement as is, I get a remote server returned an error(404) file  not found.  What file is it trying to load?

May 11, 2011 at 6:50 PM

So far I have been able to get Bing maps to load just fine; however, I have yet been able to accomplish this using Google Maps.

Also, how would one go about determining the project used in the shape file and doing the appropriate conversion to the Mercator projection that Google and Bing maps use?

May 11, 2011 at 7:02 PM

if bing works, then also google should work. try with GoogleRoads and see if works.

May 11, 2011 at 7:21 PM

Interesting, using Google.MapType.GoogleMap works, but if I use satellite it fails.

Any pointers on finding the projection used in the shape file?

May 11, 2011 at 7:55 PM

I was able to figure it out.  For those of you looking to do the same, it is rather simple.

You actually don't need to know the projection of the shape file, but merely the projection you are wanting to move to.  Once you have that it is as simple as calling the CoordinateTransformation on the layer.

Here is an example converting to Google Maps or Bing Maps Mercator projection:

            var ctf = new CoordinateTransformationFactory();
            var epsg3785 = new CoordinateSystemFactory().CreateFromWkt(
                "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], " +

            layer.CoordinateTransformation = ctf.CreateFromCoordinateSystems(shp.CoordinateSystem, epsg3785);



            map.Size = pictureBox1.Size;
            pictureBox1.Image = map.GetMap();

Where shp is merely the shapefile.

Now I move on to trying to do the same from the sql server, which should follow the same principle if what I have looked into so far proves to be accurate.

May 11, 2011 at 8:15 PM
Edited May 11, 2011 at 8:17 PM

Okay, question trying to load it from the database.  I have access to CoordinateSystem property of a shapefile; however, there is not such property when using a SQLServer2008 data provider.  Any idea how to retrieve the coordinate system from the SQLServer2008 data provider?  I'm reading the shape file I previously loaded, but this time I am trying to do so from the database.

I assume this is contained within the SRID?  How would I conver that to the appropriate CoordinateSystem?

May 12, 2011 at 6:34 AM

>Any idea how to retrieve the coordinate system from the SQLServer2008 data provider?

as far as I know, you most know the SRID of your data and set the SRID property of the dataprovider correctly.

I suggest you to load your shapefile to sql server with this tool: http://www.sharpgis.net/page/SQL-Server-2008-Spatial-Tools.aspx

and set srid property (using the correct srid instead of "0" improves spatial index, as a result of my experience).

May 12, 2011 at 3:32 PM
Edited May 12, 2011 at 3:36 PM

Okay, I think I have stumbled more towards the right direction.

I already have the shapefile being saved into the database using SharpMap.  However, I really had no idea how to get the SRID from the shape file.

What I found out that I could do was create another table with a reference to the saved shape file table name and add a wkt field to that.  I can pull the shapefile.CoordinateSystem.WKT from that.   I merely called a .ToString() and saved it into the database as a varchar(max).

Now when I load the shp file from the SQLServer2008DataSource, I can also pull that wkt field from the appropriate table.  I can then use the:


to create the Coordinate System that the shp file was using.  I can then call a:

  layer.CoordinateTransformation = ctf.CreateFromCoordinateSystems(proj, epsg3785);

in order to apply the mercator projection to the layer that loaded that shape file from the SQLServer2008DataSource. 

So, if anyone else runs into any similar issues here is a solution for you.