Opened 8 years ago

Closed 8 years ago

#4824 closed defect (fixed)

Creating another CSV file into directory with invalid CSV file fails

Reported by: Jukka Rahkonen Owned by: warmerdam
Priority: normal Milestone: 1.9.2
Component: OGR_SF Version: unspecified
Severity: normal Keywords: csv
Cc:

Description

Ogr2ogr with CSV driver does not create a new file if there is already at least one file with .csv extension in the directory.

Create a CSV file without problem

F:\OSM_data>ogr2ogr -f csv -dialect SQLITE poi.csv finland.osm.pbf -sql "select
amenity from points where amenity is not null" -spat 24.821 60.123 25.259 60.317
-debug on
layer names ignored in combination with -sql.

Trial to create another CSV file fails

F:\OSM_data>ogr2ogr -f csv -dialect SQLITE poi2.csv finland.osm.pbf -sql "select
 amenity from points where amenity is not null" -spat 24.821 60.123 25.259 60.31
7-debug on
csv driver failed to create poi2.csv

The latter command works after deleting all existing .csv files from the directory

F:\OSM_data>del *.csv

F:\OSM_data>ogr2ogr -f csv -dialect SQLITE poi2.csv finland.osm.pbf -sql "select
 amenity from points where amenity is not null" -spat 24.821 60.123 25.259 60.31
7-debug on
layer names ignored in combination with -sql.

Tested on Windows Vista 32-bit with GDAL version r24962, MSVC2010 build.

Change History (3)

comment:1 Changed 8 years ago by Jukka Rahkonen

More information: ogrinfo does not recognise the CSV file created with simple "select amenity from..

F:\OSM_data>ogrinfo poi.csv
FAILURE:
Unable to open datasource `poi.csv' with the following drivers.

If I create the first CSV file as "select * from points..." ogrinfo finds it

F:\OSM_data>ogrinfo poi.csv poi -so
INFO: Open of `poi.csv'
      using driver `CSV' successful.

Layer name: poi
Geometry: None
Feature Count: 9272
Layer SRS WKT:
(unknown)
osm_id: String (0.0)
amenity: String (0.0)
name: String (0.0)
barrier: String (0.0)
highway: String (0.0)
ref: String (0.0)
address: String (0.0)
is_in: String (0.0)
place: String (0.0)
man_made: String (0.0)
other_tags: String (0.0)

Now creating the next CSV succeeds.

comment:2 Changed 8 years ago by Even Rouault

Ah ok, I understand the issue better. The CSV driver cannot recognize a CSV file with a single column, but it can generate them. So the first ogr2ogr produces an invalid CSV file, that prevents following CSV files from being created in the same directory.

comment:3 Changed 8 years ago by Even Rouault

Component: defaultOGR_SF
Keywords: csv added
Milestone: 1.9.2
Resolution: fixed
Status: newclosed
Summary: Creating another CSV file into directory failsCreating another CSV file into directory with invalid CSV file fails

trunk r24965 "CSV: allow creating a new .csv file in a directory where there are invalid .csv files; use a trick so that the CSV driver creates valid single column files (#4824)"

branches/1.9 r24966 "CSV: allow creating a new .csv file in a directory where there are invalid .csv files; use a trick so that the CSV driver creates valid single column files (#4824)"

Note: See TracTickets for help on using tickets.