More

Where can I find country borders data in plain text format? (XML, JSON, CSV, etc)

Where can I find country borders data in plain text format? (XML, JSON, CSV, etc)


I'm trying to obtain some data representing the borders of all countries in the world. This data doesn't have to be very precise, it is to draw the countries on a computer screen. I did a bit of research and keep stumbling upon binary formats for this data to be opened in various programs and what not. Here is an example of what would be a good resource, but unusable to me.

I don't want to have to write a binary format parser if possible. So my question is two-fold:

  • Are there any resources for simplified country borders in plain text? (XML, JSON, CSV, etc)
  • If not, are there any programs where I could export the binary data found all over the web in those formats?

I would suggest downloading and installing QGIS. You can then open the file that you link to and export the data in variety of formats.

The most common format for spatial data of this type is ashapefilewhich is one of the files that you linked to (TM_WORLD_BORDERS_SIMPL-0.2.zip). The reason that it is a zipfile is that there are several associated files with a shapefile and zipping them into a folder keeps them together.

When you download and install QGIS click on this icon. Then navigate to the folder where you unzippedTM_WORLD_BORDERS_SIMPL-0.2.zipand add the fileTM_WORLD_BORDERS_SIMPL-0.2.shp. You should then see the country boundaries on your screen.

Then, right-click on the file name on the left part of the screen. There will be an optionsave-asand you can choose a variety of formats (in my screenshot I choosegeojson).


I like @celenius' answer; however, another option would be to export the the World Borders Dataset to CSV using ogr2ogr. I just downloaded your preferred dataset and ran this command with ogr2ogr --note that your script should be a single string without any line breaks. I find them easiest to write in notepad with wordwrap turned on, then I copy them into my ogr2ogr terminal:

ogr2ogr -f "CSV" "E:4_GIS1_tutorialsworldbordersWorld_wkt" "E:4_GIS1_tutorialsworldbordersTM_WORLD_BORDERS-0.3.shp" -lco "GEOMETRY=AS_WKT" -lco "LINEFORMAT=CRLF" -lco "SEPARATOR=SEMICOLON"

(CAVEAT: Copying/pasting my ogr script from the web and into your terminal won't work because the website will introduce linebreaks and ASCII character substitutions for the double-quotes. OGR will have trouble reading the script as a result. For this reason I recommend you type your adjusted script into notepad first, or directly into the terminal.)

OGR will create theWorld_wktdirectory before it performs the file format translation, so don't make that directory before running your script or you'll get an error.

Here's a snippet of the results I got:

WKT;FIPS;ISO2;ISO3;UN;NAME;AREA;POP2005;REGION;SUBREGION;LON;LAT "MULTIPOLYGON (((-61.686668 17.024441000000138,-61.73806 16.98971 "POLYGON ((2.96361 36.802216,2.981389 36.806938,3.001111 36.80971 "MULTIPOLYGON (((45.083321 39.768044000000145,45.266388 39.611107 "POLYGON ((19.436214 41.021065,19.450554 41.059998,19.513611 41.2 "MULTIPOLYGON (((45.573051000000135 40.632488,45.528881 40.606098 "MULTIPOLYGON (((11.750832 -16.75528,11.775 -16.804726,11.77 -16. "MULTIPOLYGON (((-170.542511 -14.2975,-170.546112 -14.29861,-170.

That's a snippet of Well Known Text (WKT). Very human-readable, but those strings continue to the right for a long, long way, so I didn't want to copy-in the complete records. :)

If you just want to download the CSV dataset I created, I posted it here, but I would encourage you to try this technique for yourself. If you're interested and want more info, I wrote a closely-themed blog post a few weeks ago, which you're welcome to snipe for the more salient details.


I would advise downloading Google Earth and going through the different layers in an expanded view of the layers by clicking on every single layer and expanding the tree to turn on borders and turn off whatever you don't really need as it slows down the program to have too many layers open and running. It is 3D and is very detailed and customizable as well as accurate. You can even use the flight simulator and enjoy the ride.