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

featuredatatable to be reprojected

Topics: SharpMap v0.9 / v1.x
May 18, 2015 at 10:37 AM
Hi all,
I have a featuredatatable I build on fly using a web mercator projection [EPSG:3857], but I have the need to project such featuredatatable to another spatial reference, most cases it would be WGS84.
I know how to reproject a vector layer, but I never ran into a reprojection of a featuredatatable,
So my question is about how to project a featuredatatable.
Thanks a lot in advance
May 21, 2015 at 11:47 AM
There is no built in functionality, sth along the following lines should do:
public static void ReprojectFeatureDataSet(SharpMap.Data.FeatureDataSet fds,
    GeoAPI.CoordinateSystems.ICoordinateSystem target)
    for (var i = 0; i < fds.Tables.Count; i ++)
        var fdt = fds.Tables[i];
        ReprojectFeatureDataTable(fdt, target);

public static void ReprojectFeatureDataTable(SharpMap.Data.FeatureDataTable fdt,
    GeoAPI.CoordinateSystems.ICoordinateSystem target)
    var source = SharpMap.CoordinateSystems.CoordinateSystemExtensions.GetCoordinateSystem(fdt[0].Geometry);

    var ctFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
    var ct = ctFactory.CreateFromCoordinateSystems(source, target);
    var geomFactory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory((int)target.AuthorityCode);

    for (var i = 0; i < fdt.Rows.Count; i++)
        var fdr = fdt[i];
        fdr.Geometry =
                ct.MathTransform, geomFactory);

May 21, 2015 at 2:32 PM
Thanks a lot FObermaier,
it is very helfull, I am goign to implement this immedialtely.