I am using gdal and ogr2ogr to perform a SQL query on a database of shapefiles with the code below. The geoprocessing works and the appropriate shapefile is extracted from the query, but when I print boundary it shows 0 and the .cpg and .xml files are missing after the geoprocessing is completed. I also a get a warning: Value of field SHAPE_Area of feauture 0 not successfully written. Possible due to too larger number with respect to field width

import gdal
import subprocess

directory = r"E:\IrrigatedLands\FC_test\Water_Districts\Water_Districts.shp"
output_shp = r"E:\IrrigatedLands\FC_qgis\boundary.shp"

boundary = subprocess.call(["ogr2ogr", "-where", "NAME = 'Cache La Poudre River'", output_shp, directory])

print boundary
  • Did you manage to open the output shape file ? – Shiko Apr 15 '16 at 6:28
  • What is the version of your ogr2ogr? At least new versions do write .prj. If the source projection is not recognised automatically adding -a_srs epsg:xxxx may help. – user30184 Apr 15 '16 at 6:32
  • when adding "-a_srs", "epsg:xxxx" before "-where" and after "ogr2ogr" the following error is shown: failed to lookup OUM code 0 – brgionta Apr 15 '16 at 7:20
  • I did not mean xxxx literally. Use the code of your projection, like EPSG:4326. – user30184 Apr 15 '16 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.