Georeferencing GdalRasterLayer

Topics: Data Access, General Topics, WinForms Controls
Mar 25, 2010 at 12:31 PM

Hello! I would like to ask you some help in loading GdalRasterLayer. I cannot figure out how to make a georeferencing on it. When I load it to a map together with vector layers, all coordinates are in mess, some vector layers dissapear, others group in one point. I understand that somewhere there should be some comands to input at least the corner coordinates of this raster layer, and I guess the projection, but where? Thanks to all in advance!!

Coordinator
Mar 25, 2010 at 9:17 PM

Hello kathilario,

I'm afraid I cdon't quite understand your issue. The GdalRasterLayer does not reproject to another spatial reference system. If you have vector data you want to accompany with your raster data, you need to set apropriate transforms for them. If you want your raster data in another spatial reference system, you need to do that beforehand with the native gdal tool (I think it is gdal_warp). Can you provide some more information about your raster and vector sources?

Hth FObermaier

Mar 26, 2010 at 10:36 AM

Hi, Fobermaier! Thank you for the answer. As I am a complete newbie, I also quite dont understand what I need :) I need to display a map of a small piece of land with some objects on it. The map itself is a tiff file, and that objects are on vector layers. So when I display them all together they dont appear where have to, but all in mess. I guess it is because my tiff file does not have any georeferenced info. I have it separately in 2 files with extensions .prj, .tfw, but I dont know what to do with them for SharpMap to understand which coordinates my tiff map has.

Coordinator
Mar 26, 2010 at 3:20 PM

You'll have to set up CoordinateTransformation for your vector data. the target cs is the one of the geotiff, which you can set up by passing the content of its prj file to the CoordinateSystemFactory.CreateFromWkt(...) function.

I don't know what kind of spatial reference system your vector data has, you can evaluate that by a possibly set SRID, CoordinateSystem property for the DataSource.

Hth FObermaier

Apr 3, 2010 at 12:25 PM

Dear FObermaier! Thank you again very much. I still could not figure out what to do, so I will just show you what I have and do, and may be you can give me an example how to apply it. Thank you very much in advance!!

So, I have two files, that go with my tiff. One has an extension prj and contains next:

PROJCS["KKJ / Finland Uniform Coordinate System", GEOGCS["KKJ", DATUM["Kartastokoordinaattijarjestelma (1966)", SPHEROID["International 1924", 6378388.0, 297.0, AUTHORITY["EPSG","7022"]], TOWGS84[-96.062, -82.428, -121.753, 4.801, -0.345, 1.376, 0.30857215014565614], AUTHORITY["EPSG","6123"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4123"]], PROJECTION["Transverse Mercator", AUTHORITY["EPSG","9807"]], PARAMETER["central_meridian", 27.0], PARAMETER["latitude_of_origin", 0.0], PARAMETER["scale_factor", 1.0], PARAMETER["false_easting", 3500000.0], PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","2393"]]

 

Second has an extension tfw and contains next:

 

0.11539138
0
0
-0.11546046 
3526042.86
6970146.069

0.11539138

0

0

-0.11546046 

3526042.86

6970146.069

 

I have these two files in the same folder as the tiff. In my program I write next to show the raster layer on the map:

SharpMap.Map SomeMap;

SharpMap.Layers.GdalRasterLayer MapLayer = new SharpMap.Layers.GdalRasterLayer(DATA_NAME_C, @"..\\..\\data\\map_v2.tif");

SharpMap.Layers.VectorLayer CloudLayer = new SharpMap.Layers.VectorLayer("CloudLayer");

List<SharpMap.Geometries.Geometry> Cloud = new List<SharpMap.Geometries.Geometry>();

SomeMap = new SharpMap.Map(new Size(picMap.Size.Width, picMap.Size.Height));

LoadingCloud();//here I populate vector layer CloudLayer

SomeMap.Layers.Add(MapLayer);

SomeMap.Layers.Add(CloudLayer); 

SomeMap.ZoomToExtents();

picMap.Image = SomeMap.GetMap();

 

After this as you can imagine everything is out of order on the map. I am a real dummy :), I cannot figure out what means to set up a SC for my tiff. Thanks again in advance!

 

Coordinator
Apr 6, 2010 at 8:05 AM

Hello kathilario,

from what I understood so far is that your vector data does not match/fit your geotiff.

If that is true, you don't have to do anything to do with your geotiffs, "all" you have to do is to set up a coordinate transformation to get your vector data in the same coordinate system. Therefore you need to know the spatial reference system of your vectordata. Once you know that follow the outlined path in the coordinate transformation howto (see link above)

Hth FObermaier

Apr 6, 2010 at 3:55 PM

Hi, FObermaier! Thank you for the answer! How can I discover which is the coordinate system I am using? I get points for my vector layaers from a database and have only coordinates.

Apr 6, 2010 at 4:08 PM

I tryed to perform the transformation you indicated with my vector layers, but got an exception "Only 2 dimensions are supported for points". What to do?

 

Coordinator
Apr 6, 2010 at 4:49 PM

remove the sanity check or change it (see: http://sharpmap.codeplex.com/Thread/View.aspx?ThreadId=206893)

Hth FObermaier

Apr 6, 2010 at 5:24 PM

And if I just add points to the layer manually, like SharpMap.Geometries.Point Pos = new SharpMap.Geometries.Point(10, 10), how can I perform a transformation from one projection to another, if I do not know even which projection I am using? I found out on SharpMap site, that the default projection is Pseudo Plate Carré. So I assumed that adding points this way to the layers I should get the layers projection as Pseudo Plate Carré. Therefore I tryed to perform next transformation:

CoordinateSystemFactory csFac = new CoordinateSystemFactory();

ICoordinateSystem targetCS = csFac.CreateFromWkt("PROJCS[\"KKJ / Finland Uniform Coordinate System\", GEOGCS[\"KKJ\", DATUM[\"Kartastokoordinaattijarjestelma (1966)\", SPHEROID[\"International 1924\", 6378388.0, 297.0, AUTHORITY[\"EPSG\",\"7022\"]], TOWGS84[-96.062, -82.428, -121.753, 4.801, -0.345, 1.376, 0.30857215014565614], AUTHORITY[\"EPSG\",\"6123\"]], PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\", 0.017453292519943295], AXIS[\"Geodetic longitude\", EAST], AXIS[\"Geodetic latitude\", NORTH], AUTHORITY[\"EPSG\",\"4123\"]], PROJECTION[\"Transverse Mercator\"], PARAMETER[\"central_meridian\", 27.0], PARAMETER[\"latitude_of_origin\", 0.0], PARAMETER[\"scale_factor\", 1.0], PARAMETER[\"false_easting\", 3500000.0], PARAMETER[\"false_northing\", 0.0], UNIT[\"m\", 1.0], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH], AUTHORITY[\"EPSG\",\"2393\"]]");

ICoordinateSystem sourceCS = csFac.CreateFromWkt("PROJCS[\"Sphere_Plate_Carree\",GEOGCS[\"GCS_Sphere\",DATUM[\"D_Sphere\",SPHEROID[\"Sphere\",6371000,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Plate_Carree\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",0],UNIT[\"Meter\",1]]");

CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

ICoordinateTransformation transform = ctFac.CreateFromCoordinateSystems(sourceCS, targetCS);

CloudLayer.CoordinateTransformation = transform;

But this does not work, gives an exception "Projection Plate_Carree is not supported".

Coordinator
Apr 7, 2010 at 7:31 AM

That sharpmap uses Pseudo Plate Carré projection by default is like saying it does not change/transform the input coordinates in any way.

If you want/need to apply coordinate transformation, you have to find out what the spatial reference system of your vectordata is. Perhaps there is some SRID (spatial reference id) property. What kind of datasource do you have? What kind of spatial reference systems are common where you are? Do the coordinates fit to one of those?

If you really have no way to find out the spatial reference system, there is a LeastSquaresTransform class that can compute the parameters of an affine transformation matrix (see http://sharpmap.codeplex.com/Thread/View.aspx?ThreadId=206980). Note: There are a few bugs in this class.

Hth FObermaier