https://github.com/fuzailpalnak/shapemerge
A Python based Geo Spatial library to find and merge all geometries that intersects with their neighbor.
https://github.com/fuzailpalnak/shapemerge
fiona geographical-information-system geospatial geospatial-data gis merge python rtre shapely
Last synced: about 2 months ago
JSON representation
A Python based Geo Spatial library to find and merge all geometries that intersects with their neighbor.
- Host: GitHub
- URL: https://github.com/fuzailpalnak/shapemerge
- Owner: fuzailpalnak
- License: mit
- Created: 2020-08-06T15:37:58.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-10-07T07:02:09.000Z (over 2 years ago)
- Last Synced: 2024-04-29T02:06:26.303Z (about 1 year ago)
- Topics: fiona, geographical-information-system, geospatial, geospatial-data, gis, merge, python, rtre, shapely
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.txt
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# Shape-Merge



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](#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.
### Installation
pip install shape-merge
### Requirements
The library uses [Rtree](https://rtree.readthedocs.io/en/latest/) which has a dependency on [libspatialindex](https://libspatialindex.org/),
It is recommend to resolving the dependency through [libspatialindex conda](https://anaconda.org/conda-forge/libspatialindex)*_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*
```python
from shape_merge.merge import ShapeMerge
shape_merge = ShapeMerge()
shape_merge.populate_index_by_fiona(r"path_to_shape_file.shp")
```*GeoJSON*
```python
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*
```python
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 runAfter Populating the Index, merging is matter of a function call away, execute the following to begin merging:
shape_merge.merge_geometries()
### OutputThe 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))