[Qgis-user] csv import issue

Sitansu B Pattnaik sitansubp at yahoo.com
Mon Sep 9 08:00:20 PDT 2013


Hi,
Not sure if you have tried this:
CSVT file: For formatting data input
.csvt file along with .csv file
 
The OGR CSV driver
supports reading and writing. Because the CSV format has variable length text
lines, reading is done sequentially. Reading features in random order will
generally be very slow. OGR CSV layer never have any coordinate system. When
reading a field named "WKT" is assumed to contain WKT geometry, but
also is treated as a regular field. The OGR CSV driver returns all attribute
columns as string data types if no field type information file (with .csvt
extension) is available.
 
Limited type
recognition can be done for Integer, Real, String, Date (YYYY-MM-DD), Time
(HH:MM:SS+nn) and DateTime (YYYY-MM-DD HH:MM:SS+nn) columns through a
descriptive file with the same name as the CSV file, but a .csvt extension. In
a single line the types for each column have to be listed with double quotes
and be comma separated (e.g., "Integer","String"). It is
also possible to specify explicitly the width and precision of each column,
e.g. "Integer(5)","Real(10.7)","String(15)". The
driver will then use these types as specified for the csv columns.

Source:  <http://www.gdal.org/ogr/drv_csv.html>
 

 
 Sitansu Pattnaik 

www.kcubeconsulting.com  


----- Original Message -----
From: Chris Crook <ccrook at linz.govt.nz>
To: "qgis-user at lists.osgeo.org" <qgis-user at lists.osgeo.org>
Cc: 
Sent: Sunday, September 8, 2013 12:43 AM
Subject: Re: [Qgis-user] csv import issue

Hi Telmo

You have a good point, at the moment there is no easy way to define data types for delimited text provider fields and it is has caused issues for other users too.  The delimited text provider (ex plugin) in QGIS will support the csvt file in 2.0, which at least provides a direct way of specifiying data types without a workaround.

If you are repeatedly using the same type of data, then all you need to do is to copy the same csvt file for each one (just renaming it to match the data file).  But I agree it is an extra step.

I don't thing using quoting as a way of determining data type is safe is we can't be sure that numeric data won't be quoted - quoting is about formatting the file, not about data type. It could be an option, but that might just get confusing.  I think that simply being able to select the data type for fields in the dialog is a better way to go, and is consistent with other software..  maybe in 2.1 :-)

Cheers
Chris

> I have a recurrent issue when loading csv files.
> When one of the fields is a text field only with numeric characters qgis
> allways imports that field as numeric. You might ask why would I want a
> field with numeric characters to be a text field, and the answer is that
> one dataset I usually use, the administrative regions regions are codedH
> with numeric characters as text...for example 011312 that is converted to
> 11312 even if the values in the csv file have the quote markers (" or ')
> and I define that on the csv import dialog (see below a csv example)
>
> I have found diferent workarround solutions for this issue like:
>
> - converting the code on the original shapefile to numeric
> - importing the csv to a database and loading from the database
> - creating a dummy record where i put a letter character in that field
>
> They all work, but is just annoying to do this over and over and adds some
> unecessary steps in the data analysis workflow (for example when importing
> a satscan gis file output to map the clusters). My question is:
>
> - Am I missing something here?
> - If not, is it possible to fix that?
>
> Below is a portion of a csv file, if you manage to import the file and
> keep the LOC_ID field as text please let me know.
>
>
> 'ID';'LOC_ID';'CLUSTER';'P_VALUE';'CLU_OBS';'CLU_EXP';'CLU_ODE';'CLU_RISK';'LOC_OBS';'LOC_EXP';'LOC_ODE';'LOC_RISK'
> 1;'070105';1,00;1,0e-17;283,00;72,06;3,92;13,44;0,00;0,00;0,00;0,00
> 2;'070101';1,00;1,0e-17;283,00;72,06;3,92;13,44;0,00;2,58;0,00;0,00
> 3;'070103';1,00;1,0e-17;283,00;72,06;3,92;13,44;0,00;2,72;0,00;0,00
> 4;'071002';1,00;1,0e-17;283,00;72,06;3,92;13,44;47,00;3,12;15,03;17,07
>
> My best regards
>
> Telmo Nunes
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>


This message contains information, which is confidential and may be subject to legal privilege. If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message. LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ. Thank You.
_______________________________________________
Qgis-user mailing list
Qgis-user at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user




More information about the Qgis-user mailing list