我正在使用 sharpmap 将 MSSQL 中的边框(几何)渲染为 PNG 图像。这一切都很好,除了国家在平面图像格式上看起来太“宽泛”。
据我了解,我需要创建到 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
编辑 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;
}
}