Skip to main content

Library that Merges Geo Spatial Shapes

Project description

Shape-Merge

GitHub Python Contributions welcome Downloads

A Python based GIS library for finding and merging all Geometries that intersects with their neighbour. The library will iterate over all the geometries provided in the form of following Inputs, and will look for the neighbours which forms an intersection relationship with its Parent the geometry that looks for intersection is reffered as Parent either through a direct intersection or an intersection link generated via multiple Child geometries which have a relationship associated with its Parent either as a direct neighbour or via mutiple neighbour is reffered to as a Child intersection.

Buy Me a Coffee at ko-fi.com

OutputAnimation

Installation

pip install shape-merge

Requirements

The library uses Rtree which has a dependency on libspatialindex, It is recommend to resolving the dependency through libspatialindex conda

LibSpatialIndex For Linux:

$ sudo apt-get update -y
$ sudo apt-get install -y libspatialindex-dev

LibSpatialIndex For Windows:

Experience is pretty grim for Windows Installation, i used conda for trouble free installation.

Rtree

conda install -c conda-forge rtree

Fiona

conda install -c conda-forge fiona

Inputs

ShapeFile

from shape_merge.merge import ShapeMerge
shape_merge = ShapeMerge()
shape_merge.populate_index_by_fiona(r"path_to_shape_file.shp")

GeoJSON

from shape_merge.merge import ShapeMerge
shape_merge = ShapeMerge()
shape_merge.populate_index_by_geojson(r"path_to_geo_json.geojson")

Iteratively populate the index

from shape_merge.merge import ShapeMerge
shape_merge = ShapeMerge()
for feature in feature_collection:
    shape_merge.populate_index_by_feature(feature)

Feature must be of the following structure:

{'type': 'Feature', 'id': str, 'properties': dict, 'geometry': {'type': 'GeometryType', 'coordinates': list}}

How to run

After Populating the Index, merging is matter of a function call away, execute the following to begin merging:

shape_merge.merge_geometries()

Output

The Output will be a collection, which will contain the merged geometries and the all the ids that were merged together

merged_geoemrty = OrderedDict([(0, {'ids': [ ], 'geometry': {'type': 'GeometryType', 'coordinates': []}})])

Parameters

bounds_buffer :

During rtree index creation the bounds of individual geometry are added with buffer of 0, This param controls on how big the original bounds should grow.

geometry.bounds.buffer(self.__bounds_buffer)

The bounds of the geometry are responsible for finding potential intersecting neighbour i.e everything that lies in the bound is considered as a potential neighbour. A large value of bound value will increase the computational overhead.

geometry_buffer:

Add buffer to geometries while checking if they intersect with each other

geometry_1.buffer(self.__geometry_buffer).intersects(geometry_2.buffer(self.__geometry_buffer))

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

shape_merge-1.0.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

shape_merge-1.0.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file shape_merge-1.0.2.tar.gz.

File metadata

  • Download URL: shape_merge-1.0.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for shape_merge-1.0.2.tar.gz
Algorithm Hash digest
SHA256 fa30e31718b90f20d94b92229b0d95d5be30cb67d77e1e6f9a60d55eb20d5be9
MD5 310b16913c7eed36913e13f79deb7443
BLAKE2b-256 abb30cd3e3f02ed5d2dac1b774a4a9f9d12c27b8ef4cbd3c9fab31cb611b12dd

See more details on using hashes here.

File details

Details for the file shape_merge-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: shape_merge-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for shape_merge-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fed152834dbbb7c1bc980717aaf985d2689a2c66656acd40d1c59778e8bce41b
MD5 1550057f64c081b8d20b77e4b2d52d14
BLAKE2b-256 a1050e76808a625e83524442a9e39077923e7f76f28c2ac59abdaf02e8254ee1

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