Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add method for boolean intersects #118

Merged
merged 17 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ['3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ It supports below features:

- [Random](https://github.com/omanges/turfpy/blob/master/random.md)

- [Feature Conversion](https://github.com/omanges/turfpy/blob/master/feature_conversion.md)

- [Boolean](https://github.com/omanges/turfpy/blob/master/boolean.md)

## Documentation

Documentation can be found at: [docs](https://turfpy.readthedocs.io/en/latest/)
Expand Down
41 changes: 41 additions & 0 deletions boolean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Boolean Examples :
* boolean_disjoint : Takes two features and returns (TRUE) if the two geometries do not touch or overlap.

| Argument| Type | Description|
| ------- |------ | ----------- |
| `feature_1` |Feature | Feature 1 |
| `feature_2` |Feature | Feature 2 |


| Return | Type | Description |
| ------- | ------ | ----------- |
| `bool` | bool | Return true or false |

```python
from geojson import Feature, Point
from turfpy.boolean import boolean_disjoint

feature_1 = Feature(geometry=Point((19.0760, 72.8777)))
feature_2 = Feature(geometry=Point((29.0760, 72.8777)))
boolean_disjoint(feature_1, feature_2)
```

* boolean_intersects : Takes two features and returns (TRUE) if the intersection of the two geometries is NOT an empty set.

| Argument| Type | Description|
| ------- |------ | ----------- |
| `feature_1` |Feature | Feature 1 |
| `feature_2` |Feature | Feature 2 |

| Return | Type | Description |
| ------- | ------ | ----------- |
| `bool` | bool | Return true or false |

```python
from geojson import Feature, Point
from turfpy.boolean import boolean_intersects

feature_1 = Feature(geometry=Point((19.0760, 72.8777)))
feature_2 = Feature(geometry=Point((29.0760, 72.8777)))
boolean_intersects(feature_1, feature_2)
```
28 changes: 12 additions & 16 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#test
pytest
mypy
coverage
black
mypy
pytest-cov
pytest-mypy
pytest-flake8
isort
Sphinx>=2.4.0
sphinx-rtd-theme
jupyter-sphinx==0.2.4a1
ipyleaflet
# optional dependencies required for line_intersect
geopandas
pygeos
pytest==8.3.3
mypy==1.13.0
coverage==7.6.4
black==24.10.0
pytest-cov==6.0.0
pytest-mypy==0.10.3
pytest-flake8==1.2.2
isort==5.13.2
Sphinx==8.1.3
sphinx-rtd-theme==3.0.1
jupyter-sphinx==0.5.3
ipyleaflet==0.19.2
16 changes: 16 additions & 0 deletions docs/source/boolean/boolean_disjoint.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Boolean Disjoint
=================
Takes two features and returns (TRUE) if the two geometries do not touch or overlap.

Example
-------

.. jupyter-execute::

from geojson import Feature, Point
from turfpy.boolean import boolean_disjoint

feature_1 = Feature(geometry=Point((19.0760, 72.8777)))
feature_2 = Feature(geometry=Point((29.0760, 72.8777)))
boolean_disjoint(feature_1, feature_2)

16 changes: 16 additions & 0 deletions docs/source/boolean/boolean_intersects.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Boolean Intersects
==================
Takes two features and returns (TRUE) if the intersection of the two geometries is NOT an empty set.

Example
-------

.. jupyter-execute::

from geojson import Feature, Point
from turfpy.boolean import boolean_intersects

feature_1 = Feature(geometry=Point((19.0760, 72.8777)))
feature_2 = Feature(geometry=Point((29.0760, 72.8777)))
boolean_intersects(feature_1, feature_2)

46 changes: 46 additions & 0 deletions docs/source/feature_conversion/polygon_to_line.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Polygon to Line
================
Takes a Polygon or MultiPolygon and convert it to a line.

Example
-------

.. jupyter-execute::

from geojson import Feature, Polygon
from turfpy.feature_conversion import polygon_to_line

feature_1 = Feature(geometry=Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]))
polygon_to_line(feature_1)

Interactive Example
-------------------

.. jupyter-execute::

from turfpy.feature_conversion import polygon_to_line
from geojson import Polygon
from geojson import Feature
from ipyleaflet import Map, WidgetControl
from ipywidgets import HTML

feature_1 = Feature(geometry=Polygon([[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15), (2.38, 57.322)]]))

geo_json = polygon_to_line(feature_1)

m = Map(center=[20.04303061200023, -11.832275390625002], zoom=2)

m.add_layer(geo_json)

html = HTML()
html.layout.margin = "0px 20px 10px 20px"
html.value = """
<h4>Polygon to Line for given geojson</h4>
<h4>{}</h4>
""".format(
geo_json
)
control = WidgetControl(widget=html, position="topright")
m.add_control(control)

m
12 changes: 12 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ A Python library for performing geospatial data analysis which reimplements `tur
Line Offset <transformations/line_offset>
Voronoi <transformations/voronoi>

.. toctree::
:maxdepth: 1
:caption: Boolean

Boolean Disjoint <boolean/boolean_disjoint>
Boolean Intersects <boolean/boolean_intersects>

.. toctree::
:maxdepth: 1
:caption: Feature Conversion

Polygon To Line <feature_conversion/polygon_to_line>

.. toctree::
:maxdepth: 1
Expand Down
4 changes: 2 additions & 2 deletions docs/source/measurements/area.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Interactive Example
feature_2 = Feature(geometry=geometry_2)
feature_collection = FeatureCollection([feature_1, feature_2])
geo_json = GeoJSON(data=feature_collection)
watercolor = basemap_to_tiles(basemaps.Stamen.Watercolor)
mapnik = basemap_to_tiles(basemaps.OpenStreetMap.Mapnik)

m = Map(layers=(watercolor,), center=[20.04303061200023, -11.832275390625002], zoom=2)
m = Map(layers=(mapnik,), center=[20.04303061200023, -11.832275390625002], zoom=2)

m.add_layer(geo_json)

Expand Down
8 changes: 8 additions & 0 deletions docs/source/turfpy.boolean.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
turfpy.boolean module
=========================

.. automodule:: turfpy.boolean
:members:
:undoc-members:
:show-inheritance:
:private-members:
8 changes: 8 additions & 0 deletions docs/source/turfpy.feature_conversion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
turfpy.turfpy.feature_conversion module
=========================

.. automodule:: turfpy.turfpy.feature_conversion
:members:
:undoc-members:
:show-inheritance:
:private-members:
8 changes: 8 additions & 0 deletions docs/source/turfpy.random.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
turfpy.random module
====================

.. automodule:: turfpy.random
:members:
:undoc-members:
:show-inheritance:
:private-members:
77 changes: 77 additions & 0 deletions examples/boolean.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Boolean\n",
"This notebook demonstrates all the examples of boolean"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Boolean Disjoint\n",
"Takes two features and returns (TRUE) if the two geometries do not touch or overlap."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from geojson import Feature, Point\n",
"from turfpy.boolean import boolean_disjoint\n",
"\n",
"feature_1 = Feature(geometry=Point((19.0760, 72.8777)))\n",
"feature_2 = Feature(geometry=Point((29.0760, 72.8777)))\n",
"boolean_disjoint(feature_1, feature_2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Boolean Intersects\n",
"Takes two features and returns (TRUE) if the intersection of the two geometries is NOT an empty set."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from geojson import Feature, Point\n",
"from turfpy.boolean import boolean_intersects\n",
"\n",
"feature_1 = Feature(geometry=Point((19.0760, 72.8777)))\n",
"feature_2 = Feature(geometry=Point((29.0760, 72.8777)))\n",
"boolean_intersects(feature_1, feature_2)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Loading