[gdal-dev] Autodetect "0012" as string in CSV
Rahkonen Jukka (MML)
jukka.rahkonen at maanmittauslaitos.fi
Fri Aug 18 04:53:17 PDT 2017
Hi Even,
Yeah, should have been reading the documents more closely. This keeps the leading zeroes.
ogrinfo csvtext.csv -oo autodetect_type=yes -oo quoted_fields_as_string=yes -al
INFO: Open of `csvtext.csv'
using driver `CSV' successful.
Layer name: csvtext
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
field_1: String (0.0)
field_2: Integer (0.0)
field_3: Integer (0.0)
field_4: Real (0.0)
field_5: String (0.0)
OGRFeature(csvtext):1
field_1 (String) = 00012
field_2 (Integer) = 12345
field_3 (Integer) = 1234
field_4 (Real) = 234.65
field_5 (String) = text
-Jukka-
________________________________
Lähettäjä: Even Rouault <even.rouault at spatialys.com>
Lähetetty: 18. elokuuta 2017 14:30
Vastaanottaja: gdal-dev at lists.osgeo.org
Kopio: Rahkonen Jukka (MML)
Aihe: Re: [gdal-dev] Autodetect "0012" as string in CSV
On vendredi 18 août 2017 10:59:47 CEST Rahkonen Jukka (MML) wrote:
> Hi,
>
> The schema of a CSV file like this
> "00012",012345,1234,234.65,"text"
> is autodetected this way:
>
> ogrinfo csvtext.csv -oo autodetect_type=yes -al
> INFO: Open of `csvtext.csv'
> using driver `CSV' successful.
>
> Layer name: csvtext
> Geometry: None
> Feature Count: 1
> Layer SRS WKT:
> (unknown)
> field_1: Integer (0.0)
> field_2: Integer (0.0)
> field_3: Integer (0.0)
> field_4: Real (0.0)
> field_5: String (0.0)
> OGRFeature(csvtext):1
> field_1 (Integer) = 12
> field_2 (Integer) = 12345
> field_3 (Integer) = 1234
> field_4 (Real) = 234.65
> field_5 (String) = text
>
> It would be good to autodetect also "00012" as a string. Double quotes are
> correctly stripped of from "text" so I suppose that GDAL already knows that
> they are used for enclosing strings.
Jukka,
Add -oo QUOTED_FIELDS_AS_STRING=YES
I don't remember the rationale for the default of this option to be NO. Presumably the use case while developping that was with a file generated by a CSV exporter always surrounding field content by double quotes.
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170818/5a929afd/attachment.html>
More information about the gdal-dev
mailing list