ThinkGeo.com    |     Documentation    |     Premium Support

WmsRasterLayer does not display image

Hi,

I’m using the following code to get a WmsRasterLayer from the following uri. I’ve verified the uri works in other software.

The request goes through and I can get the layers list and add the layers and styles to the active collections. Also, the getboundingbox successfully sets the map extents as expected. The only exception is there’s no image on the screen.

What am I doing wrong?

https://mesonet.agron.iastate.edu/cgi-bin/wms/us/mrms.cgi?VERSION=1.1.1&REQUEST=GetCapabilities&SERVICE=WMS&

        WmsRasterLayer wmsfl = new WmsRasterLayer(wms.URI);
        wmsfl.Name = wms.Name;

        wmsfl.Open();
        Collection<string> layers = wmsfl.GetServerLayerNames();
        Collection<string> styles = wmsfl.GetServerStyleNames();
        wmsfl.UpperThreshold = double.MaxValue;
        wmsfl.LowerThreshold = 0;
        wmsfl.TimeoutInSecond = 60;
        foreach (string layer in layers)
        {
            wmsfl.ActiveLayerNames.Add(layer);
        }
        foreach (string style in styles)
        {
            wmsfl.ActiveStyleNames.Add(style);
        }
        
        RectangleShape rect = wmsfl.GetBoundingBox();
        
        wmsfl.Close();            

        CultureOverlay.Layers.Add(wms.Name, wmsfl);

        winformsMap1.CurrentExtent = rect;
        winformsMap1.Refresh();

Hi Damian,

The code as below works for me, I think you should forget to add the overlay into map.

        wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
        WmsRasterLayer wmsfl = new WmsRasterLayer(new Uri("https://mesonet.agron.iastate.edu/cgi-bin/wms/us/mrms.cgi?VERSION=1.1.1"));            

        wmsfl.Open();
        Collection<string> layers = wmsfl.GetServerLayerNames();
        Collection<string> styles = wmsfl.GetServerStyleNames();
        wmsfl.UpperThreshold = double.MaxValue;
        wmsfl.LowerThreshold = 0;
        wmsfl.TimeoutInSecond = 60;
        foreach (string layer in layers)
        {
            wmsfl.ActiveLayerNames.Add(layer);
        }
        foreach (string style in styles)
        {
            wmsfl.ActiveStyleNames.Add(style);
        }

        RectangleShape rect = wmsfl.GetBoundingBox();

        wmsfl.Close();

        LayerOverlay CultureOverlay = new LayerOverlay();
        CultureOverlay.Layers.Add(wmsfl);
        wpfMap1.Overlays.Add(CultureOverlay);
        wpfMap1.CurrentExtent = rect;
        wpfMap1.Refresh();

Regards,

Don

Hi Don,

Sorry, I didn’t mean to confuse. In my project, CultureOverlay has a get accessor and is already an overlay in the map.

I’ve copied your code straight into a test project and ran it against version 9.0.0.541 and I get the exact same issue where the layer has data, but no display on the map.

Ideas? Missing reference? Spatial extension?

Thanks,
Damian

Hi Damian,

I don’t think the WmsRasterLayer is realted with dll and spatial extension.

Please add sending request event for wmsfl, and print all the request link, then open them in the browser to see whether you get the correct uri.

Regards,

Don

Hi Don,

When I take the uri out of the sending request event and paste it into browser, I get this message for which I don’t see much help on the internet.

msCGILoadMap(): Web application error. CGI variable “map” is not set.

Here’s the uri that came back from the sending request.

https://mesonet.agron.iastate.edu/cgi-bin/mapserv/mapserv?BBOX=-132.2109375,10.3251953125,-59.7890625,63.6748046875&EXCEPTIONS=&FORMAT=image/png&HEIGHT=607&LAYERS=mrms,mrms_p72h,mrms_p48h,mrms_p24h,mrms_p1h&REQUEST=GetMap&SERVICE=WMS&SRS=EPSG:4326&STYLES=default,default,default,default&VERSION=1.1.1&WIDTH=824

