Giter VIP home page Giter VIP logo

asmyth01 / geo-adjacency Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 8.96 MB

A robust and versatile package for calculating adjacency relationships between geometries, taking obstacles into account. Useful whenever a simple intersection isn't good enough.

Home Page: https://asmyth01.github.io/geo-adjacency/

License: MIT License

Python 100.00%
adjacency geography geolocation geometry geospatial gis location matplotlib matplotlib-pyplot numpy

geo-adjacency's Introduction

Geo-Adjacency

Pip repository

Full documentation

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:

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.

$ git clone [email protected]:asmyth01/geo-adjacency.git
$ cd geo-adjacency
$ python -m build

Example Usage

See the docs 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 <https://github.com/asmyth01/geo-adjacency/>_.

    s, t, o = load_test_geoms("../tests/sample_data")
       engine = AdjacencyEngine(s , t, o, True)
  3. Run the analysis

    output = engine.get_adjacency_dict()
    # defaultdict(<class 'list'>, {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

  5. You probably will want to match the adjacency dictionary back to the original data so that you can do something cool with it.

      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]

geo-adjacency's People

Contributors

asmyth01 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

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.