简体   繁体   中英

Importing GeoJSON into leaflet with coordinates n CRS epsg:3857

Please bear with me as I am fairly new to this whole maps things

I have a geojson file with the coordinates given in the epsg:3857 format

{"name":"2011","type":"FeatureCollection"
,"crs":{"type":"name","properties":{"name":"EPSG:3857"}}
,"features":[{  "type":"Feature",
        "geometry": {"type":"Polygon", "coordinates":[[[16455748.301877,-4074559.33797376],[16455757.520912,-4074683.80559603],[16455834.5041285,-4074749.65646613]]]},
        "properties":{"CODE":"LGA12200","LGA_NAME":"Cootamundra (A)","STATE_CODE":"1","STATE_NAME":"New South Wales","AREA_SQKM":1523.75245790713}
    }
    ]
}

When I import this into leaflet using L.geojson(....), the polygon is formed off the map... I know that this is because the coordinates are in the EPSG:3857..

How do I convert these to lat long coords when I import them?

There are around 100 features in the geojson file

my code to import the json file is:

$.getJSON("js/output1.json", function (data) {

    // create geojson object
    L.geoJson(data).addTo(map);
}

You should convert the coordinates before you import them with L.geojson. Find an algorithm that does this conversion, create a parser for your geoJSON and generate a new one with the converted coordinates. Then load them with L.geoJson.

Of course you should do this on the server side, but if you only have the geoJSON file than this is the way.

Upload your geo-file in QGIS and then switch the projection to projection is EPSG:3857. Re-save the geo-file in geoJson,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM