PostGIS Commands in Arcpy

Most of you know, I love spatial SQL. I also love PostGIS and ArcGIS – can’t we just all get along? Well, yes we can. In this case, Python becomes the great mediator.

Check out this video where I analyze data from an ESRI shapefile using Arcpy, call PostGIS to run a procedure on the data using the psycopg2 package, and return the results.

In this case, I am trying to compute the distance between points and line in meters, but the data is in Lat/Lon. So, I am bringing PostGIS into the mix because it does a very good job of returning distances between points and lines.

Now, you can do all of this in Arcpy directly by getting the geometry object:

but, my point here was to show that you can move along with an Arcpy script, take a short and painless detour to use PostGIS, and then get back to your Arcpy script (assuming that PostGIS does something that you are really interested in using).

want to learn more about how to program with Python, Arcpy, and PostGIS? Check out my courses on ongisadvisor.com.