6

I'm using Leaflet to transform some drawn polygons to GeoJSON and send them to a backend. But the GeoJSON objects generated by layer.toGeoJSON are like this:

{
 "type":"Feature",
 "properties":{},
 "geometry":{
    "type":"Polygon",
    "coordinates":[[[18.69873046875,51.481382896100975],[18.69873046875,51.890053935216926],[20.456542968749996,51.890053935216926],[20.456542968749996,51.481382896100975],[18.69873046875,51.481382896100975]]]
  }
 }

When I receive that GeoJSON object in the backend of my application (Django based) and create a GEOS object from it, epsg:4326 is assumed. Even when epsg:3857 is used for the map.

I know GeoJSON spec supports CRS definition, but I don't know how to include it in the GeoJSON object generated by toGeoJSON.

Any suggestion?

0

I don't have enough rep to comment on the accepted answer.

This is a link to the comment made by @johanvdw saying the CRS for all GeoJSON is epsg:4326 (WGS84) https://tools.ietf.org/html/rfc7946#section-4

8

You can just set the crs field:

object.crs =  {
  "type": "name",
  "properties": {
    "name": "epsg:3857"
    }
  }

Note however that the coordinates you give in your example really are epsg:4326 coordinates, which is also what leaflet would output by default. I don't think you need a change here.

  • Thanks! You're right. For any reason, I was thinking about epsg:3857 as a not projected CRS, what obviously isn't. Those coords are 4326, of course. Silly me! – Jorge Arévalo Dec 17 '13 at 18:43
  • 5
    As this reply just got an upvote, note 4 years later that setting a crs is no longer part of the geojson standard. You should really consider working only in epsg:4326 all the time. – johanvdw Oct 4 '17 at 19:00
  • Thanks! So, this isn't the valid response anymore. – Jorge Arévalo Oct 5 '18 at 11:06

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.