Convert a shapefile (.shp) to xml/json

蹲街弑〆低调 提交于 2019-11-29 18:42:57
sgillies

What dassouki said. Get GDAL from http://www.kyngchaos.com/software:frameworks. Use it to convert a shapefile to GeoJSON like this:

$ 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, ...
  ...

GDAL is your friend. Use the ogr2ogr libraries, and here's a cheat sheet.

If you want a good GIS application, install QGIS and download the gdal converter plugin

I've found this website that converts loads of Geo formats: 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!

(I was trying GDAL at the same time and it's still downloading...)

This online converter worked for me

http://mapshaper.org/

I uploaded my .shp file, Then exported it to GeoJson.

I can also offer a very round about answer.

Put geoserver on your machine (you can download a self contained zip file)

Set up a datastore that points to your shapefile.

Set up a layer that points to your datastore

Go to the preview layers page and ask for a WFS as GML preview

Voila - an xml representation of your shapefile.

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