Monday 15 May 2017

How to visually sort the order of Points with QGIS, GDAL, ...?


The following Points layer is the basis of a rendering in a Android application.


Points layer in QGIS


Android allows to draw a shape from the provided points. I cannot use LineStrings.


Points layer in Android



However, the order of points exported from QGIS seems to be odd.


Is there any way to visually sort the order of points in QGIS or using the GDAL tools? The order of feature ids in the final export format (such as CSV) needs to be kind of a roundtrip as visualized in the following picture. If there are multiple paths or a "hole" it is perfectly okay to have multiple point layers.


Points layer visualizing the roundtrip


Export experiments


I tried different steps to get hold of the latitude/longitude coordinates:



  1. QGIS: Export points layer as CSV, add layer create options: GEOMETRY=AS_YX

  2. Convert into Android specific format JSON format using regular expressions.


This has the disadvantage that the feature id is still included. The order of points however is not as desired.




  1. ogr2ogr -f CSV output.csv input.shp -lco GEOMETRY=AS_YX

  2. Convert into Android specific format JSON format using regular expressions.


Here the feature id is already omitted. The order of points however is not as desired.



  1. QGIS: Export points layer as GML

  2. ogr2ogr -f "CSV" -select "" output.csv input.gml -lco "GEOMETRY=AS_YX"

  3. Convert into Android specific format JSON format using regular expressions.



The order of points however is not as desired. The order of points is different to what the former exports/conversions output.




The original layer is also available as a LineString layer.



Answer



I tried this in QGIS:



  1. Load the polyline data from OSM

  2. Reproject it to UTM 32N

  3. Vector -> Geoprocessing -> Buffer with a value of 10 (metres) for Buffer distance.

  4. Vector -> Geoprocessing -> Dissolve using dissolve all will lead to one polygon


  5. Vector -> Geometry Tools -> Multipart to single part creates one polygon for every LEZ with a hole in the middle

  6. Vector -> Geometry Tools -> Polygons to Lines

  7. Vector -> Geometry Tools -> Lines to Polygons

  8. Vector -> Geoprocessing -> Dissolve using dissolve all will remove the inner ring

  9. Vector -> Geometry Tools -> Multipart to single part creates one polygon for every LEZ without hole

  10. Using Field Calculator, create unique ids with a new field filled with $id

  11. Install the MMQGIS plugin

  12. MMQGIS -> Import/Export -> Geometry Export to CSV


For checking:




  • Import as Delimited text layer

  • Install Points2One plugin

  • Join the points to a line with Points2One


This works for Münster, but may fail on other cities (like Frankfurt, where a segment of the border is missing).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...