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.

I am experiencing projection problems with the following set up:

  • GeoServer with ESPG:4326 based shapefiles (*.shp)
  • OpenJump to edit my shapefiles
  • Openlayers with EPSG:900913 base layers
  • GeoServer provides the shapefiles as WMS to OpenLayers.

Here is my source code:

<html>
<head>
    <title>Openplanning mit Geoserver</title>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <script type='text/javascript' src='http://www.openlayers.org/api/OpenLayers.js'></script>

</head>

 <body>
    <div id="map-id"></div>
        <script>
            var geographic = new OpenLayers.Projection("EPSG:4326");
            var mercator = new OpenLayers.Projection("EPSG:900913");

            var world = new OpenLayers.Bounds(-180, -89, 180, 89).transform(
                geographic, mercator
            );
            var vienna_center = new OpenLayers.LonLat(16.3670, 48.205333).transform(
                geographic, mercator
            );

            var options = {
                projection: mercator,
                displayProjection: geographic,
                units: "m",
                maxExtent: world,
                maxResolution: 156543.0399
            };

            var map = new OpenLayers.Map("map-id",options);

            var osm = new OpenLayers.Layer.OSM();

            map.addLayer(osm);

            var vienna = new OpenLayers.Layer.WMS(
                "Vienna Calling",
                "http://localhost:8888/geoserver/wms?",
                {layers: "topp:ma_vienna", 
                transparent: true}
            );
            map.addLayer(vienna);
            map.setCenter(vienna_center, 8);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            //zeigt die Koordinaten der aktuellen Mause-Position an
            map.addControl(new OpenLayers.Control.MousePosition());

            map.addControl(featureInfo);
            featureInfo.activate();
        </script>
    </div>
 </body>
 </html>

It seems that GeoServer is converting from ESPG:4326 to EPSG:900913 internally. Here you can see a sample request for Vienna (which is sent by my OpenLayers application to GeoServer):

http://localhost:8888/geoserver/wms?LAYERS=topp:ma_vienna&SRS=EPSG:900913&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image/png&BBOX=1800244.8899219,6116147.6705496,1839380.6483984,6155283.4290261&WIDTH=256&HEIGHT=256

My problem: the requested file looks distored, as you can see here:

http://i.stack.imgur.com/UcWBQ.png (sorry, I had to post a link again after my edit ...)

In case I open the WMS layer in the OpenLayers preview of GeoServer, it looks ok:

http://i.stack.imgur.com/P8IMj.png (sorry, I had to post a link again after my edit ...)

The question is: Why is my shapefile distorted in my OpenLayers application, but not in the GeoServer preview? As you can see, the GeoServer preview uses EPSG:4326 and my OpenLayers application EPSG:900913 (Update: EPSG:4326 as well; mouse coordinates are displayed as latitude/longitude). But, however, as GeoServer provides a WMS interface with EPSG:900913 capabilities, shouldn't it correctly reproject my vector sources?

Thanks for you replies in advance, Rainer.

share|improve this question
1  
Are you sure your shapefile data in geographic coordinates (degrees)? And mouse coordinates are not always connected with layer projection, for set projection for display mouse position option displayProjection is used –  drnextgis Nov 25 '11 at 2:11
add comment

1 Answer 1

The first thing to check is that your data is really in 4326 (lat/lon) and that GeoServer is reading them in in that projection - check on the DataStore page for "Native Projection" if that is unknown then go to http://prj2epsg.org/search and paste in the contents of your shapefile .prj file, this will give you a correct projection to put in the projection box.

If your shapefile doesn't have a .prj file then you need to go back to the data supplier and ask them what projection the data is in.

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.