GeoCSV

Aus Geoinformation HSR
Wechseln zu: Navigation, Suche

Specification of the tabular file format CSV (Comma Separated Values) with an optional geometry extension!

 >> DRAFT Version 0.3 - Date of last modification: see bottom<<

Author: Stefan and contributors. (For notes and discussion see Diskussion:GeoCSV).

Introduction

GeoCSV is an extension of the "human readable", tabular file format Comma-Separated Values (CSV) and/or Tab-Separated Values (TSV). CSV/TSV are well-known but spartanic format with possible information loss.

For exchanging geospatial data think about using more capable and elegant formats file exchange like e.g. GeoPackage. One the other hand it has some potential since it's quite more capable as e.g. a Shapefile. See also TheShapefileChallenge.

This format has following drawbacks:

  • not suited for massive datasets (except when compressing/zipping)
  • auxiliary cluttered accompanying files, like .csvt and .prj
  • no layer name - except for the file name (which can be changed easily by others...).

GeoCSV file format specification

GeoCSV is based on the CSV specification (see following section) and comes with two variants: Option Point(X/Y) and Option WKT.

Option "Point(X/Y" (easting/northing, longitude/latitude, lon/lat, long/lat, x/y like in mathematics):

  • Geometry Point type as two columns (in either order and not necessary neighboring) of type Integer or Float: one containing the easting coordinate, and another containing northing coordinate separated by a comma.
  • Example for the two X and Y (Point) columns "8.8249;47.2274".
  • This option supports only Points.

Option WKT:

  • It's one single column of type String containing a constructor, like for example: "POINT (8.8249 47.2274)".
  • This option supports Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon and even GeometryCollection and ARCs!
  • WKT ("Well Known Text") is originally defined by the Open Geospatial Consortium (OGC) and described in their Simple Feature Access specification (also ISO SQL/MM). See e.g. http://en.wikipedia.org/wiki/Well-known_text

Common restrictions:

  • There are more than one geometry columns allowed per sheet but only one column(-pair) can have either type Point(X/Y) or WKT.
  • Coordinate system is WGS84 (EPSG:4326) by default. See section PRJ.
  • All geometry values within one table are in the same coordinate reference system (CRS).

Optional auxiliary files (with same base filename but different file extensions) are:

  • CSVT:
    • Contains field type information (schema).
    • File extension is .CSVT (or .csvt).
    • See section below.
  • PRJ (to be clarified!):
    • Contains Coordinate Reference System (CRS) information.
    • File extension is .PRJ (or .prj).
    • Default (and strongly recommended) is EPSG:4326 (WGS84, lon/lat).
  • CSVZ:
    • File extension is .CSVZ (or .csvz)
    • The CSV file can be accompanied with following files, having the same file base name: .csvt and .prj.
    • Archiving and compressing in format .ZIP (or .zip) is also possible and encouraged.

CSV file format specification

File:

  • Contains the actual (geo-)data.
  • File extension is .CSV (or .csv).
  • Character Encoding and character set is UTF-8 (default) or ANSI/Windows-1252(?).
  • End-of-lines are: CR, LF or CR/LF.
  • Line End-of-lines (in String) fields) are disallowed (use e.g. HTML is needed).

Rows:

  • First row contains attribute names separated by a => delimiter.
  • Following rows are contains values separated by a => delimiter.
  • All rows have same number of attributes.

Fields/columns:

  • Field delimiter is semicolon (;) by default.
  • Strings are enclosed by parantheses, to allow delimiters inside (e.g. "string").
  • Data types (if supported from source or target system): See CSVT file format specification.
  • Calculations are possible in fields of type String (like "=A1+B1").

See also CSV.

CSVT file format specification

CSVT means "CSV Types" and it describes the field types and eventually their properties.

Field/column types, case insensitive, eventually in quotes ('"') - if supported from source or target system:

  • Integer or "Integer".
  • Real or "Real".
  • String or "String".
  • Date (format "YYYY-MM-DD"), Time (format "HH:MM:SS+nn") and DateTime (format "YYYY-MM-DD HH:MM:SS+nn"), whereas nn is the timezone.
  • "CoordX","CoordY" or "Point(X)","Point(Y)" - as two separate colums.
  • "WKT" or subtypes "WKT(Point)", "WKT(LineString)", "WKT(Polygon)".
  • If WKT name is indicated without subtype, all WKT geometry types are allowed: Multipoint, GeometryCollection, Arcs, ... (see OGC WKT).
  • All values of that WKT column are expected to contain the same geometry (sub)type.

Notes:

  • Types can be in quotes ('"') or not, e.g. <<"Integer";"Real">>.
  • Types can have precision in parantheses, e.g. ('Real(20.2)')).
  • There's only one geometry column per .csvt, namely either "CoordX","CoordY" or "WKT" (but not both).
  • Geometry types are a kind of subtype: CoordX,CoordY values are stored as integer or float, option WKT is stored in one column of type String.
  • See also http://www.gdal.org/drv_csv.html section with .csvt extension.
  • (Enhancement issue: There could be more properties like "mantatory/optional" or, for strings field length, and for numbers precision etc.)

PRJ file format specification

Software

Examples

CSV type file 'example1.csvt' - Option Point(X/Y):

Integer,String,Real,String,CoordX,CoordY

CSV file 'example1.csv - Option Point(X/Y):

id;name;amount;city;lon;lat
1;Kevin;2.1;Rapperswil;8.8249;47.2274
2;Eva;2.2;Zürich;8.5435;47.3768
3;"Jimmy;Muff";2.3;;7.4397;46.9487

CSV type file 'example2.csvt' - Option WKT:

Integer,String,Real,String,WKT(Point)

CSV file 'example2.csv - Option WKT:

id;name;amount;city;geom
1;Kevin;2.1;Rapperswil;POINT(8.8249 47.2274)
2;Eva;2.2;Zürich;POINT(8.5435 47.3768)
3;"Jimmy;Muff";2.3;;POINT(7.4397 46.9487)

...can be shown as following table:

id name amount remarks geom
1 Kevin 2.1 Rapperswil POINT(8.8249 47.2274)
2 Eva 2.2 Zürich POINT(8.5435 47.3768)
2 Jimmy;Muff 2.3 POINT(7.4397 46.9487)

Note the remarks string in row 2 and the empty string in row 3.