However, if I use other software and provide the base uri as configure, then I can see all the layers and they display.

MapSuite is seeing the layers are there, but something is preventing display. Attached is the test project. It’s based on your code, so please confirm it works for you as is.

Regards,
Damian

WFSTest.zip (37.1 KB)

Hi Damian,

Thanks for your further research. I found that’s because the dll problem.

Please download the dll here: https://ap.thinkgeo.com:5001/sharing/oeQke192a

And that should works.

Regards,

Don

Hi Don,

The new dll works for this, but it’s got some other issues making it impossible for me to put into production. For example, I thought to test reprojecting from WGS84 to UTM and found that when you try and set the ExternalProjectionParametersString it doesn’t take (see below).

I found that the new dll caused the uri to be modified to include the following “map=/opt/iem/data/wms/us/mrms.map”. Please can you tell me where this string came from so that I can use the SendingWebRequest event to append this to the uri without having to use the new version 9.0.612.0.

Thanks,
Damian

        ManagedProj4Projection proj = new ManagedProj4Projection();

        proj.InternalProjectionParametersString = ManagedProj4Projection.ConvertEpsgToPrj(4326);
        proj.ExternalProjectionParametersString = ManagedProj4Projection.ConvertEpsgToPrj(32615);   // = null!

Hi Damian,

I think you should want modify the code like this:

ManagedProj4Projection proj = new ManagedProj4Projection();

        proj.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);
        proj.ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(32615);

Regards,

Don

Hi Don,

Okay thanks. Strange, but I thought ConvertEpsgToPrj should do the same thing.

I have another problem now though. I try and set imagesource of the image to new proj and I get errors as such:

“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

The code I added is as follows (map is in meters):

        ManagedProj4Projection proj = new ManagedProj4Projection();

        proj.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);
        proj.ExternalProjectionParametersString = ManagedProj4Projection.GetSphericalMercatorParametersString();

        proj.Open();
        wmsfl.ImageSource.Projection = proj;
        rect = proj.ConvertToExternalProjection(rect);

Hi Damian,

Thanks for your code, but your code works well in my end.

I think maybe you can try to open the wmsfl also, and if the exception is still thrown, please upload a simple sample so we can reproduce it.

Regards,

Don

Hi Don,

Attached my simple project where I get the errors. Leaving wmsfl open has no impact.

FYI: I also get this same error with GDIPlusRasterLayer, but haven’t gotten around to report it yet. Must be some coincidence.

Regards,
Damian

WFSTest.zip (43.3 KB)

Hi Damian,

Thanks for your sample, but it still works well in my machine:

I guess that’s related with your unmanaged dlls, please try to download this package and install it.
https://ap.thinkgeo.com:5001/sharing/I7Htis5v0

Regards,

Don

Hi Don,

Yes, it looks like I still had version 8 unmanaged dll installed on my computer.

This brings me to something that we’ve spoken about before (under my old uid), and that’s to do with version control.

  1. To initially fix WMS problem you sent me desktop edition 9.0.612.0 libraries.
  2. These libraries are not on the customer portal where I still see 9.0.541.0 and 9.0.0.541 which is what my production software is built off of.
  3. The unmanaged dll you sent is version 9.0.569.0. I went to look for one that is built off 9.0.0.541, but it isn’t found on the Dependencies page or customer portal which begs the question of how to get the files in the first place when they aren’t included in the desktop edition package.

I’m quite confused how the unmanaged dll and desktop edition packages you sent me can be higher than the development version on customer portal.

Although I would really like to ensure that I have the most current and stable production version of the code, these issues make me feel too uncomfortable to deploy in my software. Please advice to getting correct packages, why there are so many version discrepancies and what I should do when I find them.

Thanks,
Damian

Hi Damian,

Thanks for let us know your confusing about the version.

For V9, we optimize the daily build update process, you can find all the V9 package get refresh each day, so please download them from the product center.

And I want to recommend you upgrade to our V10, because the V10 choose new distribution way NuGet, you can always upgrade to the latest version include Managed and Unmanaged dlls, and don’t need to worry the mismatching problem.

Regards,

Don