Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asmyth01/geo-adjacency
A robust and versatile package for calculating adjacency relationships between geometries, taking obstacles into account. Useful whenever a simple intersection isn't good enough.
https://github.com/asmyth01/geo-adjacency
adjacency geography geolocation geometry geospatial gis location matplotlib matplotlib-pyplot numpy scipy shapely spatial spatial-analysis spatial-data spatial-data-analysis voronoi voronoi-diagram
Last synced: 3 months ago
JSON representation
A robust and versatile package for calculating adjacency relationships between geometries, taking obstacles into account. Useful whenever a simple intersection isn't good enough.
- Host: GitHub
- URL: https://github.com/asmyth01/geo-adjacency
- Owner: asmyth01
- License: mit
- Created: 2023-11-21T04:49:21.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-26T19:13:32.000Z (about 1 year ago)
- Last Synced: 2024-09-28T21:01:56.280Z (3 months ago)
- Topics: adjacency, geography, geolocation, geometry, geospatial, gis, location, matplotlib, matplotlib-pyplot, numpy, scipy, shapely, spatial, spatial-analysis, spatial-data, spatial-data-analysis, voronoi, voronoi-diagram
- Language: Python
- Homepage: https://asmyth01.github.io/geo-adjacency/
- Size: 8.75 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Geo-Adjacency
Pip [repository](https://pypi.org/project/geo-adjacency/)Full [documentation](https://asmyth01.github.io/geo-adjacency/index.html)
# Installation
It's recommended to use a virtual environment to install this tool, since its dependencies may
require different versions than what is installed on your system.## pip
Recommended installation is with [pip](https://pypi.org/project/pip/):```python -m pip install geo-adjacency```
## Build from source
You must have Python <3.13,>=3.9 installed.
```
$ git clone [email protected]:asmyth01/geo-adjacency.git
$ cd geo-adjacency
$ poetry install
```
Or with [build](https://pypa-build.readthedocs.io/en/latest/).
```
$ git clone [email protected]:asmyth01/geo-adjacency.git
$ cd geo-adjacency
$ python -m build
```# Example Usage
_See the [docs](https://asmyth01.github.io/geo-adjacency/index.html) for details._1. Load the data. geo-adjacency expects you to provide your data as Shapely geometries. You will provide three lists: source_geoemtries, target_geometries, and obstacle_geometries. What we are analyzing is which of the source geometries are adjacent to which of the target geometries. Obstacles can prevent a source and target from being adjacent, but they do not participate in the adjacency dictionary.
2. Create an AdjacencyEngine. In this case, we'll load the sample data which is available on `Github `_.```python
s, t, o = load_test_geoms("../tests/sample_data")
engine = AdjacencyEngine(s , t, o, True)
```
3. Run the analysis
```python
output = engine.get_adjacency_dict()
# defaultdict(, {0: [1, 2], 1: [1], 2: [1], 3: [2], 6: [1], 7: [1]})
```The output is a dictionary. Keys are the indices of source geometries in the input list, and values are a list of indices of adjacent target geometries in the input list.
4. You can visualize the output with a handy built-in method which uses pyplot.
`engine.plot_adjacency_dict()`. (Source geoms are grey, targets are blue, obstacles are red. Linkages are green.![adjancency diagram](docs/images/adjacency_with_segmentation.png)
5. You probably will want to match the adjacency dictionary back to the original data so that you can do something cool with it.
```python
for source_i, target_i_list in output.items():
source_geom = source_geometries[source_i]
target_geoms = [target_geometries[i] for i in target_i_list]
```