[OpenLayers-Users] geosjon format with epsg other than 4326

Steve.Toutant at inspq.qc.ca Steve.Toutant at inspq.qc.ca
Fri Oct 11 13:03:12 PDT 2013


Thanks Julien
I just had a look at the read function of format.geojson and crs is not 
read.
this.externalProjection  has to be defined in the format.

There is 
if (this.internalProjection && this.externalProjection && !collection) {
            geometry.transform(this.externalProjection, 
                               this.internalProjection); 
        }

My idea is to set the externalProjection by a function
var geojson_format = new OpenLayers.Format.GeoJSON({
        'internalProjection': map.getProjectionObject(),
        'externalProjection': getGeojsonProjection(request.responseText)
});
function getGeojsonProjection( geojson )
{
        //parse the json for CRS code and create the projection, if no CRS 
return 4326
        ......

        //Example: return new OpenLayers.Projection("EPSG:32198");
}

That will work if all the features are ine the same projection.
Perhaps someone as a better idea?
many thanks
steve





Julien-Samuel Lacroix <jlacroix at mapgears.com>@lists.osgeo.org 
Envoyé par : openlayers-users-bounces at lists.osgeo.org
2013-10-11 15:41

A
openlayers-users at lists.osgeo.org
cc

Objet
Re: [OpenLayers-Users] geosjon format with epsg other than 4326








Hi,

Others may be able to give you more info on this one, but...

If I recall correctly there was a long discussion on the GeoJSON 
mailing-list [1] on the usability of this CRS tag. I think that the 
conclusion was to remove it from GeoJSON, other may correct me if I'm 
wrong. So don't plan on it. Are you in control of this data and service? 
maybe it could return you a WFS. Or maybe a GetCapabilities to the data 
server would tell you the projection before you receive the GeoJSON.

This is a tricky one, I agree.


[1] 
http://lists.geojson.org/pipermail/geojson-geojson.org/2013-May/thread.html


Julien


On 13-10-11 11:09 AM, Steve.Toutant at inspq.qc.ca wrote:
> Hi,
>
> Sometimes I receive geojson from a wps service in different projection
> than 4326. I manage it like this for example
> geojson_format = new OpenLayers.Format.GeoJSON({'internalProjection':
> map.getProjectionObject(),'externalProjection': new
> OpenLayers.Projection("EPSG:32198")});
>
> It works but 32198 is hardcoded, and I don't know when the epsg will be
> different.
>
> I read that if different than 4326, the geojson should have a crs tag as
> defined here
> http://geojson.org/geojson-spec.html#named-crs
>
> Someone has defined a new OpenLayers.Format.GeoJSON that can read this
> tag and set the externalProjection code?
>
> thanks
> steve
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>

-- 
Julien-Samuel Lacroix
Mapgears
http://www.mapgears.com/
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20131011/c181668c/attachment.html>


More information about the Users mailing list