Git Product home page Git Product logo

geo-benthos's Introduction

Geo-Benthos

Benthos plugins to transform geographic coordinates from a stream.

Benthos is the swiss army of stream processing: Benthos solves common data engineering tasks such as transformations, integrations, and multiplexing with declarative and unit testable configuration.

This repo contains multiple Benthos plugins as Go modules, that you can build on demand (see cmd/geo-benthos).

Note that the h3 plugin is using a CGO free version.

Get the country for a latitude and longitude

Use country with the following parameters: latitude, longitude.

An example position.json:

{"id":42, "lat": 48.86, "lng": 2.34}

A country.yaml pipeline.

input:
  file:
    paths: ["testdata/position.json"]
    codec: all-bytes

pipeline:
  threads: 1
  processors:
  - mapping: |
      #!blobl
      root = this
      root.country = country(this.lat, this.lng)

output:
  label: "out"
  stdout:
    codec: lines

Enrich the input with the timezone:

go build -o geo-benthos ./cmd/geo-benthos
./geo-benthos -c testdata/country.yaml
{"country":["France"],"id":42,"lat":48.86,"lng":2.34}

country module is using coord2country.

Transform latitude and longitude into an Uber h3 cell

Use h3 with the following parameters: latitude, longitude, resolution.

An example position.json:

{"id":42, "lat": 48.86, "lng": 2.34}

A h3.yaml pipeline.

input:
  file:
    paths: ["testdata/position.json"]
    codec: all-bytes

pipeline:
  threads: 1
  processors:
  - mapping: |
      #!blobl
      root = this
      root.h3 = h3(this.lat, this.lng, 5)

output:
  label: "out"
  stdout:
    codec: lines

Enrich the input with the h3 cell:

go build -o geo-benthos ./cmd/geo-benthos
./geo-benthos -c testdata/h3.yaml
{"h3":"851fb467fffffff","id":42,"lat":48.86,"lng":2.34}

Transform latitude and longitude into a Google s2 cell

Use s2 with the following parameters: latitude, longitude, resolution.

An example position.json:

{"id":42, "lat": 48.86, "lng": 2.34}

A s2.yaml pipeline.

input:
  file:
    paths: ["testdata/position.json"]
    codec: all-bytes

pipeline:
  threads: 1
  processors:
  - mapping: |
      #!blobl
      root = this
      root.s2 = s2_object(this.lat, this.lng, 15)

output:
  label: "out"
  stdout:
    codec: lines

Enrich the input with the s2 cell:

go build -o geo-benthos ./cmd/geo-benthos
./geo-benthos -c testdata/s2.yaml
{"id":42,"lat":48.86,"lng":2.34,"s2":"2/033303031301002"}

Get the timezone for a given latitude and longitude

Use tz with the following parameters: latitude, longitude.

An example position.json:

{"id":42, "lat": 48.86, "lng": 2.34}

A tz.yaml pipeline.

input:
  file:
    paths: ["testdata/position.json"]
    codec: all-bytes

pipeline:
  threads: 1
  processors:
  - mapping: |
      #!blobl
      root = this
      root.tz = tz(this.lat, this.lng)

output:
  label: "out"
  stdout:
    codec: lines

Enrich the input with the timezone:

go build -o geo-benthos ./cmd/geo-benthos
./geo-benthos -c testdata/tz.yaml
{"tz":"Europe/Paris","id":42,"lat":48.86,"lng":2.34}

tz module is using tzf.

Generate random position in a range (mainly for debug)

This is an input plugin that will generate random coordinates in your range.

input:
  randpos:
    min_lat: 46.0
    max_lat: 48.0
    min_lng: 2.0
    max_lng: 2.3

output:
  label: "out"
  stdout:
    codec: lines

Live Testing

Run this command and point your browser to http://localhost:4195/

./geo-benthos blobl server --no-open --host 0.0.0.0 --input-file ./testdata/position.json -m testdata/s2_mapping.txt   

TODO

  • s2 shape index to perform PIP
  • spatialite lookup to perform PIP
  • random points in a rect
  • lat lng to h3
  • lat lng to s2
  • lat lng to tz
  • lat lng to country

geo-benthos's People

Contributors

akhenakh avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

geo-benthos's Issues

Address validation

Google address format can validate an address from a user.

would be useful for this package ?

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.