Encodings for geometric objects
Project description
geo-encodings
Positional encodings for geometric objects
Spatial analysis deals with geometric objects of type Point LineString, and Polygon; plus multipart extensions: MultiPoint, MultiLineString, and MultiPolygon. Most Machine Learning (ML) tools -- classifiers, regression models, neural networks -- are not built to ingest geometric objects in their native format. That's where this package comes in.
The geo-encodings package turns
arbitrary geometric objects into vectors that approximately encode
their shape and location.
Here's a quick example of its use.
# Define a Point object using the `shapely` package.
import shapely
g = shapely.from_wkt('POINT(23 37)')
# Get an encoding of that point.
from geo_encodings.encoders import MPPEncoder
encoder = MPPEncoder(region=[0, 0, 100, 100], resolution=20)
e = encoder.encode(g)
print(e.values())
---
[0.11323363 0.15628545 0.13055936 0.07307309 0.03344699 0.01396199
0.23930056 0.42183804 0.30056792 0.13055936 0.05109572 0.01939549
0.31356727 0.80885789 0.42183804 0.15628545 0.0576166 0.02121767
0.19664689 0.31356727 0.23930056 0.11323363 0.04626952 0.01798739
0.08731465 0.11587698 0.0990703 0.05863808 0.02815546 0.01215945
0.03496679 0.04269944 0.03828613 0.02591118 0.01429364 0.00691243]
We just defined a 25-element vector that encodes the Point location (x = 23, y = 37) within a square region (lower left = (0, 0), upper right = (100, 100)).
So why bother encoding a coordinate pair as a 25-element vector?
Mostly because the vector can be fed to most machine learning models,
where the string "POINT(23, 37)" typically can not
(unless we are talking about certain Large Language Models (LLMS),
which are a whole other story).
And importantly, the exact same operation works for all other types of geometries:
LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon.
In other words, any geometric object in the region can be represented
in the same form: a vector of aparticular size.
Supported encoding models
The geo-encodings package implements a few different ways to encode shapes.
Multi-Point Proximity (MPP) Encoding
MPP encoding involves laying out a grid of reference points
$\bf{r} = {r_i: i \in [1..n]}$
over a rectangular region.
Then for a given shape $\bf{g}$, compute its distance $d_i$ to each reference point,
where "distance" is the Euclidean distance between the reference point and the closest point of the shape.
The apply negative exponential scaling to the distances:
$e_i = \exp(-d_i / s)$
where $s$ is the scale parameter of the MPP encoder.
Discrete Indicator Vector (DIV) Encoding
DIV encoding involves dividing a given region into non-overlapping square "tiles". An encoding for a shape is an indicator vector (0 or 1) indicating which tiles it intersects.
Supporting packages
shapely: Provides computations on geometric objects.scipy: Provides tools for handling sparse arrays.
Installation
pip install geo-encodings
Release History
- 1.0.0: Initial release
Author and maintainers
- John Collins --
john@odyssey-geospatial.com
Contributing
If you would like to contribute, do this:
- Fork the repo (https://github.com/yourname/yourproject/fork)
- Create your feature branch (git checkout -b feature/myFeatureBranch)
- Commit your changes (git commit -am 'add some new features')
- Push to the branch (git push origin feature/myFeatureBranch)
- Create a new Pull Request
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geo_encodings-1.0.4.tar.gz.
File metadata
- Download URL: geo_encodings-1.0.4.tar.gz
- Upload date:
- Size: 313.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b560114f6d768edd04e69471ac7079bba12ee584829e5298722e4b524f8ce8ad
|
|
| MD5 |
d98882630afa45bed2482f505fe4c516
|
|
| BLAKE2b-256 |
f4bf19bd8ed37646ff0ad36c811abfd8a4664fa7d66bd0133470b7b754bb1dc8
|
File details
Details for the file geo_encodings-1.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: geo_encodings-1.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
768b206f05e1f400d2c8cf6914b29eb60657708cc5a2e7ccf3be00a0528512ea
|
|
| MD5 |
83f11311493f7c5a1c97d31caaaf5357
|
|
| BLAKE2b-256 |
2d4f3dde80a8fb629bb2b822acbff899b2dab941c263edc4c92874221721b233
|