GithubHelp home page GithubHelp logo

odk_geotrace_to_wkt's Introduction

Convert ODK Geotraces to GIS-friendly formats (WKT linestrings or 3D points)

Takes a CSV file containing line strings from an OpenDataKit Geotrace, which consist of a series of text coordinates, and returns a similar CSV file with properly formatted Well-Known Text (WKT) linestrings (and points).

These scripts expect the default GeoTrace format from an ODK CSV export from an ODK aggregator (ODK Aggregate, Kobo Toolbox, or OMK Server), which consists of a series of node coordinates separated by semicolons. Each node seems to consist of a latitude, longitude, and two zeros, internally separated by spaces. The WKT format specifies the type (LINESTRING or POINT) followed by long, then lat separated by spaces, then a comma separating nodes.

lines_to_wkt usage

Positional Argument:

  1. An input CSV file

Optional Arguments:

  • -c or --column: An integer specifying which column contains the geotrace (1-based column count; the way humans, not computers, count). No default value; if this parameter is not given the script assumes that the appropriate column is named rather than numbered (see next argument).
  • -cn or --column_name: a string matching the column header of the geotrace column. Defaults to geotrace because that might occasionally be the actual column header used.
  • -d or --delimiter: a single character representing the delimiter of the CSV file (usually a comma, semicolon, or Tab character). Defaults to assuming a comma.
  • -o our --output: the name of the output file. Defaults to creating a file with the same name as the input file, with _results appended. So /my/input/file.csv will by default get an output file /my/input/file_results.csv.

Example usage:

python3 lines_to_wkt.py infile.csv Looks for a column named "geotrace" and converts the linestrings in it to WKT.

python3 lines_to_wkt.py infile.csv -c 8 Converts the contents of the 8th column (count starting from 1) into WKT from linestrings.

python3 lines_to_wkt.py infile.csv -cn road_trace -d ; Looks for a column titled "road_trace". Expects the CSV delimiter to be a semicolon rather than a comma (KoBo Toolbox uses semicolons by default, while OMK Server uses commas).

The output file should be identical to the input, with the exception of having converted the GeoTrace coordinates to valid WKT lines.

In a future version this may allow additional column number arguments to convert multiple traces in the same file (in case someone collects multiple lines in the same survey).


points_3D_from_ODK_lines usage

Positional Argument:

  1. An input CSV file

Optional Arguments:

  • -c or --column: An integer specifying which column contains the geotrace (1-based column count; the way humans, not computers, count). No default value; if this parameter is not given the script assumes that the appropriate column is named rather than numbered (see next argument).
  • -cn or --column_name: a string matching the column header of the geotrace column. Defaults to geotrace because why not.
  • -d or --delimiter: a single character representing the delimiter of the CSV file (usually a comma, semicolon, or Tab character). Defaults to assuming a comma.
  • -o our --output: the name of the output file. Defaults to creating a file with the same name as the input file, with _3D_points appended. So /my/input/file.csv will by default get an output file /my/input/file_3D_points.csv.
  • -kc or --keep_columns: a string describing which columns in the original file (which has one row per geotrace line) should be kept in the output file (which has one row per point in those geotrace lines). It seems obvious that users don't want to duplicate all of the information about each geotrace line, but probably want to retain some of it (for example, the line ID or the ID of the device that did the survey).

Example usage:

python3 points_3D_from_ODK_lines.py infile.csv Looks for a column named "geotrace", extracts the 3-dimensional points from the lines, and exports a new CSV file with a row for each point in all lines.

python3 points_3D_from_ODK_lines.py infile.csv -c 8 Converts the contents of the 8th column (starting from 1) into 3D points from linestrings.

python3 points_3D_from_ODK_lines.py infile.csv -cn river_transect -d ; Looks for a column titled "road_trace". Expects the CSV delimiter to be a semicolon rather than a comma (KoBo Toolbox uses semicolons by default, while OMK Server uses commas).

python3 points_3D_from_ODK_lines.py infile.csv -c 17 -kc 3,6-9,22 produces a csv file full of 3D points, and includes columns 3, 6, 7, 8, 9, and 22 from the original file, along with the lat, long, elevation, and precision of each individual point.


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.