[gdal-dev] OGR2OGR - Define output naming from concatenated queries from a DB

D eloquence2 at gmail.com
Thu Aug 7 11:48:26 EDT 2008


Hi Mateusz,

thanks for the help and the sample! I will try to implement it. I have also
received a sample from an Oracle DBA how to create a Batch file with a
properly defined command line while executing an SQL script with some PL/SQL
procedures.

If interested, I will send it to you, when completed developing and testing
it.

Best regards,

Dejan

On Thu, Aug 7, 2008 at 5:42 PM, Mateusz Loskot <mateusz at loskot.net> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20080807/63c08c12/attachment.html


More information about the gdal-dev mailing list