This project has moved. For the latest updates, please go here.

Where is SpatialRefSys.xml ?

Topics: SharpMap v0.9 / v1.x
Mar 7, 2014 at 4:34 PM

I'm trying to use this method
var wkt = SharpMap.Converters.WellKnownText.SpatialReference.SridToWkt(map.SRID);
to obtain the WKT from a SRID, but it does not work, it tries internally to load the file SpatialRefSys.xml, that is not present anywhere.

Mar 10, 2014 at 8:10 AM
Edited Mar 10, 2014 at 9:18 AM
I must admit that I was not aware of this method. There [used to be|still] is an SRID.csv that was once used with Proj.Net to get WKT definitions for srid keys, but that [was not used|is not used] anywhere throughout the code.

If you have PostGIS or SpatiaLite at hand it should be fairly easy to build such a file. I'll give it a shot asap.
select t.xml from
(select '<?xml version="1.0" encoding="utf-8" ?>' as "xml", 0 as auth_srid
union select '<SpatialReference>', 1 as auth_srid
union select '  <ReferenceSystem><SRID>' || "auth_srid" || '</SRID>' || trim("srtext") || E'</ReferenceSystem>' , "auth_srid" from spatial_ref_sys
union select '</SpatialReference>', 999999 as auth_srid order by auth_srid) t;
Note: You need to replace &#39; with '
After that you may need to mofify one or the other wkt definition to remove a sole '&'.
Mar 10, 2014 at 11:11 AM
By looking at SharpMap code, I found out this interesting section inside the GdalRasterLayer.ReprojectToMap:
using (var p = new OSGeo.OSR.SpatialReference(null))
                    string wkt;
                    p.ExportToWkt(out wkt);
// [...]
I wonder whether I could use this for all conversions rather than going through your mentioned methods, at least it is free, and the list is official from OSGeo.

Maybe you should change the implementation of the not-working method.

Mar 10, 2014 at 11:59 AM
For your convenience I added the SpatialRefSys.xml to the repository.

Relying on OSGeo.OSR.SpatialReference would impose a dependency on GDAL for the whole SharpMap project. We don't want that.