67

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?

chrki
  • 5,626
  • 6
  • 28
  • 51
minimalpop
  • 6,718
  • 13
  • 64
  • 80
  • 1
    Also you can try to use http://techslides.com/demos/mapping/shapefile-geojson-converter.html It is online and works fine for me. – gis_wild Jan 27 '13 at 22:17

5 Answers5

93

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, ...
  ...
Brian Burns
  • 14,953
  • 5
  • 69
  • 59
sgillies
  • 2,151
  • 14
  • 9
46

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

dassouki
  • 5,921
  • 7
  • 47
  • 79
31

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...)

Giorgio
  • 11,673
  • 12
  • 42
  • 72
  • Why you have passed the shapefile's name without any extension (highlighted with bold) as last parameter in the following command? ogr2ogr -f "GeoJSON" /tmp/world.json world_borders.shp **world_borders** – JayeshMori Aug 31 '12 at 00:29
  • Thank you for this link. I was able to take a series of shape file outputs and convert them to GeoJSON instantly. – uadrive May 14 '13 at 03:07
  • This was the easiest solution for me. Thanks for the link. – ShadeTreeDeveloper Jul 19 '13 at 12:36
  • 1
    link is now dead (404), try http://converter.mygeodata.eu/ although the tool didn't work for me – sham Apr 09 '15 at 22:16
7

This online converter worked for me

http://mapshaper.org/

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

iYazee6
  • 758
  • 10
  • 20
3

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.

TheSteve0
  • 3,493
  • 1
  • 17
  • 24