[gdal-dev] OGR2OGR - Define output naming from concatenated
queries from a DB
Mateusz Loskot
mateusz at loskot.net
Thu Aug 7 11:42:03 EDT 2008
D wrote:
> Hi,
>
> I have a question about the usage of OGR2OGR in defining an ESRI Shapefile
> output name. I am exporting Spatial data from Oracle Spatial (11g) from a
> single table to an ESRI Shapefile and would like to get the following naming
> syntax for my Shapefile:
>
>
> [select distinct FIELD1 from SHEMA.TABLE][select distinct FIELD2 from
> SHEMA.TABLE][fixed value -> 01]
>
> .. the output would look like
>
> 50000002806200701.shp
> 50000002806200701.shx
> 50000002806200701.dbf
>
> The naming parts/chunks that are concatenated here are actually queries in
> the source database (Oracle).
D,
It's not possible to get it done with ogr2ogr only. You need to write a
script.
> Any examples (sample scripts, procedures) or hints on how to implement this,
> would be very helpful.
Here you have a prototype of how it can be solve with Python:
#################################
import os
import cx_Oracle
connstr = 'system/pantera at localhost'
conn = cx_Oracle.connect(connstr)
cur = conn.cursor()
# build your SQL queries
cur.execute('SELECT DISTINCT NAME FROM TEST_POINTS')
row = cur.fetchone()
i = 0
while row is not None:
# generate filename
prefix = row[0]
name = prefix + '_%02d' % i
# call ogr2ogr and pass the generate name as output file name
os.system('ogr2ogr -f "ESRI Shapefile" %s.shp ....' % name)
...
# read next record
row = cur.fetchone()
i = i + 1
if cur is not None:
cur.close()
if conn is not None:
conn.close()
#################################
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
More information about the gdal-dev
mailing list