[GIS] How to convert CSV file in VRT

command linegdalqgisvrt

I use the gdal executable in QGIS file, with a DOS command.

I have a csv file like this (test.csv) :

  X       Y
-5.48   42.81
-4.78   42.52
-5.06   42.02

This coordinates are GCP. I would like to convert my csv file in a VRT. On the internet, I found example like :

<OGRVRTDataSource>
    <OGRVRTLayer name="test">
        <SrcDataSource>test.csv</SrcDataSource>
        <GeometryType>wkbPolygon</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
        <Field name="id" src="id" />
        <GeometryField encoding="WKT" field="geo" />
    </OGRVRTLayer>
</OGRVRTDataSource>

Simply, I don't know where to put this line. Should I put them in a DOS command in my QGIS file ?

Best Answer

If you want to work with GDAL on command line, you have to change your input file to comma delimiters:

X,Y
-5.48,42.81
-4.78,42.52
-5.06,42.02

The appropriate vrt file for it is:

<OGRVRTDataSource>
    <OGRVRTLayer name="test">
        <SrcDataSource>test.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
        <GeometryField encoding="PointFromColumns" x="X" y="Y"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

Note that the source file name, geometry type, and geometry column names must match your data file.

You can test it with ogrinfo test.vrt on the DOS command line.

Alternatively, since you have QGIS already installed, you can load the file directly (even with blanks) as Delimited Text (the icon with the comma).

Related Question