0

I have 2 layers in the map file with different extents. In QGIS, I am able to see them one over the other in proper positions. However, when I am adding those 2 layers in the map file for MapServer (actually MS4W), only one of the 2 layers are visible depending upon whose extent is used in Map EXTENT.

Only that layer is visible whose extent (as shown in QGIS for that layer) is used in Map's EXTENT property.

When EXTENT=-7117600.0000000000000000 1367760.0000000000000000 4897040.0000000000000000 7809680.0000000000000000

enter image description here

When EXTENT=-164.1598054400749902 57.4191918763605997 -148.4810114236049969 70.7414186722972005 enter image description here

Following is the mapfile:

MAP  
  #EXTENT         -164.1598054400749902 57.4191918763605997 -148.4810114236049969 70.7414186722972005
  EXTENT       -7117600.0000000000000000 1367760.0000000000000000 4897040.0000000000000000 7809680.0000000000000000
  SIZE           3663 1964
  IMAGECOLOR     255 255 255
  SHAPEPATH      "../data"

  IMAGETYPE PNG

  WEB
    IMAGEPATH '/ms4w/tmp/ms_tmp/'
    IMAGEURL  '/ms_tmp/'
  END


  PROJECTION 
    "init=epsg:2964"
  END

  #
  # Start of LAYER DEFINITIONS ---------------------------------------------
  LAYER # Landcover raster layer begins here
    NAME         "landcover"
    DATA         "landcover-2.tif"
    #EXTENT       -7117600.0000000000000000 1367760.0000000000000000 4897040.0000000000000000 7809680.0000000000000000
    STATUS       OFF
    TYPE         RASTER

    PROJECTION     
      "init=epsg:2964"
    END
   
  END # Landcover raster layer ends here
  
  LAYER # Combined lakes layer begins here
    NAME         "combined-lakes"
    DATA         "combined-lakes.shp"
    #EXTENT         -164.1598054400749902 57.4191918763605997 -148.4810114236049969 70.7414186722972005
    STATUS       OFF
    TYPE         POLYGON   
    PROJECTION
      "init=epsg:2964"
    END
    
    CLASS
      NAME       "lakes"
      
      STYLE
        COLOR        0 0 0
        OUTLINECOLOR 32 32 32
      END
    END
   
  END # Combined lakes layer ends here
  
  # End of LAYER DEFINITIONS -------------------------------

END # end of map file

In QGIS, I am able to view both the layers properly: enter image description here

What am I missing in my Map File that is causing this behavior?

1 Answer 1

2

It's not clear to me how you are calling those MS4W layers (by the way, thanks for using MS4W, hope it works well for your organization, I am the creator/maintainer/everything for it, ha). Please specify if you are using WMS, or CGI "mode=map&layers=all" request, or whatever.

Here are some notes:

  • you have STATUS OFF for your layers, I would have them as STATUS ON (see the demo mapfile included in /ms4w/apps/local-demo/). Test your mapfile with shp2img command as shp2img -m test.map -o ttt.png -all_debug 3 (for MS4W v5.0 / MapServer8 this command will be changed to map2img)

  • use gdalinfo command for your raster layer, and a ogrinfo command for your vector (lakes) layer, to get the proper EXTENT values to put into those layers. (since you are using MS4W, execute first setenv.bat before those commands)

  • you have specified in your mapfile LAYER settings that both your layers are in the same source projection, please verify that both your data sources are in the EPSG:2964 projection. By your commented extent for the combined-lakes layer, it seems that its source projection is actually EPSG:4326 Please review the 'Important notes" section at https://mapserver.org/mapfile/projection.html Always think of the top MAP-level projection as the output projection, and then specify a PROJECTION object for each layer, using the source projection for each dataset. If you discover that the combined-layers layer is actually in the EPSG:4326 projection, then for that layer change the line "init=epsg:2964" to "init=epsg:4326", so MapServer knows that layer's source projection, so MapServer can then reproject it to your output projection on-the-fly.

  • QGIS does have on-the-fly reprojection, which can be confusing as you might assume that all of your data shown there is in the same projection, even if they might not be

Finally, thanks so much for the positive feedback for MS4W. I have put now 20 years of effort into that product. Thanks again, and happy mapserv-ing :)

Thanks again for mapserv-ing!

4
  • If you click the screenshots, you will be able to see the request I did in browser. I am using: http://localhost:81/cgi-bin/mapserv.exe?map=C:\ms4w\Imple\htdocs\combined-lakes-1.map&layer=landcover&layer=combined-lakes&mode=map Your 3rd point was bang on! The projection of combined-lakes was actually epsg:4326 and that was the cause of this issue. I exported the layer with epsg:2964 in QGIS and used that .shp file in MapServer with the now corrected extent (I took the extent of combined-lakes in Map's extent). Issue resolved. Thanks! But can't we use different projections for layers?
    – shanti
    May 28, 2022 at 9:50
  • 1
    Yes you can have source data in different CRS but you must have right values in the mapfile. For example epsg.org/crs_2964/NAD27-Alaska-Albers.html? is using survey foot as unit and the extent must use the same units. You had an extent -164.1598054400749902 57.4191918763605997 -148.4810114236049969 70.7414186722972005 but I think that the lakes cover larger area than about 16 by 13 feet.
    – user30184
    May 29, 2022 at 21:13
  • @shanti yes of course MapServer can do on-the-fly reprojection, I have updated my answer above to explain (you only needed to change one line). See the last sentence in my 3rd point.
    – mapserving
    May 30, 2022 at 10:11
  • @mapserving Regarding your point "If you discover that the combined-layers layer is actually in the EPSG:4326 projection, then for that layer change the line "init=epsg:2964" to "init=epsg:4326" yeah I did that too while trying. However, the extent may be in different units (I am not sure if different CRS use different units)
    – shanti
    May 30, 2022 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.