Loding WMS Layer

Helo everybody,

I’ve just started trying to include WMs-Layers in my Ms-Access application - and didn’t succeed.

First the URL of the WMS-Server seems to be funny (somethings seems to be missing):
"https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete?[hwgf_hqhaeufig]

Second the projection is UTM32 but tkTileProjection does not seem to offer this one…

Thirdly I tryed the following code - but nothing seem to happen (I’m quite sure I mixed everything up - maybe someone could help? - Thank you:

Dim objProvider As Object
Dim intProviderId As Integer
Set objProvider = Me.mapMain.Tiles.Providers
intProviderId = CInt(tkTileProvider.ProviderCustom) + 1
objProvider.Add intProviderId, "?berschwemmungsfl?chen", "https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete?[hwgf_hqhaeufig] ", tkTileProjection.SphericalMercator, 0, 18
Me.mapMain.Tiles.ProviderId = intProviderId
Me.mapMain.Redraw

Hello @dimpflmoser

If you debug and step through the code, where does it break down?

Followup:

One thing we’ve seen in the past with MS Access VBA (this may not be true in your case) is that you cannot piggy-back the COM calls. In other words, instead of

Set objProvider = Me.mapMain.Tiles.Providers

you may have to instead do something like

Dim objTiles as Tiles
Set objTiles = mapMain.Tiles
Set objProvider = objTiles.Providers

Hello again,

thank you for your answeres.

In the meantime I found the following link on your forum : https://gis.stackexchange.com/questions/289051/loading-wms-layer-with-mapwingis-from-geoserver - which I should have found earlier - sorry for that.

I followed the instructions and ended up with the following vba-code:

' Test WMS
Dim objWmsLayer As MapWinGIS.WmsLayer
Dim objExtents As MapWinGIS.Extents
Dim intLayerHandle As Integer

Set objExtents = New MapWinGIS.Extents
Set objWmsLayer = New MapWinGIS.WmsLayer
objExtents.SetBounds 8.205988, 46.781936, 0, 14.641022, 51.030572, 0

objWmsLayer.BaseUrl = "https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete?"
objWmsLayer.BoundingBox = objExtents
objWmsLayer.Epsg = 25832
objWmsLayer.Format = "image/png32"
objWmsLayer.Layers = "[hwgf_hqhaeufig}"
objWmsLayer.name = "Hochwassergefahrenfl?chen HQh?ufig"
objWmsLayer.Opacity = 255

intLayerHandle = Me.mapMain.addLayer(objWmsLayer, True)

Me.mapMain.LayerVisible intLayerHandle, True
Me.mapMain.Redraw

This code doesn’t give any error, but the layer doesn’t appear either. I can’t see what my mistake is. I’m trying to load the map using the Information from the following site:
https://geoportal.bayern.de/getcapabilities/CapabilitiesViewer?ows_url=https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete?&format=html&link=true

Thank you very much again

Hello again,

as stated in my last post (not published yet) I moved to MapWinGis WmsLayer functionality to display Wms-maps. The problem in my last try was, I got the extents mixed up (I accidentally swaped the X- and Y-Values).

Just to round this thread up - this is the code which did the Job:

' Test WMS
Dim objWmsLayer As MapWinGIS.WmsLayer
Dim objExtents As MapWinGIS.Extents
Dim intLayerHandle As Integer

Set objExtents = New MapWinGIS.Extents
Set objWmsLayer = New MapWinGIS.WmsLayer
objExtents.SetBounds 444247.640297, 5181048.300034, 0, 914153.8116, 5665064.52217, 0

objWmsLayer.BaseUrl = "https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete"
objWmsLayer.BoundingBox = objExtents
objWmsLayer.DoCaching = False
objWmsLayer.Epsg = 25832
objWmsLayer.Format = "image/png"
objWmsLayer.Layers = "hwgf_hqhaeufig"
objWmsLayer.name = "Hochwassergefahrenfl?chen HQh?ufig"
objWmsLayer.Opacity = 63
objWmsLayer.UseCache = False
objWmsLayer.TransparentColor = 255
objWmsLayer.UseTransparentColor = True

intLayerHandle = Me.mapMain.addLayer(objWmsLayer, True)

Me.mapMain.LayerVisible intLayerHandle, True
Me.mapMain.Redraw

Thank you again for your help

Hello again,

strange though, I implemented the code in my application after I have moved to MapWingis 5.2.4 and what used to work in 4.9.x in June doesn’t anymore.
The code doesn’t produce any errors but doesn’t show up the Wms-Layer either. So I guess somethings got messed up with the coordinates again by me. Strange though in the upper right corner of the map the coordinates displayed seem not to be EPSG 25832 but something like Mercator - I think I can remember they didn’t before.
As anybody any Idea?
Thanks in advance

It’s me again,

for I was not sure whether it’s been kind of an MS-Access problem I created a small C# project with just one form and a map-Control . I put all the intelligence into the form load method (below). The code should load one shapefile (which it does) and display a wms layer (which it doesn’t).
The same as in Vba-code. No error-message but nothing shown either.
If someone wants to try out the code I could provide the shapefile.
The capabilities of the Wms-Layer can be found here:

Do I mix up the Coordinates? I’m pretty sure I don’t but numbers never been my strong side.
Thanks

And here is my C#-code:

private void Form1_Load(object sender, EventArgs e)
    {
        MapWinGIS.Shapefile objShape;
        MapWinGIS.WmsLayer objWmsLayer;
        MapWinGIS.Extents objExtents;
        int intShapeHandle;
        int intLayerHandle;

        objShape = new MapWinGIS.Shapefile();
        // Shapefile laden
        if (objShape.Open("D:\\Daten\\Gis-Data\\SHAPE-Kuenzing\\AX_Flurstueck.shp", null)) {
            intShapeHandle = this.mapMain.AddLayer(objShape, true);

            // Hochwasser
            objExtents = new MapWinGIS.Extents();
            objWmsLayer = new MapWinGIS.WmsLayer();
            objExtents.SetBounds(444247.640297, 5181048.300034, 0, 914153.8116, 5665064.52217, 0);

            objWmsLayer.BaseUrl = "https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete?";
            objWmsLayer.BoundingBox = objExtents;
            objWmsLayer.Epsg = 4326;
            objWmsLayer.Format = "image/png32";
            objWmsLayer.Layers = "[hwgf_hqextrem]";
            objWmsLayer.Name = "Hochwassergefahrenflächen HQhäufig";
            objWmsLayer.Opacity = 63;

            intLayerHandle = this.mapMain.AddLayer(objWmsLayer, true);

            this.mapMain.set_LayerVisible(intLayerHandle, true);

            this.mapMain.ZoomToLayer(intShapeHandle);
        }
    }

Hello @dimpflmoser

Yes, please attach the Shapefile, and I’ll have a look.

Regards,
Jerry.

Hello Jerry,

that’s very nice of you - thanks very much.

RegardsAX_Flurstueck.zip (483.6 KB)

Hello @dimpflmoser

I’ve started looking at this; I’ll need more time.

I know nothing about WMS layers, but I need to learn.

  1. I do notice that the BoundingBox property indicates that it should be in the coordinate system of the server
  2. That said, you are setting the EPSG to 4326, which is in degrees-minutes-seconds
  3. but the bounding box properties you are setting look more like meters (UTM or Google Mercator)
  4. Could this be why it’s not loading?

As a side note, the Shapefile you attached does load, but it has no DBF or projection file. The map control is likely defaulting to Google Mercator. There are settings to control the map projection as well as whether you want your layer to comply with the map, or the map to comply with the layer’s projection.

Regards,
Jerry.

Hello again.

Well, I’ve made a few changes, trying different things, but still no success. Do you know the version of the WMS data? This affects the bounding box order. AND there may be a bug in the OCX related to the new v1.30, which changed the order (I think) to Lat,Long instead of Long,Lat.

    private void Form1_Load(object sender, EventArgs e)
    {
        MapWinGIS.Shapefile objShape;
        MapWinGIS.WmsLayer objWmsLayer;
        MapWinGIS.Extents objExtents;
        int intShapeHandle;
        int intLayerHandle;

        // tell the map we're using Google Mercator
        axMap1.Projection = MapWinGIS.tkMapProjection.PROJECTION_GOOGLE_MERCATOR; // .PROJECTION_WGS84; // 
        axMap1.TileProvider = MapWinGIS.tkTileProvider.ProviderNone;

        MapWinGIS.GlobalSettings gs = new MapWinGIS.GlobalSettings();
        // tell the layer to use the Map's projection
        gs.AllowLayersWithoutProjections = true;
        gs.AllowProjectionMismatch = true;
        gs.ReprojectLayersOnAdding = true;
        

        objShape = new MapWinGIS.Shapefile();
        // Shapefile laden
        if (objShape.Open("C:\\Temp\\AX_Flurstueck\\AX_Flurstueck.shp", null))
        {
            intShapeHandle = this.axMap1.AddLayer(objShape, true);

            // Hochwasser
            objExtents = new MapWinGIS.Extents(); // objShape.Extents; // 
            objWmsLayer = new MapWinGIS.WmsLayer();
            objWmsLayer.Version = MapWinGIS.tkWmsVersion.wvAuto;
            

            objExtents.SetBounds(444247.640297, 5181048.300034, 0, 914153.8116, 5665064.52217, 0);

            objWmsLayer.BaseUrl = "https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete?";
            objWmsLayer.BoundingBox = objExtents;
            // the coordinates we're providing are in Google Mercator
            objWmsLayer.Epsg = 3857; // 4326; // 
            objWmsLayer.Format = "image/png32";
            objWmsLayer.Layers = "[hwgf_hqextrem]";
            objWmsLayer.Name = "Hochwassergefahrenflächen HQhäufig";
            objWmsLayer.Opacity = 63;

            intLayerHandle = this.axMap1.AddLayer(objWmsLayer, true);

            this.axMap1.set_LayerVisible(intLayerHandle, true);

            this.axMap1.ZoomToLayer(intLayerHandle);
        }
    }

Let me know if you figure anything out, and I’ll do likewise.

Regards,
Jerry.

Hi Jerry,
Hi dimpflmoser (aka Hotzenplotz-Hunter :wink:

I played around with your code and found a working solution in VBA:

##############

Map0.TileProvider = MapWinGIS.tkTileProvider.ProviderNone
Map0.Projection = tkMapProjection.PROJECTION_WGS84

Set objWmsLayer = New MapWinGIS.WmsLayer
Set objExtents = New MapWinGIS.Extents

objExtents.SetBounds 10.98326, 48.69167, 0, 11.0237, 48.72229, 0

objWmsLayer.BaseUrl = "https://www.lfu.bayern.de/gdi/wms/wasser/ueberschwemmungsgebiete"
objWmsLayer.BoundingBox = objExtents
objWmsLayer.DoCaching = False
objWmsLayer.Epsg = 4326
objWmsLayer.Format = "image/png32"
objWmsLayer.Layers = "hwgf_hqhaeufig"
objWmsLayer.Name = "Hochwassergefahrenfl?chen HQh?ufig"
objWmsLayer.Opacity = 63
objWmsLayer.UseCache = False
objWmsLayer.TransparentColor = 255
objWmsLayer.UseTransparentColor = True
objWmsLayer.Version = wv13

intLayerHandle = Me.Map0.AddLayer(objWmsLayer, True)
Me.Map0.LayerVisible intLayerHandle, True

Set Me.Map0.Extents = objExtents
Me.Map0.MoveTo 10.9833, 48.6918
Me.Map0.Redraw

################

It is quite usefull to log the WMS/Tile-Requests of MapWinGIS with:

Dim myGlobalSettings As MapWinGIS.GlobalSettings

If (myGlobalSettings Is Nothing) Then Set myGlobalSettings = New MapWinGIS.GlobalSettings

myGlobalSettings.LogTileErrorsOnly = True
Call myGlobalSettings.StartLogTileRequests(strPath + strTILE_LOG_FILE)

–> where strPath & strTILE_LOG_FILE need to be defined.

Here i figuerd out, that

  • the WMS-Version needs to be set, to get the CRS-Parameter used by MapWinGis compatible to this specific WMS-Server.

Hope this works for you as well.

Stay healthy and have fun.

Ciao
Stefan

1 Like

Thank you for posting this.

Dear Stefan,

thank you very much for posting your solution. As of Corona it’s just now I’m getting back to work on the application.

I’ll test it next week and keep you informed

Best whishes and regards

I am trying on vb.net with no success
-> https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php
who wants to help me?

    Dim objWmsLayer As New MapWinGIS.WmsLayer
    Dim objExtents As New MapWinGIS.Extents
    objExtents.SetBounds(-1877994.66, 3932281.56, 0, 836715.13, 9440581.95, 0)
    objWmsLayer.BaseUrl = "https://wms.cartografia.agenziaentrate.gov.it/inspire/wms/ows01.php"
    objWmsLayer.BoundingBox = objExtents
    objWmsLayer.DoCaching = False
    objWmsLayer.Epsg = 25832
    objWmsLayer.Format = "image/png"
    objWmsLayer.Layers = "CP.CadastralZoning,acque,strade,CP.CadastralParcel,fabbricati,codice_plla,simbolo_graffa"
    objWmsLayer.Name = "catasto"
    objWmsLayer.Opacity = 63
    objWmsLayer.UseCache = False
    objWmsLayer.TransparentColor = 255
    objWmsLayer.UseTransparentColor = True
    objWmsLayer.Version = tkWmsVersion.wv111
    Dim intLayerHandle As Integer = Me.AxMap2.AddLayer(objWmsLayer, True)
    AxMap2.set_LayerVisible(intLayerHandle, True)
    AxMap2.Extents = objExtents
    AxMap2.Redraw()

Thanks in advance :slight_smile:

Hi Max,

i think, there is something wrong with this WMS-Service.
First, the ssl-certifacte it uses is self signed and not accepted from any application.
I just added this server address to QGis and MapInfo Pro and
it looks weired in both applications, you cannot zoom and it’s always only one view in one scale that shows up.
My first guess is a missconfigured wms server.

cheers
Stefan