This project has moved and is read-only. For the latest updates, please go here.

Blank image after coordinate transformation

Topics: SharpMap v2.0, Web Controls
Oct 28, 2010 at 2:01 PM
Edited Oct 28, 2010 at 2:04 PM


I'm trying to get a shapefile (countries.shp) to transform to Google Mercator for use with Google Maps.

I'm loading the WKT from the shape file and using it as my source coordinate system and using the following WKT for google mercator 1SP:

PROJCS["WGS84 / Google Mercator", GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Longitude", EAST], AXIS["Latitude", NORTH], AUTHORITY["EPSG","4326"]], PROJECTION["Mercator_1SP"], PARAMETER["semi_minor", 6378137.0], PARAMETER["latitude_of_origin", 0.0], PARAMETER["central_meridian", 0.0], PARAMETER["scale_factor", 1.0], PARAMETER["false_easting", 0.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["x", EAST], AXIS["y", NORTH], AUTHORITY["EPSG","900913"]]

The shapefile's WKT is:


I'm using the AsyncMapHandlerBase  in SharpMap.Presentation.AspNet.Handlers as my base class for the generic handler.

If I don't do the transform the image displays fine, but when I do the transform the image rendered out is blank.

The code I'm using is below:


public class getTile : AsyncMapHandlerBase {

    public override void LoadLayers()
        GeometryServices geometryServices = new GeometryServices();

        ShapeFileProvider shapeFile = new ShapeFileProvider(Context.Server.MapPath("~/userdata/kqydhhBHD1/countries.shp"),
            geometryServices.DefaultGeometryFactory, geometryServices.CoordinateSystemFactory, false);
                //try to read the projection information from the prj file.
        System.IO.StreamReader sr = new System.IO.StreamReader(Context.Server.MapPath("~/userdata/kqydhhBHD1/countries.prj"));
        string fileWKT = sr.ReadLine();

        ICoordinateSystem srs = geometryServices.CoordinateSystemFactory.CreateFromWkt(fileWKT);
        ICoordinateSystem wgs84 = geometryServices.CoordinateSystemFactory.CreateFromWkt(System.Configuration.ConfigurationManager.AppSettings["GoogleMercator"]);
        ICoordinateTransformation ics = geometryServices.CoordinateTransformationFactory.CreateFromCoordinateSystems(srs, wgs84);
        shapeFile.CoordinateTransformation = ics;

        AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider(shapeFile);

        GeometryLayer layer = new GeometryLayer("Shape", provider);

    protected override IWebMapRenderer CreateMapRenderer()
        return new GdiImageRenderer();

    protected override IMapRequestConfigFactory CreateConfigFactory()
        return new BasicMapRequestConfigFactory();

    protected override IMapCacheProvider CreateCacheProvider()
        return new NoCacheProvider();


Is this transformation not supported? Am I missing something?
Oct 28, 2010 at 2:26 PM

Hello LithiumIon,

without knowing what the problem is, i strongly suggest you transform your shapefile beforehand using FWTools or GDAL/OGR library.

This is because on-the-fly coordinate transformation is expensive and -especially with Lat/Long to Google Mercator- I have experienced issues using ProjNet.

Hth FObermaier

Oct 28, 2010 at 2:39 PM

Unfortunately because the project will be hosted in a shared hosting environment, I don't have the luxury of running FWTools or any other command line utility to apply the transformation beforehand.

That's why I opted to do on the fly transformation. Unless I missed something and I can use a library to do the transform ahead of time.

Any suggestions?

Oct 28, 2010 at 2:45 PM
Edited Oct 28, 2010 at 2:46 PM

Why can't you transform the countries.shp file on your local machine and upload the transformed shapefile to the server? I think you even can do that with Quantum GIS (

Oct 28, 2010 at 3:10 PM

Because I want to be able to upload a SHP file to the web application and have it transform the file automatically, or have sharpmap transform the file on the fly.

I don't think my users are savvy enough to know how to use the tools, so i would prefer to have it automated in some way if I can.

I'm looking at Quantum GIS, but it looks like a standalone application, so I'm not sure it would work for what I'm trying to accomplish.

Oct 28, 2010 at 4:45 PM

In that case QGis is not an option. I will have a look.

Oct 28, 2010 at 4:50 PM

Thank you!

Oct 29, 2010 at 11:22 AM

Is it possible that you query the map for [-180, -90, 180, 90] and with CoordinateTransfromation it should be a lot larger (don't know the extents for google mercator)?

Oct 29, 2010 at 2:37 PM

I'm not setting the extents, so I would assume it should figure it out automatically. Shouldn't it?

Nov 8, 2010 at 5:33 PM

Is it possible I could use NetTopologySuite to read the shp files, do the transform, and update the shp file, then use sharpmap to output the map?

Or would I have to use OGR or some other library?

Nov 9, 2010 at 12:30 PM

Hello LithiumIon, I got it to work, but the result is not very accurate. ATM I'm looking for the error in the transformation process or an alternative.

Btw, do you use the trunk version or some branch?

cheers FObermaier

Nov 9, 2010 at 2:50 PM

I appreciate the help.

I'm using the trunk

Jan 13, 2011 at 7:39 PM

How did you get it to work?? I am also doing coordinate transformation and in the result I am getting blank screen!!!

Code I am using:
PostGIS pg = new PostGIS(frmDataBase.GetConnectionString(),"table""geom""gid");
SharpMap.Layers.VectorLayer  vlay= new VectorLayer("name", pg);
ICoordinateSystem epg3059 = SridReader.GetCSbyID(3059);
ICoordinateSystem epg3785 = SridReader.GetCSbyID(4236);
CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
ICoordinateTransformation transform = ctFac.CreateFromCoordinateSystems(epg3059, epg3785);
vlay.CoordinateTransformation = transform;;


May 31, 2011 at 11:03 AM

I have the same problem. I need to use on-the-fly tranformation (it's a school project) and i wasn't able to find a solution. Does anyone know how to fix this?

May 31, 2011 at 11:57 AM

If you go by the code above, it is lacking a call to map.ZoomToExtents().

If you are calling some sort of map.ZoomXXX function to ensure at least part of the map is visible, check your data providers extents (IProvider.GetExtents())

Hth FObermaier

May 31, 2011 at 5:36 PM

Thank you! That did it.