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

CoordinateSystems WKT SpatialRefSys.xml

Topics: SharpMap v0.9 / v1.x
Oct 19, 2010 at 8:04 AM


I am new to SharpMap.  I have down loaded version 0.9-Trunk-2009.10.22 and have been playing around mixing up the various demo's and successfully compiling them.

I now wish to introduce "on the fly reprojection".  The concept looks fairly straight forward but a couple of trivial issues are tripping me up.

1/    Raster Layers can't be reprojected on the fly so I wish to identify if a layer is raster or vector before I try reprojecting it.  'If I have a layer already loaded in a map control, how can I determine if it has a raster or vector data source?'

2/   Sometimes the WKT associated in a shapefiles prj file contains the correct parameter info but the coordinate system or datum name may not quite agree with the appropriate text in the SRID.csv file. So I am thinking of writting a get projection dialog form which will try best match and suggest a coordinate system from the SRID.csv file.  I don't wish to reinvent any wheels.  So before I do this I would like to know - 'Has anyone has already done something similar to handle syntax differences between SRID.csv and prj files?'

3/   I also wish to be able to generate Coordinate system WKT from srid's.  The file SpatialReference.cs contains the method SridToWkt(int srid) which references the file 'SpatialRefSys.xml'.  I can't locate this xml file.  Where can I get it from?

Any help appreciated ... Cheers

Oct 19, 2010 at 11:25 AM

Hello PunchCard.

Please do not use the binaries provided via download tab, please compile sharpmap yourself using the latest commit.

1.) As you noticed, on the fly reprojection only works for VectorLayer. Therefore you can test

if (!(map.Layers[i] is VectorLayer))


2.) What is wrong with taking the wkt from the prj file?

3.) where do you have spatialreference.cs from?

Hth FObermaier


Oct 20, 2010 at 8:24 AM

Hi FObermaier,

Thankyou for the quick response!

I down loaded version 0.9-Trunk-2009.10.22 for the binaries and change set for the source.  I will try change set

I have recompiled for Sharpmap specific binaries, but I have assumed the External Reference binaries don't need recompiling......Is this correct?

1/   Just what I needed

2/   I wish to write an application where the display coordinate system is configurable and layers are reprojected to suite.  Similar to the GlobalMapper Application ( only rasters with a different srid's will be turned off for now. 

 I can create coordinate system's and transforms using the prj's WKT, but I want a quick way of comparing coordinate systems. To achieve this, I intend to use the SRID value to check if a layer needs to reprojected or not.  When I load the example datafile SharpMap\WinFormSamples\GeoData\World\countries.prj as a Map layer its Datum and Projection parameters are correct but the SRID value equals -1 when I was hoping for 4326.  I am guessing it's value is -1 because of syntax differences between the SRID.csv and .prj file, ie  record 4326 in SRID.csv WKT contains "WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"  whereas the prj file contains  "GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984"

Hence why I was going to try best match and prompt the user to confirm.  Or is there a better approach?

3/  In Change set zip under the directory Trunk\SharpMap\Converters\WellKnownText.  I want this functionallity because some files will require the user to manually provide projection information.

Since some people outside the Spatial industry find datums and projections confusing I wish to keep it simple.  So I was just going to provide them with a list box with preset coordinate systems (linked to SRIDs), in these instances I wish to generate prj files based on the user input (SRID really).


Oct 20, 2010 at 9:13 AM

Hello PunchCard,

You do not need to recompile the ExternalReference binaries, but please do not use the ones provided via the download tab, but the ones in the repository.

2.) Providers SRID property is only set internally when used with db-based providers. For ShapeFile you have to set it yourself. You may succed setting up a CoordinateSystem by the use of Proj.Net and get the SRID int value from there. I think Proj.Net CoordinateSystems implement IEquatable<T> so you might be able to check for equality using that.

3.) I cannot say anything about SpatialReference.cs, there is an SRID.csv reader class in Proj.Net. that takes the SRID.csv and gets the CoordinateSystem specification from there. You may need to get yourself a copy of Proj.Net and compile it yourself, because some "vital" classes are internal, so you cannot access them using the default Proj.Net assembly.

Hth FObermaier