Projections and Transformations

Topics: Algorithms, SharpMap Project, SharpMap v0.9 / v1.x
Jun 20, 2010 at 10:12 AM

Hi,

I have some polygons in SQL Server 2008 database stored as Geometries. Now I would like to create a map with the following specs:

Layer 1 will be a VectorLayer with its DataSource set to a ShapeFile. The PRJ file for this shape file has the following WKT:

PROJCS["Asia_North_Lambert_Conformal_Conic",
   GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",
   SPHEROID["WGS_1984",6378137.0,298.257223563]],
   PRIMEM["Greenwich",0.0],
   UNIT["Degree",0.0174532925199433]],
   PROJECTION["Lambert_Conformal_Conic"],
   PARAMETER["False_Easting",0.0],
   PARAMETER["False_Northing",0.0],
   PARAMETER["Central_Meridian",95.0],
   PARAMETER["Standard_Parallel_1",15.0],
   PARAMETER["Standard_Parallel_2",65.0],
   PARAMETER["Latitude_Of_Origin",30.0],
   UNIT["Meter",1.0]]

Layer 2 will also be a VectorLayer with its DataSource set to GeometryFeatureProvider. For legacy reasons I am not using the SqlServer2008 provider as the data source. The SRID of all the features in this layer would be 4326 (i.e., WGS 84)

Now, the map loads and then I can see the features from the Shape File in the Top Right corner of the screen, and features in the 2nd layer don't even show up. I believe that some kind of reprojection/transformation has to be done for this to work, but I am totally lost on what exactly needs to be done.

Thanks,
Raghu

Coordinator
Jun 20, 2010 at 2:55 PM
Edited Jun 20, 2010 at 6:52 PM

Hello Raghu,

to do on the fly reprojection of your layer, you have to set up coordinate transformation (see this). The steps you need to do are

  • Add reference to GeoAPI.Net and Proj.Net.
  • Get WKT for EPSG:4326 (www.spatial-reference.org) and use CoordinateSystemFactory.CreateFromWKT to parse it (-> CS1).
  • Get Coordinate System from ShapeFile using ((Shapefile)Layer1.DataSource).CoordinateSystem (->CS2)
  • Use CoordinateTransformationFactory to set up CoordinateTransformation.CreateFromCoordinateSystems(CS1, CS2) (-> CT)
  • Apply CT to your ((VectorLayer)Layer2).CoordinateTransformation.

Hth FObermaier