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.

Is it possible to show geodata by OpenLayers in custom projection?

I want to show my geodata in OpenLayers interface.

Source layer(s): shape-file(s), standard epsg:4326 lon/lat projection; processed by Mapserver (WMS Layers).

Result map: Albers Conic Equal Area projection, with specific central meridian (It has no EPSG code).

Definition in PROJ.4 format:

+proj=aea +lat_1=52 +lat_2=64 +lat_0=0 +lon_0=93 +x_0=16500000 +y_0=0 +ellps=krass +units=m +towgs84=28,-130,-95,0,0,0,0 +no_defs

As to Mapserver Layers – they are all well, I can show geodata through standard Mapserver CGI template-based interface, in this custom Albers projection…

For OpenLayers I tried to define Proj4js.defs –

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="ol/style.css" type="text/css" />
<style type="text/css">
    #map {
        width: 800px;
        height: 500px;
        border: 1px solid black;
    }
    #mouse-position-meters,
    #mouse-position-4326 {
        float: left;
        clear: left;
    }
    #shortdesc {
        margin-bottom: .5em;
        clear: left;
    }
</style>
<script src="lib/OpenLayers.js"></script>
<script src="lib/proj4js-compressed.js"></script>
<script type="text/javascript">
Proj4js.defs["USER:00001"] = "+proj=aea +lat_1=52 +lat_2=64 +lat_0=0 +lon_0=93 +x_0=16500000 +y_0=0 +ellps=krass +units=m +towgs84=28,-130,-95,0,0,0,0 +no_defs";
    function init(){
        map = new OpenLayers.Map('map', {
        projection: 'USER:00001',
        maxResolution: 'auto',
        units: 'm',
        controls: [
                new OpenLayers.Control.PanZoomBar(),    
                new OpenLayers.Control.Navigation(),
            new OpenLayers.Control.MousePosition({
                div: $('mouse-position-meters'),
                prefix: 'Coords: (',
                suffix: ') m (ALBERS).'
            }),
            new OpenLayers.Control.MousePosition({
                div: $('mouse-position-4326'),
                displayProjection: new OpenLayers.Projection('EPSG:4326'),
                prefix: 'Coords: (',
                suffix: ') dd (EPSG:4326).'
            })
        ],
        maxExtent: new OpenLayers.Bounds(12460000, 4870000, 20540000, 9500000)
    });
    var rus_general = new OpenLayers.Layer.MapServer('Russian Regions', 
        'http://localhost/cgi-bin/mapserv.exe',
    {map: 'C:/OSGeo4W/apache/htdocs/test/z-albers.map', layers: 'rus_general'}
        );
    map.addLayer(rus_general);
    map.zoomToMaxExtent();
        map.addControl(new OpenLayers.Control.LayerSwitcher() );
    }
</script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers Test</h1>
<div id="map" class="smallmap"></div>
<div id="mouse-position-meters"></div>
<div id="mouse-position-4326"></div>
</body>
</html>

It seems that the presented coordinate transformation works correctly (displaying the appropriate numbers when I move the mouse), but the map does not appear…

How can I do this?

====================

Discussion of the problem & Answer to the question --
It looks like I found the answer myself...
(The above source code has been corrected, and already has a working version)

I changed WMS-layer upon layer of MapServer type

Original (non-working) version was:

...
    var rus_general = new OpenLayers.Layer.WMS( 'Russian Regions', 
        'http://localhost/cgi-bin/mapserv.exe?map=C:/OSGeo4W/apache/htdocs/test/z-albers.map', 
    {layers: 'rus_general'}
        );
...

In this case, the bottleneck - WMS-service: I do not know how to specify a custom (non-EPSG) projection in this case ...
This is not a problem for the Mapserver layer type. Mapserver generates a map projection with PROJECTION section in the MAP-file. There are no restrictions such as "EPSG Only"...

Thank you all.

share|improve this question

closed as too localized by underdark Nov 28 '12 at 21:38

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Is this your full code? I don't see where you add a single base or overlay layer. –  Vadim Sep 28 '12 at 17:53
    
No, it is only part of the code .. –  Yakubailik Sep 29 '12 at 17:40
    
You shoul add your custom projection to epg file. Open your epsg file in a text editor and edit it. On Windows, the default location of the epsg file is c:\proj\nad. MS4W users will find the epsg file in \ms4w\proj\nad. –  drnextgis Oct 1 '12 at 2:20
    
Have you solved this? –  Plux Feb 24 at 14:59

1 Answer 1

Your code seems right. you have included proj4js because it is needed for projections other than 900913 and 4326 but, where is the OpenLayers.Layer.WMS pointing to your WMS server?


OpenLayers Cookbook can help you

share|improve this answer
    
Thanks for the link. I am very detail overlooked this book. Unfortunately, there does not discuss details on the custom projections... I really just gave a code snippet. Details are provided below. –  Yakubailik Sep 29 '12 at 17:38

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