3

I'm not sure if I can complete this operation in one step - but someone might be able to help me.

My input file is a csv file with PointID, x, y, z and LineID columns. I'm looking to combine all rows with the same LineID into Polyline25D using ogr2ogr with a virtual datasource (VRT file).

I can get a MultiPoint output, but can't work out how to combine multiple rows (if it's at all possible).

Alternatively, could someone help me with a python script to combine the x, y, z fields into WKT?

Input Example :

pointid y   x   z   lineid
1   320589.01   1815258.73  423.78  1
2   320573.49   1815256.71  425.04  1
3   320557.42   1815252.40  425.86  1
4   320541.64   1815248.71  426.19  1
5   320529.37   1815247.01  427.18  1
1   320588.78   1815259.35  423.43  2
2   320573.06   1815257.09  424.66  2
3   320557.00   1815253.09  425.06  2
4   320541.79   1815249.54  425.78  2
5   320529.14   1815247.74  426.22  2
6   320516.78   1815245.02  426.84  2
1   320588.62   1815260.10  423.44  3
2   320572.59   1815258.42  424.65  3
3   320556.21   1815255.29  425.13  3
4   320540.73   1815252.19  425.80  3
5   320529.02   1815248.37  426.20  3
0

Starting with GDAL 2.1, it is possible to directly specify the potential names of the columns that can contain X/longitude and Y/latitude with the X_POSSIBLE_NAMES and Y_POSSIBLE_NAMES open option. (Source: http://www.gdal.org/drv_csv.html)

It's possible to accomplish this task with the following one-line ogr2ogr command (GDAL >= 2.1):

ogr2ogr multilinestringzs.shp pointzs.csv -dialect SQLite -sql "SELECT lineid, ST_Multi(MakeLine(geom)) AS geometry FROM (SELECT lineid, pointid, MakePointZ(x,y,z) AS geom FROM pointzs ORDER BY lineid, pointid) GROUP BY lineid" -oo X_POSSIBLE_NAMES=x -oo Y_POSSIBLE_NAMES=y -oo Z_POSSIBLE_NAMES=z -oo KEEP_GEOM_COLUMNS=YES

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.