Ogr2ogr is the swiss-army knife when it comes to conversion of GIS data. It is part of the Geospatial Data Abstraction Library and provides an easy way to convert data between common storage formats: GeoJSONShapefile, PostGIS and others.

Ogr2ogr is available as part of the FW Tools Toolkit: http://fwtools.maptools.org/. It is usually called from the command line using the following syntax:

> ogr2ogr -f "file_format" destination_data source_data


Here are a few examples:

Convert GeoJSON to PostGIS:

> ogr2ogr -f "PostgreSQL" PG:"dbname=my_database user=postgres" "source_data.json"

If we want to specify a destination table, we can use the -nln table option. In order to append the new data to the already existing records, we can use the -append flag:

> ogr2ogr -f "PostgreSQL" PG:"dbname=my_database user=postgres" "source_data.json" -nln destination_table -append


Convert GeoJSON to ESRI Shapefile:

> ogr2ogr -f "ESRI Shapefile" destination_data.shp "source-data.json"


 Convert Shapefile to PostGIS:

> ogr2ogr.exe -f "PostgreSQL" PG:"dbname=my_database user=postgres" "source_data.shp" -skip-failures



4 thoughts on “Using ogr2ogr to convert data between GeoJSON, PostGIS and Esri Shapefile

  1. Joseph Spenner says:

    When trying to convert GeoJSON to PostGIS or GeoJSON to ESRI Shapefile, I get an error after several seconds:


    Is there a timeout somewhere I can set? It’s a large JSON file.


  2. Morphocode says:


    To convert a PostGIS table to a shapefile, you can use the following command:
    ogr2ogr -f “ESRI Shapefile” buildings_mn.shp “PG:host=localhost dbname=nyc user=postgres password=password” “buildings_mn”

    where “buildings_mn” is the name of your db table


Leave a Reply

Your email address will not be published. Required fields are marked *