33

I am working on a project where it is necessary to display maps of countries and cities using d3.js.

Actually, D3 supports GeoJson format. Usually, I guess, GeoJson format is converted from some other format.

I found some places with this GeoJson data:

http://mbostock.github.com/protovis/ex/countries.js

But, this is only a list of countries, I am looking for some service or program that gives me the ability to set an ID, get this format, and convert it to GeoJson, or get it in GeoJson better.

Thanks!!

ZachB
  • 13,051
  • 4
  • 61
  • 89
todotresde
  • 1,770
  • 2
  • 19
  • 25

4 Answers4

76

Does this need to be a service? Here's how I've approached this in the past, using free/Open Source tools:

Now you have hi-res GeoJSON data.

This is a really big file, though, so you'll want to split it up. But you don't need a service for this, just static files for each country, named by ID. This would be easy enough to produce with a script in your utility of choice (Python, Ruby, node.js).

Dharman
  • 30,962
  • 25
  • 85
  • 135
nrabinowitz
  • 55,314
  • 10
  • 149
  • 165
  • 6
    To those who need a more elaborate answer: 1. Download map from Natural Earth Data. 2. Unzip and find the Shape file. 3. Drag shape file to QGIS. 4. "Layer > Save As" as above. – daCoda Feb 20 '14 at 01:03
  • faster : convert online at https://mygeodata.cloud/converter/shp-to-geojson – cyrianox Nov 04 '17 at 03:59
15

Note that, via the GDAL library, you may also use the command-line ogr2ogr to convert shapefiles. For example:

$ ogr2ogr -f geojson source_file.shp dst_file.json

will convert source_file.shp into the GeoJSON-formatted dst_file.json.

Read more here:

Convert a shapefile (.shp) to xml/json

Community
  • 1
  • 1
mjhoy
  • 461
  • 3
  • 7
3

Take a look at https://github.com/mledoze/countries

It has geoJSONs for each country. (med resolution I would say)

countries.json contain each country description including localized country names, coordinate (at which you can display the label), and capitals names.

Walfie
  • 3,376
  • 4
  • 32
  • 38
ambientlight
  • 7,212
  • 3
  • 49
  • 61
2

Some good folks made the shapefile to geojson formatter an online service.

Check the following link: http://ogre.adc4gis.com/

They even open-sourced it: http://github.com/wavded/ogre

ᐅdevrimbaris
  • 718
  • 9
  • 20