Friday 30 September 2016

postgis - How to run shp2pgsql in python without reporting every row loaded?


I'm running shp2pgsql in python with a simple script, which works just fine:


import os
import subprocess

cmd = 'shp2pgsql -s 4326 ../data/shp/statistical_neighborhoods.shp temp_table | psql -h hostname -d databasename -U username'


subprocess.call(cmd, shell=True)

The problem is, for every record loaded, there is a message reported:


INSERT 0 1

That message is reported for the 78 records in the neighborhoods layer in the example above, but for a file with 280,000 records (address point file from the City, or Parcels layer), that would be a very unnecessary amount of messages.


Is this problem coming from shp2pgsql, or is it a result of the subprocess.call() function?



Answer



To avoid a message from subprocess.call when psql writes its informations to stdout you can simply tell psql to not write any information. The operator is -q or --quiet as taken from the psql manual.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...