Converting a Shapefile to a PostGIS table using ogr2ogr

The simplest way to transform data from one format to another is to directly use the ogr2ogr tool that comes with the installation of GDAL. This powerful tool can convert over 200 geospatial formats. In this solution, we will execute the ogr2ogr utility from within a Python script to perform generic vector data conversions. The Python code is, therefore, used to execute this command-line tool and pass around variables so that you can create your own scripts for data imports or exports.

Using this tool is also recommended if you are not really interested in coding too much and simply want to get the job done to move your data. A pure Python solution is, of course, possible, but it's definitely ...

Get Python Geospatial Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.