Giter Club home page Giter Club logo

csv_to_wkt's Introduction

Convert ODK Geotraces to Well-Known Text linestrings

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).

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 drain_line because the Ramani Huria team is using it for drain traces.
  • -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 "drain_lines" and converts the linestrings in it to WKT.

python3 lines_to_wkt.py infile.csv -c 8 Converts the contents of the 8th column (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).


This script expects 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.

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).

csv_to_wkt's People

Contributors

johanespeter9 avatar

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.