Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Updates: Problem Solved !!!!!!!!!!!!!!!!!!!!!

Replace "wms_srs" "EPSG:3857" to "wms_srs" "EPSG:900913" in Mapfile

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I am using OpenLayer WMS to loaded a layer from the PostGIS Raster Table, the JavaScript on openlayer are as following:

        function init(){
        var map = new OpenLayers.Map('map');

        var imagery = new OpenLayers.Layer.WMS(
            "Global Imagery",
            "http://maps.opengeo.org/geowebcache/service/wms",
            {layers: "bluemarble",
            }
        );  
       // var imagery = new OpenLayers.Layer.OSM( "Simple OSM Map");
/*It doesn't work with this OSM basemap, showing error: 
     WMS Server Error: Invalid SRS is given */
        map.addLayer(imagery);

        localWMS = new OpenLayers.Layer.WMS( "Local WMS layers",
                  "http://127.0.0.1/cgi-bin/mapserv.exe?MAP=C:/Users/gyu1/Desktop/Newfolder/mapserver.map",
                  {layers: 'polygon',transparent: true}, {isBaseLayer: false} );
        map.addLayer(localWMS);

        map.setCenter(
            new OpenLayers.LonLat(1.147, 52.472).transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
            ), 5
        );

        map.addControl( new OpenLayers.Control.LayerSwitcher());
    }

The map file linking the Data and styling are as following:

MAP
NAME "polygon"
WEB 
        METADATA
           "wms_title"          "MapServer"
           "wms_onlineresource" "http://127.0.0.1/cgi-bin/mapserv.exe?MAP=C:/Users/gyu1/Desktop/Newfolder/mapserver.map"
           "wms_srs"            "EPSG:4326 EPSG:3857"
        END      
END

PROJECTION
    "init=epsg:3857"
END  

    LAYER
        NAME "postgis"
        TYPE raster
        STATUS ON
        DATA "PG:host=localhost port=5432 dbname='fusiongeo' user='postgres' password='**' schema='public' table='london' mode='2'" 
        PROCESSING "NODATA=-9999"
        PROCESSING "SCALE=AUTO"

        CLASS
            NAME "boring"
            EXPRESSION ([pixel] < 50)
            COLOR 250 100 0
        END
        CLASS
            NAME "mildly interesting"
            EXPRESSION ([pixel] > 50 AND [pixel] < 100)
            COLOR 100 0 0
        END
        CLASS
            NAME "very interesting"
            EXPRESSION ([pixel] >= 100)
            COLOR 0 50 0
        END
    END     
END # end map

It works for the Google Base Map not the OpenStreetMap. I am quite new with the MapServer, openlayer and I don't know how to change the SRS to make it work. Thanks. The data in PostGIS are in EPSG:3857.

share|improve this question
    
EPSG:3857 is web mercator, the same than EPSG:900913 which unit is meter. EPSG:4326 is WGS84 in lat/lon degree. Maybe the right projection unit, resolution and extent are not well define in OpenLayers –  Below the Radar Jun 13 '13 at 13:41
    
You need to set the projection of the map. I don't see that in your code. –  Devdatta Tengshe Jun 13 '13 at 13:42
    
You can just append epsg:900913 to the wms_srs line so Mapserver will advertise in WMS that it can reproject to that srs as well. –  Dave X Sep 13 '13 at 19:07
add comment

2 Answers 2

 map.setCenter(
            new OpenLayers.LonLat(1.147, 52.472).transform(
                new OpenLayers.Projection("EPSG:4326"),
                map.getProjectionObject()
            ), 5
        );

you're mixing things like above. If Mapserver is serving your Postgis data set in EPSG:3857, you don't need EPSG:4326 in your mapfile. The EPSG:4326, however, will be needed in your html if you need to convert utm values to geographical ones (ie. to decimal degrees). It also will be needed if you want to add some WMS in 4326 (so in the mapfile and openlayers code). OSM is in Spherical Mercator and EPSG:3857 in your mapfile is correct. Check here for some working examples:

http://jsfiddle.net/aguiguy/ZAZN8/
http://jsfiddle.net/UAxun/155/
http://jsfiddle.net/VictorVelarde/DbCgt/

About your mapfile, what I meant was for instance:

DATA "geom FROM table USING UNIQUE id USING SRID=4326"

which works for a table in EPSG:4326, and this goes into your mapfile. Your mapfile has this:

DATA "PG:host=localhost port=5432 dbname='fusiongeo' user='postgres' password='**' schema='public' table='london' mode='2'"

and I think it should be something like this (you has missed so far the connection option):

CONNECTION "PG:host=localhost port=5432 dbname='fusiongeo' user='postgres' password='**'"
DATA "geom FROM YOURtable USING UNIQUE id USING SRID=3857"

Check here for some more basic info: http://trac.osgeo.org/mapserver/wiki/PostGIS

Hope this helps,

share|improve this answer
    
Hi, Gery. I updates my javascript but it still shows the same error. My new javascript is as following: –  Yu Guo Jun 13 '13 at 15:11
    
I think something wrong with the Map file wms_srs: code –  Yu Guo Jun 13 '13 at 16:49
    
Hi Yu, you need only ´"wms_srs" "EPSG:3857"´ in your mapfile. Also you need more info about the file type (PNG, etc) and tags like SIZE, EXTENT, UNITS, etc, check here for good map file examples: live.osgeo.org/es/quickstart/mapserver_quickstart.html, atlantic.evsc.virginia.edu/~jhp7e/advgis/local/2005/… –  Gery Jun 13 '13 at 19:08
    
Hi Gery, is not the case. I already tried with that before, it just doesn't work with OpenStreet Map. It works with Google map even without SIZE, EXTENT,Units. Since it connects to the PostGIS raster table, I don't think the user need to specify the details. The MapServer can read it from table. –  Yu Guo Jun 14 '13 at 8:33
    
I see, and you also specified the SRID in your postgis call in mapserver? –  Gery Jun 14 '13 at 8:34
show 7 more comments

Updates Java Script

 var map = new OpenLayers.Map('map', {
                projection: new OpenLayers.Projection("EPSG:3857"),
                displayProjection: new OpenLayers.Projection("EPSG:4326"),
                units: "m"
        });
  var imagery = new OpenLayers.Layer.OSM( "Simple OSM Map");
  map.addLayer(imagery);

        localWMS = new OpenLayers.Layer.WMS( "Local WMS layers",
                  "http://127.0.0.1/cgi-bin/mapserv.exe?MAP=C:/Users/gyu1/Desktop/Newfolder/mapserver.map",
                  {layers: 'polygon',transparent: true},
                  {isBaseLayer: false} );
        map.addLayer(localWMS);

        var lonlat = new OpenLayers.LonLat(lon,lat).transform(map.displayProjection, map.projection);
        map.setCenter(lonlat, 5);

        map.addControl( new OpenLayers.Control.LayerSwitcher());
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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