To convert TopoJSON files to Shapefiles using ogr2ogr
you'll need to install the geojson-cli
package for Node.js using the Node Package Manager (NPM). You can follow the instructions below or read this article on installing both.
# If you need to install Node and NPM...
wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz
tar -xzvf node-v0.10.24.tar.gz && rm node-v0.10.24.tar.gz && cd node-v0.10.24
./configure
sudo make
sudo make install
# For installing NPM...
wget https://npmjs.org/install.sh
source install.sh
# Finally, install the geojson-cli
sudo npm install -g geojson
With the geojson-cli
installed, you can convert your TopoJSON back into GeoJSON, which can then be converted to a Shapefile using ogr2ogr
.
# Automatically makes a file with ".topo" removed in filename
geojson my.topo.json
ogr2ogr -f "ESRI Shapefile" my.shp my.json
Alternatively, you can convert your TopoJSON to GeoJSON and back again using this handy web client.
If you just need to convert that file, take a look in the JSON for the BorderText attribute. That's the Well Known Text version of the border:
MULTIPOLYGON (((14.3433288676297 50.0848527027202, 14.3446421202828 50.0846995307187, 14.3448521702545 50.0847861746278, 14.3452308586668 50.0853115978675, 14.3449545937579 50.0856219793441, 14.3445904744911 50.0857306463445, 14.344515321968 50.0856213001745, 14.3431047456068 50.0851438479227, 14.3433288676297 50.0848527027202)))
You can then copy that and go to Geometry Inspector and paste it in the WKT textbox. Click any other textbox and it will convert it to GeoJSON and EsriJSON.
You can convert the EsriJSON with Esri tools, or copy the GeoJSON, paste it in GeoJSON.io, and then under the Save
menu there's an option to download the data as a shapefile.
If you want something a bit more streamlined, you could chain together cURL, JQ, and ogr2ogr to something like:
curl http:/your/url | jq ".BorderText" | ogr2ogr outfile.shp /vsistdin/
Best Answer
It's not possible to do with pure JavaScript as it creates 3 binary files. Your best bet would be to setup a OGR web service that would take json in parameter and output a zipped SHP. Look at Ogre, it may help:
http://ogre.adc4gis.com/
EDIT:
I didn't test it myself, but it is indeed now possible to save shapefile from javascript:
https://github.com/mapbox/shp-write