将 shapefile (.shp) 转换为 xml/json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2223979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert a shapefile (.shp) to xml/json
提问by minimalpop
I'm working with a shapefile (.shp, .dbf, etc) and would like to convert it to xml. I'm on a mac, and I'm having trouble finding an application that will help me with the conversion. Does anyone know of a method for converting this file format into an xml file?
我正在使用 shapefile(.shp、.dbf 等)并希望将其转换为 xml。我使用的是 mac,但找不到可以帮助我进行转换的应用程序时遇到了麻烦。有谁知道将这种文件格式转换为 xml 文件的方法?
回答by sgillies
What dassouki said. Get GDAL from http://www.kyngchaos.com/software:frameworks. Use it to convert a shapefile to GeoJSONlike this:
达苏希说的。从http://www.kyngchaos.com/software:frameworks获取 GDAL 。使用它来将 shapefile 转换为GeoJSON,如下所示:
$ ogr2ogr -f "GeoJSON" output.json input.shp
eg
例如
$ ogr2ogr -f "GeoJSON" /tmp/world.json world_borders.shp world_borders
$ cat /tmp/world.json
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "CAT": 1.000000, "FIPS_CNTRY": "AA",
"CNTRY_NAME": "Aruba", "AREA": 193.000000, "POP_CNTRY": 71218.000000 },
"geometry": { "type": "Polygon", "coordinates": [ [ [ -69.882233, ...
...
回答by dassouki
回答by Giorgio
I've found this website that converts loads of Geo formats: http://mygeodata.eu/apps/converter/index_en.html
我发现这个网站可以转换大量的地理格式:http: //mygeodata.eu/apps/converter/index_en.html
In less than 2 minutes I was able to convert a ShapeFile zip to a GeoJson file!
在不到 2 分钟的时间内,我就能够将 ShapeFile zip 转换为 GeoJson 文件!
(I was trying GDAL at the same time and it's still downloading...)
(我同时在尝试 GDAL,它仍在下载......)
回答by iYazee6
This online converter worked for me
这个在线转换器对我有用
I uploaded my .shp file, Then exported it to GeoJson.
我上传了我的 .shp 文件,然后将其导出到 GeoJson。
回答by TheSteve0
I can also offer a very round about answer.
我也可以提供一个非常全面的答案。
Put geoserver on your machine (you can download a self contained zip file)
将 geoserver 放在您的机器上(您可以下载一个自包含的 zip 文件)
Set up a datastore that points to your shapefile.
设置指向 shapefile 的数据存储。
Set up a layer that points to your datastore
设置一个指向您的数据存储的层
Go to the preview layers page and ask for a WFS as GML preview
转到预览图层页面并要求提供 WFS 作为 GML 预览
Voila - an xml representation of your shapefile.
瞧 - 你的 shapefile 的 xml 表示。

