2

I have a problem with ecw file. I'm using mapserver and openlayers. I have a ecw file and I make my tileindex file with gdaltindex. I want to put in my map file, I tried many ways but no ones work. How can I show my ecw files in my map?

PS: I have support for ecw files by the way.

3

It works in a similar way than tileindex with geotiffs. Actually I would recommend to test first with a geotiff tileindex and couple of images so that you know that everything else despite ECW is configured correctly. If changing to ECW breaks something you know where to start searching the reason for the issue. It can be that the GDAL of your Mapserver does not support ECW. However, if you could create the tileindex then probably that is not the case. Two suggerstions:

  • Perhaps the paths in tileindex are not correct? I always create them with "-write_absolute_path" but some others prefer to write them relative to SHAPEPATH http://www.mapserver.org/optimization/tileindex.html.
  • Learn to use DEBUG in your mapfiles
  • Learn to test with shp2img utility, it removes the hassle caused by the clients and the web. Once you know that Mapserver is OK you can continue and try to connect it from your client.
LAYER
NAME 'ecw_tileindex_layer'
TYPE RASTER
#DEBUG 5 
#In case of trouble uncomment DEBUG and see MS_ERRORFILE
TILEINDEX 'users/user/data/ecw_tileindex.shp'
STATUS ON
OFFSITE 0 0 0
METADATA
'wms_title'    'ecw_tileindex_layer'
'wms_srs' 'EPSG:4326 EPSG:3587'
END
PROJECTION
'init=epsg:4326'
END
END

Edit

Here comes the whole procedure for making a WMS layer from a bunch of images.

  1. Acquire some images. I use the demo images which come with Geoserver installation and files can be found from directory geoserver-2.5\data_dir\coverages\mosaic_sample. They are png images but it is not important because all the images behave in the same way for Mapserver if it has a driver for reading them.
  2. Check the native projection of the images. In this case it can be done by opening one .prj file which shows "AUTHORITY["EPSG","4326"]]". Gdalinfo is the standard tool for checking the projection but it fails with these png images.
  3. Create tileindex as

    C:\ms4w\apps\image_data>gdaltindex -write_absolute_path png_mosaic.shp *.png

  4. Check the extents of the tileindex with ogrinfo

     C:\ms4w\apps\image_data>ogrinfo -al -so png_mosaic.shp INFO: Open of
     `png_mosaic.shp'
           using driver `ESRI Shapefile' successful.
    
     Layer name: png_mosaic Geometry: Polygon Feature Count: 25 Extent:
     (6.346175, 36.491772) - (20.829683, 46.590767)
    
  5. Write a basic mapfile "tileindex.map" with all this information.
MAP
SIZE 800 800
EXTENT 6.346175 36.491772 20.829683 46.590767
UNITS DD
IMAGECOLOR 20 250 250
WEB
    METADATA
        "ows_enable_request" "*"
        "wms_bbox_extended" "true"
        "wms_srs" "CRS:84 EPSG:4326 EPSG:3857"
        "wms_title" "tileindex demo"
    END #metadata
END #web    
CONFIG "PROJ_LIB" "C:/ms4w/proj/nad"
CONFIG "CPL_DEBUG" "ON"
CONFIG "MS_ERRORFILE" "c:/ms4w/tmp/debug.txt"
PROJECTION
"init=epsg:4326"
END

LAYER
NAME "tileindex_layer"
TYPE RASTER
TILEINDEX "c:/ms4w/apps/image_data/png_mosaic"
STATUS ON
DEBUG 10
PROJECTION
        "init=epsg:4326"
END
METADATA
"wms_title" "tileindex_layer"
END
END
END

6. Test your Mapserver and mapfile. All these can be sent from the browser. The request and output that shows that everything is OK follows. See \comments

http://localhost/cgi-bin/mapserv.exe
No query information to decode. QUERY_STRING is set, but empty.

\mapserv.exe executable is found

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tileindex.map
mapserv(): Web application error. Traditional BROWSE mode requires a TEMPLATE in the WEB section, but none was provided.

\mapfile from is found

http://localhost:8060/cgi-bin/mapserv.exe?map=/ms4w/apps/tileindex.map&mode=map&layers=all

\mode=map may be ancient but sometimes handy for testing

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/tileindex.map&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&WIDTH=409&HEIGHT=346&LAYERS=tileindex_layer&TRANSPARENT=TRUE&FORMAT=image%2Fpng&BBOX=6.34617,35.41501469437653,20.8297,47.667585305623476&SRS=EPSG:4326&STYLES=

\this is a real complete WMS request and below is the result

Mapserver WMS output from this tutorial

Everything is done in a similar way with ECW images but it is better to test fist with some images which are for sure supported with all Mapserver and GDAL versions.

28
  • It doesn't work. I tried that way, I use the shp2img to debug the map and it is ok. May be the problem is in the openlayers call? I call it wms = new OpenLayers.Layer.WMS('ortofotos','localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/prueba/mapa.map',{layers: 'ortofotos'},{isBaseLayer:true}); Jun 23 '14 at 10:43
  • If shp2img works then I would test with some WMS client like OpenJUMP or QGIS next. You must help OpenJUMP by doing Zoom to WMS layer from the Table of contents because it does not zoom automatically. If WMS works you can be sure that the problem is in the OpenLayers configuration and ECW and Mapserver play no role at all.
    – user30184
    Jun 23 '14 at 10:54
  • I try with gvSig and it doesn't connect by wms. I don't know why but my mapfile is the next : MAP NAME mapa SIZE 1400 900 IMAGETYPE png IMAGECOLOR 196 240 255 EXTENT -16.1737 27.6847 -13.1254 29.4506 SHAPEPATH "C:/ms4w/apps/prueba/datos" WEB TEMPLATE "c:/ms4w/apps/prueba/index.html" IMAGEPATH "c:/ms4w/tmp/ms_tmp/" IMAGEURL "/ms_tmp/" METADATA WMS_TITLE "mapa" WMS_SRS "EPSG:4326 EPSG:4258" WMS_ONLINERESOURCE "localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/prueba/mapa.map" WMS_ENABLE_REQUEST "*" END END PROJECTION "init=EPSG:4258" END UNITS meters and the code that you put. Jun 23 '14 at 11:31
  • Use your browser and send http://localhost/cgi-bin/mapserv.exe you should see "No query information to decode. QUERY_STRING is set, but empty." Next send http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/prueba/mapa.map Do you see "mapserv(): Web application error. Traditional BROWSE mode requires a TEMPLATE in the WEB section, but none was provided." If yes, everything is OK so far.
    – user30184
    Jun 23 '14 at 11:54
  • When I put the first URL I get the message "No query information to decode. QUERY_STRING is set, but empty.", but when I put the second, I get "Content-type: text/html isValidTemplate(): Web application error. Missing magic string, c:/ms4w/apps/prueba/index.html doesn't look like a MapServer template." Is anything wrong? Jun 23 '14 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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