Projection issue

Topics: General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Sep 28, 2015 at 10:58 AM
Hello all,
Is this projection string supported?
Dim cFac As New ProjNet.CoordinateSystems.CoordinateSystemFactory()
Dim wkt As String = "PROJCS[""Monte_Mario_Italy_zone_2"",GEOGCS[""GCS_Monte Mario"",DATUM[""D_Monte_Mario"",SPHEROID[""International_1924"",6378388,297]],PRIMEM[""Greenwich"",0],UNIT[""Degree"",0.017453292519943295]],PROJECTION[""Transverse Mercator""],PARAMETER[""latitude_of_origin"",0],PARAMETER[""central_meridian"",15],PARAMETER[""scale_factor"",0.9996],PARAMETER[""false_easting"",2520000],PARAMETER[""false_northing"",0],UNIT[""Meter"",1]]"
Dim pers As ICoordinateSystem = cFac.CreateFromWkt(wkt)
Dim ctFact As New ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()
LayerCatasto.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(pers, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator)
LayerCatasto.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, pers)
in qgis it is correctly overlay, in sharpmap no.

Image
Coordinator
Sep 28, 2015 at 4:24 PM
Where did you get the projection string from? maybe the parameters are not correct?
Sep 28, 2015 at 4:53 PM
This parameters are in ".prj" file. I exported shape from qgis, and in qgis the overlay work fine.
I imported .shp file in sql server with ogr2ogr and i show geometry in sharpmap from database.
Sep 30, 2015 at 2:05 AM
Edited Sep 30, 2015 at 2:06 AM
You can try something like:


Dim wkt As String = "PROJCS[""Monte_Mario_Italy_zone_2"",GEOGCS[""GCS_Monte Mario"",DATUM[""D_Monte_Mario"",SPHEROID[""International_1924"",6378388,297]],PRIMEM[""Greenwich"",0],UNIT[""Degree"",0.017453292519943295]],PROJECTION[""Transverse Mercator""],PARAMETER[""latitude_of_origin"",0],PARAMETER[""central_meridian"",15],PARAMETER[""scale_factor"",0.9996],PARAMETER[""false_easting"",2520000],PARAMETER[""false_northing"",0],UNIT[""Meter"",1]]"
    Dim t As New ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()
    Dim pcs As GeoAPI.CoordinateSystems.IProjectedCoordinateSystem
    pcs = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt)
    LayerCatasto.CoordinateTransformation = t.CreateFromCoordinateSystems(LayerCatasto_provider.CoordinateSystem, pcs)
    LayerCatasto.ReverseCoordinateTransformation = t.CreateFromCoordinateSystems(pcs, LayerCatasto_provider.CoordinateSystem.)
Oct 1, 2015 at 1:38 PM
Hello Pablo,

Unfortunately it don't work.


I don't understand this:
LayerCatasto_provider.CoordinateSystem
Full code is this:
Dim CW As DbCommand = dbSQL.GetSqlStringCommand("select * from  totgb ")
Dim ds As DataSet = New DataSet()
CW.CommandTimeout = 0
dbSQL.LoadDataSet(CW, ds, "Ric")


Dim fdt As New SharpMap.Data.FeatureDataTable
fdt.Columns.Add(New System.Data.DataColumn("id", System.Type.GetType("System.UInt32")))
fdt.Columns.Add(New System.Data.DataColumn("foglio", System.Type.GetType("System.String")))
fdt.Columns.Add(New System.Data.DataColumn("mappale", System.Type.GetType("System.String")))
fdt.Columns.Add(New System.Data.DataColumn("complessivo", System.Type.GetType("System.String")))


Dim fact As NetTopologySuite.Geometries.GeometryFactory = New NetTopologySuite.Geometries.GeometryFactory()
Dim wktreader As WKTReader = New WKTReader(fact)


        For Each row As DataRow In ds.Tables(0).Rows
            Dim Poligono As NetTopologySuite.Geometries.Geometry = wktreader.Read(row("ogr_geometry").ToString())
            Dim fdr As SharpMap.Data.FeatureDataRow = fdt.NewRow
            fdr.ItemArray = New Object() {row("ogr_fid"), row("foglio"), row("mappale"), (row("foglio") & " | " & row("mappale"))}
            fdr.Geometry = Poligono
            fdr.Geometry.SRID = row("ogr_fid")
            fdt.AddRow(fdr)
        Next


Dim gfp As New SharpMap.Data.Providers.GeometryFeatureProvider(fdt)
LayerCatasto = New SharpMap.Layers.VectorLayer("poligoni", gfp)
Dim cFac As New ProjNet.CoordinateSystems.CoordinateSystemFactory()

Dim wkt As String = "PROJCS[""Monte_Mario_Italy_zone_2"",GEOGCS[""GCS_Monte Mario"",DATUM[""D_Monte_Mario"",SPHEROID[""International_1924"",6378388,297]],PRIMEM[""Greenwich"",0],UNIT[""Degree"",0.017453292519943295]],PROJECTION[""Transverse Mercator""],PARAMETER[""latitude_of_origin"",0],PARAMETER[""central_meridian"",15],PARAMETER[""scale_factor"",0.9996],PARAMETER[""false_easting"",2520000],PARAMETER[""false_northing"",0],UNIT[""Meter"",1]]"

