我正在使用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
任何幫助表示讚賞。
編輯: 這是我現在得到的圖像爲法國和它的地區「利穆贊」。正如你所看到的,它太「寬」了。
這是圖片當我申請的轉型,這可以在代碼註釋中找到does not work with this
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;
}
}
嗨羅伯特。臨時票據,如賞金等在短期內並沒有真正有用,所以他們在評論中更好。我們的經驗是,即使他們已經過期或過期,他們通常也會被留下。除了緊急請求之外,我不會注意到這一點,這裏不鼓勵。 – halfer
作者提供+100這個職位的答案。 – halfer
請閱讀[在什麼情況下,我可以添加「緊急」或其他類似的短語到我的問題,以獲得更快的答案?](/ meta.stackoverflow.com/q/326569) - 總結是,這不是這是解決志願者問題的理想方式,可能會對獲得答案產生反作用。請不要將這添加到您的問題。 – halfer