2017-06-19 678 views
4

我正在使用sharpmap將MSSQL的邊界(幾何圖形)呈現爲PNG圖像。 這一切運作良好,除了國家在平面圖像格式上看起來太「寬」。將EPSG:4326投影轉換爲EPSG:3857 mercator

據我所知,我需要創建轉換到EPSG:3857投影,但我不知道該怎麼做。

這裏是我的代碼

var map = new Map(new Size(request.Width, request.Height)); 
map.BackColor = Color.Transparent; 
var countryGeometry = GeometryFromWKT.Parse(dto.CountryWkt); 

IProvider countryProvider = new GeometryFeatureProvider(countryGeometry); 
var countryLayer = new VectorLayer("country", countryProvider); 
var borderColor = System.Drawing.ColorTranslator.FromHtml("#525252"); 

countryLayer.Style.EnableOutline = true; 
countryLayer.Style.Outline = new Pen(borderColor); 
countryLayer.Style.Fill = Brushes.Transparent; 
//does not work with this 
countryLayer.CoordinateTransformation = new 
       ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(
        ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, 
        ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator); 

map.Layers.Add(countryLayer); 

map.ZoomToBox(new Envelope(dto.Envelope.BottomLeft.Longitude, 
      dto.Envelope.TopRight.Longitude, 
      dto.Envelope.BottomLeft.Latitude, 
      dto.Envelope.TopRight.Latitude 
     )); 

var img = map.GetMap(); 

WKT可以在這裏找到https://pastebin.com/PEbpAdxT

任何幫助表示讚賞。

編輯: 這是我現在得到的圖像爲法國和它的地區「利穆贊」。正如你所看到的,它太「寬」了。 enter image description here

這是圖片當我申請的轉型,這可以在代碼註釋中找到does not work with this enter image description here

EDIT 2

我也試了下進行改造,但是這使得空白png(無紅色交叉)

public ICoordinateTransformation Wgs84toGoogleMercator 
     { 
      get 
      { 

       if (_wgs84ToGoogle == null) 
       { 
        CoordinateSystemFactory csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory(); 
        CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory(); 

        IGeographicCoordinateSystem wgs84 = csFac.CreateGeographicCoordinateSystem(
         "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, 
         new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)); 

        // var a = csFac.CreateFromWkt("aa"); 


        List<ProjectionParameter> parameters = new List<ProjectionParameter>(); 
        parameters.Add(new ProjectionParameter("semi_major", 6378137.0)); 
        parameters.Add(new ProjectionParameter("semi_minor", 6378137.0)); 
        parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0)); 
        parameters.Add(new ProjectionParameter("central_meridian", 0.0)); 
        parameters.Add(new ProjectionParameter("scale_factor", 1.0)); 
        parameters.Add(new ProjectionParameter("false_easting", 0.0)); 
        parameters.Add(new ProjectionParameter("false_northing", 0.0)); 
        IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters); 

        IProjectedCoordinateSystem epsg900913 = csFac.CreateProjectedCoordinateSystem(
         "Google Mercator", wgs84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), 
         new AxisInfo("North", AxisOrientationEnum.North)); 

        ((CoordinateSystem)epsg900913).DefaultEnvelope = new [] { -20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789 }; 

        _wgs84ToGoogle = ctFac.CreateFromCoordinateSystems(wgs84, epsg900913); 
       } 

       return _wgs84ToGoogle; 

      } 
     } 
+0

嗨羅伯特。臨時票據,如賞金等在短期內並沒有真正有用,所以他們在評論中更好。我們的經驗是,即使他們已經過期或過期,他們通常也會被留下。除了緊急請求之外,我不會注意到這一點,這裏不鼓勵。 – halfer

+0

作者提供+100這個職位的答案。 – halfer

+0

請閱讀[在什麼情況下,我可以添加「緊急」或其他類似的短語到我的問題,以獲得更快的答案?](/ meta.stackoverflow.com/q/326569) - 總結是,這不是這是解決志願者問題的理想方式,可能會對獲得答案產生反作用。請不要將這添加到您的問題。 – halfer

回答

2

您使用的實際上工作。

由於您的ZoomToBox座標錯誤,您正在顯示空白圖像,因此實際上會顯示圖像的空白部分。如果您使用map.ZoomToExtents();函數來代替,以查看整個圖像在放大之前,它看起來是這樣的:

France - not zoomed

現在,如果我手動縮放瀏覽器來得到法國的特寫圖像與這種轉變應用,你可以看到它實際上不再被拉伸。

France - zoomed

作爲結論,我會說,你只需要修復您的ZoomToBox座標,一切都將工作得很好。希望能幫助到你。 :)

+0

我也試過,但我的是空白的。我也嘗試將信封變形。你有沒有使用我發佈的同一個WKT? – Robert

+0

@Robert Yea,那是我唯一的一個。 – msmolcic

+0

這很奇怪。你可以把你的代碼放到GitHub上,也許我的一些依賴關係會搞砸了嗎? – Robert

相關問題