Dim t As New ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()
Dim pcs As GeoAPI.CoordinateSystems.IProjectedCoordinateSystem
pcs = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt)

LayerCatasto.CoordinateTransformation = t.CreateFromCoordinateSystems(pcs, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator)
LayerCatasto.ReverseCoordinateTransformation = t.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, pcs)

MapBox1.Map.Layers.Add(LayerCatasto)
LayerCatasto.IsQueryEnabled = True
could you explain better your way to solve the problem?
Many thanks
Oct 1, 2015 at 4:49 PM
unknow, but Try:




Dim CW As DbCommand = dbSQL.GetSqlStringCommand("select * from totgb ")
    Dim ds As DataSet = New DataSet()
    CW.CommandTimeout = 0
    dbSQL.LoadDataSet(CW, ds, "Ric")
    Dim fdt As New SharpMap.Data.FeatureDataTable
    fdt.Columns.Add(New System.Data.DataColumn("id", System.Type.GetType("System.UInt32")))
    fdt.Columns.Add(New System.Data.DataColumn("foglio", System.Type.GetType("System.String")))
    fdt.Columns.Add(New System.Data.DataColumn("mappale", System.Type.GetType("System.String")))
    fdt.Columns.Add(New System.Data.DataColumn("complessivo", System.Type.GetType("System.String")))
    Dim fact As NetTopologySuite.Geometries.GeometryFactory = New NetTopologySuite.Geometries.GeometryFactory()
    Dim wktreader As WKTReader = New WKTReader(fact)
    For Each row As DataRow In ds.Tables(0).Rows
        Dim Poligono As NetTopologySuite.Geometries.Geometry = wktreader.Read(row("ogr_geometry").ToString())
        Dim fdr As SharpMap.Data.FeatureDataRow = fdt.NewRow
        fdr.ItemArray = New Object() {row("ogr_fid"), row("foglio"), row("mappale"), (row("foglio") & " | " & row("mappale"))}
        fdr.Geometry = Poligono
        fdr.Geometry.SRID = row("ogr_fid")
        fdt.AddRow(fdr)
    Next
    Dim gfp As New SharpMap.Data.Providers.GeometryFeatureProvider(fdt)
    LayerCatasto = New SharpMap.Layers.VectorLayer("poligoni", gfp)
    Dim cFac As New ProjNet.CoordinateSystems.CoordinateSystemFactory()
    Dim wkt As String = "PROJCS[""Monte_Mario_Italy_zone_2"",GEOGCS[""GCS_Monte Mario"",DATUM[""D_Monte_Mario"",SPHEROID[""International_1924"",6378388,297]],PRIMEM[""Greenwich"",0],UNIT[""Degree"",0.017453292519943295]],PROJECTION[""Transverse Mercator""],PARAMETER[""latitude_of_origin"",0],PARAMETER[""central_meridian"",15],PARAMETER[""scale_factor"",0.9996],PARAMETER[""false_easting"",2520000],PARAMETER[""false_northing"",0],UNIT[""Meter"",1]]"
    Dim t As New ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory()
    Dim pcs, ge As GeoAPI.CoordinateSystems.IProjectedCoordinateSystem
    pcs = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt)
    ge = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse("PROJCS[""Popular Visualisation CRS / Mercator"",GEOGCS[""Popular Visualisation CRS"",DATUM[""WGS84"",    SPHEROID[""WGS84"", 6378137.0, 298.257223563, AUTHORITY[""EPSG"",""7059""]],AUTHORITY[""EPSG"",""6055""]],PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"",""8901""]], UNIT[""degree"", 0.0174532925199433, AUTHORITY[""EPSG"", ""9102""]], AXIS[""E"", EAST], AXIS[""N"", NORTH], AUTHORITY[""EPSG"",""4055""]],PROJECTION[""Mercator""],PARAMETER[""semi_minor"",6378137],PARAMETER[""False_Easting"", 0],PARAMETER[""False_Northing"", 0],PARAMETER[""Central_Meridian"", 0],PARAMETER[""Latitude_of_origin"", 0],UNIT[""metre"", 1, AUTHORITY[""EPSG"", ""9001""]],AXIS[""East"", EAST], AXIS[""North"", NORTH],AUTHORITY[""EPSG"",""3785""]]")
    LayerCatasto.CoordinateTransformation = t.CreateFromCoordinateSystems(pcs, ge)
    LayerCatasto.ReverseCoordinateTransformation = t.CreateFromCoordinateSystems(ge, pcs)
    MapBox1.Map.Layers.Add(LayerCatasto)
    LayerCatasto.IsQueryEnabled = True
Coordinator
Oct 2, 2015 at 8:55 AM
Maurizio80 wrote:
This parameters are in ".prj" file. I exported shape from qgis, and in qgis the overlay work fine.
I imported .shp file in sql server with ogr2ogr and i show geometry in sharpmap from database.
If it is displayed correctly within QGIS, why don't you export it changing the projection to EPSG.3857.
That way you can skip the coordinate transformation code.