Custom projection

Topics: General Topics
Oct 15, 2009 at 1:47 PM

Hi,

I'm from Croatia and we are using Bessel elipsoid that is not in Proj4 or SpatialReferenceSystem.

How can I define custom projection? I have parameters for proj4 but i don't know how implement in sharpmap

 

Thanks

Coordinator
Oct 15, 2009 at 2:55 PM

Hi Frane, could you post the projection parameters for proj4?

cheers

FObermaier

Oct 15, 2009 at 9:31 PM

+proj=tmerc +lat_0=0 +lon_0=15 +k=0.9999 +x_0=5500000 +y_0=0 +ellps=bessel +towgs84=550.499,164.116,475.142,5.80967,2.07902,-11.62386,0.99999445824 +units=m +no_defs

Coordinator
Oct 16, 2009 at 10:46 AM
Edited Oct 16, 2009 at 11:04 AM

Hi Frane,

the wkt-representation or your proj4 parameters is (according to Osr):

 

PROJCS["unnamed",
GEOGCS["Bessel 1841",
DATUM["unknown",
SPHEROID["bessel",6377397.155,299.1528128],
TOWGS84[550.499,164.116,475.142,5.80967,2.07902,-11.62386,0.99999445824]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",15],
PARAMETER["scale_factor",0.9999],
PARAMETER["false_easting",5500000],
PARAMETER["false_northing",0],
UNIT["Meter",1]]

 

What you need to do is add this information to your datasources. To do that you need to reference Proj.Net from the external dependencies folder and do something like:

 

using SharpMap.CoordinateSystems;
using SharpMap.CoordinateSystems.Transformations;

...

CoordinateSystemFactory csf = new CoordinateSystemFactory();
CoordinateTransformationFactory ctf = new CoordinateTransformationFactory();

ICoordinateSystem cs = csf.CreateFromWkt(@"PROJCS[""unnamed"", GEOGCS[""Bessel 1841"", DATUM[""unknown"", SPHEROID[""bessel"",6377397.155,299.1528128], TOWGS84[550.499,164.116,475.142,5.80967,2.07902,-11.62386,0.99999445824]], PRIMEM[""Greenwich"",0], UNIT[""degree"",0.0174532925199433]], PROJECTION[""Transverse_Mercator""], PARAMETER[""latitude_of_origin"",0], PARAMETER[""central_meridian"",15], PARAMETER[""scale_factor"",0.9999], PARAMETER[""false_easting"",5500000], PARAMETER[""false_northing"",0], UNIT[""Meter"",1]]");

...
//Datasource
ShapeFile sf = new ShapeFile(filename, true);

...

VectorLayer layer = new VectorLayer("MyLayer", sf);
layer.CoordinateTransformation = ctf.CreateFromCoordinateSystems(sf.CoordinateSystem, cs);

 

You might need to set the CoordinateSystem for the datasource as well

 

sf.CoordinateSystem = csf.CreateFromWkt( ... );

 

but I'm not sure about that.

Depending on the CRS of your datasource you might not be able to do coordinate transformation because it might not be implemented.

Please see Apply on the fly transfromation to a layer.

Hth FObermaier

Oct 16, 2009 at 1:56 PM

Thanks