Hi Torsten,
For your link a, you can view it’s capability here:
http://www.pegelonline.wsv.de/webservices/gis/wms/aktuell/mnwmhw1?request=GetCapabilities&service=WMS
If you view the XML you will see it’s bouding box is like this:
<LatLonBoundingBox minx="5.09019" miny="46.9823" maxx="15.9068" maxy="55.1555" />
<BoundingBox SRS="EPSG:31467"
minx="3.25047e+06" miny="5.22116e+06" maxx="3.94202e+06" maxy="6.1139e+06" />
If you render it under 4326, it works well:
And here is the test code:
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
WmsRasterLayer wmsLayer = new WmsRasterLayer(new Uri("http://www.pegelonline.wsv.de/webservices/gis/wms/aktuell/mnwmhw"));
wmsLayer.SendingWebRequest += Wms_SendingWebRequest;
wmsLayer.ActiveLayerNames.Add("PegelonlineWMS");
wmsLayer.ActiveStyleNames.Add("default");
wmsLayer.Crs = "EPSG:4326";
wmsLayer.OutputFormat = "image/png";
LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.Layers.Add(wmsLayer);
winformsMap1.Overlays.Add(layerOverlay);
winformsMap1.CurrentExtent =new RectangleShape(5.09019, 55.1555, 15.9068, 46.9823);
winformsMap1.Refresh();
And this code works well for 31467 just simple change, because the 31467 list its bounding box in capability.
wmsLayer.Crs = "EPSG:31467";
Proj4Projection proj4 = new Proj4Projection(4326, 31467);
proj4.Open();
winformsMap1.CurrentExtent = proj4.ConvertToExternalProjection(new RectangleShape(5.09019, 55.1555, 15.9068, 46.9823)) as RectangleShape;
If the bounding box is not listed in the capability but you want to use it for example 3857 or 25832 you should want write a custom class and it should works.
public class CustomWmsRasterLayer : WmsRasterLayer
{
public CustomWmsRasterLayer(Uri uri) : base(uri)
{
}
protected override RectangleShape GetBoundingBoxCore()
{
RectangleShape rect = base.GetBoundingBoxCore();
if (Crs == "EPSG:25832")
{
Proj4Projection proj4 = new Proj4Projection(4326, 25832);
proj4.Open();
rect = proj4.ConvertToExternalProjection(rect) as RectangleShape;
}
return rect;
}
}
private void LoadServer1()
{
winformsMap1.MapUnit = GeographyUnit.Meter;
CustomWmsRasterLayer wmsLayer = new CustomWmsRasterLayer(new Uri("http://www.pegelonline.wsv.de/webservices/gis/wms/aktuell/mnwmhw"));
wmsLayer.SendingWebRequest += Wms_SendingWebRequest;
wmsLayer.ActiveLayerNames.Add("PegelonlineWMS");
wmsLayer.ActiveStyleNames.Add("default");
wmsLayer.Crs = "EPSG:25832";
wmsLayer.OutputFormat = "image/png";
LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.Layers.Add(wmsLayer);
winformsMap1.Overlays.Add(layerOverlay);
Proj4Projection proj4 = new Proj4Projection(4326, 25832);
proj4.Open();
winformsMap1.CurrentExtent = proj4.ConvertToExternalProjection(new RectangleShape(5.09019, 55.1555, 15.9068, 46.9823)) as RectangleShape;
winformsMap1.Refresh();
}
I think this should be the problem of capability in server, but I also will ask our developer did research on it.
Wish that’s helpful.
Regards,
Ethan