Importing GeoJSON into leaflet with coordinates n CRS epsg:3857

大憨熊 提交于 2019-12-12 01:44:24

问题


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);
}

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/25498644/importing-geojson-into-leaflet-with-coordinates-n-crs-epsg3857

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!