SharpGIS | Applying on-the-fly transformation in SharpMap

I have received a lot of questions on how to transform data from one coordinatesystem to another on the fly in SharpMap. Usually the problem is that they have data in different coordinatesystems and want to match them. Although I would recommend applying transformations once-and-for-all to increase performance (you could use OGR for this), it is easy to setup in SharpMap. Below are some examples on how to accomplish this. SharpMap gives you the full power to specify all the parameters in a projection. The following method demonstrates how to setup a UTM projection: If you have a well-known text-representation, you can also create a projection from this. A WKT for an UTM projection might look like this: PROJCS['WGS 84 / UTM zone 32N',GEOGCS['WGS 84',DATUM['WGS_1984',SPHEROID['WGS 84',6378137,298.257223563,AUTHORITY['EPSG','7030']],AUTHORITY['EPSG','6326']],PRIMEM['Greenwich',0,AUTHORITY['EPSG','8901']],UNIT['degree',0.01745329251994328,AUTHORITY['EPSG','9122']],AUTHORITY['EPSG','4326']],PROJECTION['Transverse_Mercator'],PARAMETER['latitude_of_origin',0],PARAMETER['central_meridian',9],PARAMETER['scale_factor',0.9996],PARAMETER['false_easting',500000],PARAMETER['false_northing',0],UNIT['metre',1,AUTHORITY['EPSG','9001']],AUTHORITY['EPSG','32632']] SharpMap comes with WKT parsers for parsing a WKT to a coordinate system (note: the current v0.9RC1 has a few bug in its WKT parser, but if you get problems parsing the WKT, use the current source from the repository, where these issues have been resolved) If your data is based on shapefile data and they have a .prj file defining the coordinatesystem, you can simply retrieve the CS from the shapefile instead: The next step is to create a transformation between two coordinate systems. SharpMap currently supports transforming between a geographic coordinate system and one of the following projections: Unfortunately datum-shifts and transformations between two projections are still down the pipeline, but the above will be sufficient in most cases. (for those interested full transformation between all supported projections as well as datum-shifts are almost done...) The following shows how to create a transformation and apply it to a vectorlayer (only vector- and label-layers supports on-the-fly transformations): Isn't there a problem? //Apply transformation to a vectorlayer (myMap.Layers[0] as VectorLayer).DataSource = transform, It doesn't want to apply a ICoordinateTransformation to a Datasource. We can make that : (myMap.Layers[0] as VectorLayer).CoordinateTransformation = transform but it's only transforming the envellope and not the geometry inside. Source.

Яндекс.Метрика Рейтинг Free Web Counter
page counter
Last Modified: April 22, 2016 @ 6:06 pm