Having a good world dataset is kind of essential for most GIS users to have as a standard reference dataset, give context to maps and so on. Anita Graser’s recent blog post about the Natural Earth Data project added another nice dataset to my world dataset collection. The Natural Earth Data set (I got the ‘full’ one) is provided as shapefiles. Of course as a PostGIS fan I’d rather have these in my geospatial database, so I wrote a one liner in bash to load all the datasets.
First download the full dataset from here, and then extract the contents into a working directory somewhere. Then simply run this line, adjusting your destination database and schema as needed:
for FILE in `find . -name *.shp`; do \ BASE=`basename $FILE .shp`; \ /usr/lib/postgresql/9.1/bin/shp2pgsql -s 4326 -I $FILE world.$BASE \ | psql gis; done
Ok that looks like four lines above, but only because I added some line breaks so things would be readable on this blog.
Note that you should replace ‘world’ with the name of the schema you are importing the data into, and ‘gis’ with the name of the database you are importing your data into. Thanks for the awesome dataset Natural Earth Team!