Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geospatial-jeff/enum-spatial
Enumerations for spatial data.
https://github.com/geospatial-jeff/enum-spatial
Last synced: 3 months ago
JSON representation
Enumerations for spatial data.
- Host: GitHub
- URL: https://github.com/geospatial-jeff/enum-spatial
- Owner: geospatial-jeff
- Created: 2020-01-04T16:40:51.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-04T20:13:44.000Z (almost 5 years ago)
- Last Synced: 2024-05-15T04:39:02.053Z (6 months ago)
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spatial-enum
Enumerations for spatial data with support for vectorized spatial operations via [`pygeos`](https://github.com/pygeos/pygeos).```python
from enum_spatial import BoundsEnum
from shapely.geometry import Pointclass MyEnum(BoundsEnum):
bbox1 = [-118, 34, -117, 35]
bbox2 = [-81, 30, -80, 31]print(MyEnum.bbox1)
>>> POLYGON ((-118 34, -118 35, -117 35, -117 34, -118 34))print(MyEnum.intersects(Point([-117.5, 34.5]))
>>> bbox1
```Supported enum types:
- `BoundsEnum`
- `PointEnum`
- `LineStringEnum`
- `PolygonEnum`
- `MultiPointEnum`
- `MultiLineStringEnum`
- `MultiPolygonEnum`Support spatial operations:
- `intersects`
- `contains`
- `overlaps`
- `touches`
- `disjoint`
- `crosses`## Installation
```python
pip install shapely --no-binary shapely
pip install git+https://github.com/geospatial-jeff/enum-spatial.git
```### World Cities Example
Download the dataset:
```bash
curl https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson -o countries.geojson
```Load into the enum through the `enum.Enum` [functional API](https://docs.python.org/3/library/enum.html#functional-api):
```python
import json
from enum_spatial import MultiPolygonEnum
from shapely.geometry import shapedata = json.load(open('countries.geojson', 'r'))
enum_members = []
for feat in data['features']:
geom = shape(feat['geometry'])
country_name = feat['properties']['ADMIN']
if geom.is_valid:
enum_members.append((country_name, geom))world_countries = MultiPolygonEnum('WorldCountries', enum_members)
```Find a country which contains a given point:
```python
print(world_countries.intersects(Point([-54, 15])))
>>> Brazil
```Find neighboring countries:
```python
print(world_countries.intersects(world_countries.Paraguay))
>>> ['Argentina', 'Bolivia', 'Brazil', 'Paraguay']
```