Skip to main content

Custom geo type extensions for datacraft package

Project description

datacraft-geo

Custom plugin for datacraft to extend the geo types to include geo.mgrs and geo.utm

Usage in Specs

geo.mgrs

{
  "mgrs":{
    "type": "geo.mgrs"
  }
}
$ datacraft -s geo.mgrs.json -i 4 -r 1 --format json -x -l error
{"mgrs": "33TVE8831137089"}
{"mgrs": "28CET4236233893"}
{"mgrs": "33RXH7235656683"}
{"mgrs": "44XNJ6899271743"}

geo.utm

{
  "utm":{
    "type": "geo.utm"
  }
}
$ datacraft -s geo.utm.json -i 3 -r 1 --format json -x -l warning

{"utm": "37 T 482637 5257154"}
{"utm": "38 T 489869 4504951"}
{"utm": "33 K 673513 7460351"}
{"utm": "20 Q 629432 1992725"}

Customizing UTM output

We use the utm package under the hood, which provides it's output as a tuple of (EASTING, NORTHING, ZONE_NUMBER, ZONE_LETTER) e.g: (513864.9288961077, 1664402.2459186069, 25, "P"). The default is to format this as: {{ zone_number }} {{ zone_letter }} {{ easting | int }} {{ northing | int }} You can override this by specifying a template config parameter with the fields arranged as you like. See example below. The other way is to override the geo_utm_template default value from the command line (datacraft --set-defaults geo_utm_template="{{ zone_number }}{{ zone_letter }} {{ easting | int }}/{{ northing | int } }"). Note that {{ zn }} can be used in place of zone_number and {{ zl }} in place of zone_letter.

{
  "utm_custom":{
    "type": "geo.utm",
    "config": {
      "template": "{{ zn }}{{ zl }} {{ easting | int }}/{{ northing | int }}"
    }
  }
}
$ datacraft -s geo.utm.custom.json -i 3 -r 1 --format json -x -l warning
{"utm_custom": "37T 325263/5115949"}
{"utm_custom": "31N 676324/553043"}
{"utm_custom": "45J 300889/6854467"}
{"utm_custom": "44R 288307/2890462"}

Geo Lat/Long/Pair Clipped

These types are extensions to the existing datacraft geo types to support clipping of the points using geojson to specify valid polygon boundaries.

Types

name description
geo.pair.clip coordinate pair as list with longitude first, unless lat_first=True specified
geo.lat.clip latitude from a coordinate pair bounded by the geojson
geo.long.clip longitude from a coordinate pair bounded by the geojson
geo.utm also supports clipping
geo.mgrs also supports clipping

Example:

from shapely.geometry import shape
geojson = {
  "type": "Feature",
  "geometry": {
    "type": "Polygon",
    "coordinates": [[[23.0843, 53.1544], [23.0859, 53.1544], [23.0859, 53.1535], [23.0843, 53.1544]]]
  }
}
shape(geojson['geometry'])

Boundary

The image above describes the boundary of where we want our points to exist. To reference this geojson boundary, we can use the geojson config parameter in two ways.

  1. as the raw geojson
{
  "coords": {
    "type": "geo.pair.clip",
    "config": {
      "geojson": {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[23.0843,53.1544],[23.0845,53.1544],[23.0859,53.1535],[23.0843,53.1544]]]}},
      "join_with": ","
    }
  }
}
  1. as the file name path to the geojson file
{
  "coords": {
    "type": "geo.pair.clip",
    "config": {
      "geojson": "/path/to/clip.geo.json",
      "join_with": ","
    }
  }
}

Instead of hard-coding the path, you can specify just the file name then use the --data-dir to specify where to look for it and other data related files.

Multiple Polygons

You can use multiple polygons as boundaries by using a GeoJSON FeatureCollection:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [[ 23.0843, 53.1544 ],
           [ 23.0845, 53.1544 ],
           [ 23.0859, 53.1535 ],
           [ 23.0843, 53.1544 ]]
        ]
      }
    },{
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [[ 33.0843, 43.1544 ],
           [ 33.0845, 43.1544 ],
           [ 33.0859, 43.1535 ],
           [ 33.0843, 43.1544 ]]
        ]
      }
    }
  ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datacraft-geo-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

datacraft_geo-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file datacraft-geo-0.1.0.tar.gz.

File metadata

  • Download URL: datacraft-geo-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for datacraft-geo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb56758debdfb10a8fab89cd0ccc218c1ea9b82a05414abcbbc10decf96882a8
MD5 d8db24bde62a67ee120fd07fd3ee5f1c
BLAKE2b-256 59537e97defdc599eef3dcf4915a00391d56734ba84d3483f05127258c1bc583

See more details on using hashes here.

File details

Details for the file datacraft_geo-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for datacraft_geo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4daf498345d817ee1cf7ce36834a4a875c77be98679e2e0673997d174b01659
MD5 603a8d1d261a24e0e764b959fed3b1d0
BLAKE2b-256 ce757eddc7a89bfcb2ff1bc982896733049463ee0c97ace11f56d4de9839b9a1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page