Skip to content

Commit

Permalink
Merge pull request #43 from pyturf/boolean_intersects
Browse files Browse the repository at this point in the history
Add boolean-intersects module
  • Loading branch information
diogomatoschaves committed Nov 22, 2020
2 parents 622fc0a + 1c1169b commit ccbf7e7
Show file tree
Hide file tree
Showing 49 changed files with 1,394 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Currently, the following modules have been implemented:
- [bbox-polygon](https://github.com/pyturf/pyturf/tree/master/turf/bbox_polygon)
- [bearing](https://github.com/pyturf/pyturf/tree/master/turf/bearing)
- [boolean-disjoint](https://github.com/pyturf/pyturf/tree/master/turf/boolean_disjoint)
- [boolean-intersects](https://github.com/pyturf/pyturf/tree/master/turf/boolean_intersects)
- [boolean-point-in-polygon](https://github.com/pyturf/pyturf/tree/master/turf/boolean_point_in_polygon)
- [boolean-point-on-line](https://github.com/pyturf/pyturf/tree/master/turf/boolean_point_on_line)
- [center](https://github.com/pyturf/pyturf/tree/master/turf/center)
Expand Down
12 changes: 12 additions & 0 deletions docs/source/modules/booleans.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
Booleans
========

boolean-disjoint
----------------

.. autofunction:: turf.boolean_disjoint


boolean-intersects
------------------

.. autofunction:: turf.boolean_intersects


boolean-point-in-polygon
------------------------

Expand Down
1 change: 1 addition & 0 deletions turf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from turf.bbox_polygon import bbox_polygon
from turf.bearing import bearing
from turf.boolean_disjoint import boolean_disjoint
from turf.boolean_intersects import boolean_intersects
from turf.boolean_point_in_polygon import boolean_point_in_polygon
from turf.boolean_point_on_line import boolean_point_on_line
from turf.center import center
Expand Down
3 changes: 1 addition & 2 deletions turf/boolean_disjoint/_boolean_disjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def boolean_disjoint(feature_1: Any, feature_2: Any) -> bool:
is_disjoint = disjoint(flat_1, flat_2)

if not is_disjoint:
break
return is_disjoint

return is_disjoint

Expand All @@ -55,7 +55,6 @@ def disjoint(
:param feature_2: {List} a List with geometry type and coordinates
:return: boolean True/False if features are disjoint
"""

is_disjoint = True

if feature_1[0] in ["Point"]:
Expand Down
4 changes: 0 additions & 4 deletions turf/boolean_disjoint/tests/test_boolean_disjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import os

from turf.boolean_disjoint import boolean_disjoint
from turf.helpers import feature, feature_collection, point, line_string
from turf.helpers._features import all_geometry_types
from turf.utils.error_codes import error_code_messages
from turf.utils.exceptions import InvalidInput
from turf.utils.test_setup import get_fixtures


Expand Down
1 change: 1 addition & 0 deletions turf/boolean_intersects/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from turf.boolean_intersects._boolean_intersects import boolean_intersects
14 changes: 14 additions & 0 deletions turf/boolean_intersects/_boolean_intersects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any

from turf.boolean_disjoint import boolean_disjoint


def boolean_intersects(feature_1: Any, feature_2: Any) -> bool:
"""
Returns true if the two geometries intersect.
:param feature_1: {GeoJSON} feature_1 any Feature or Geometry
:param feature_2: {GeoJSON} feature_2 any Feature or Geometry
:return: boolean True/False if features intersect
"""
return not boolean_disjoint(feature_1, feature_2)
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/LineString-LineString.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[0, 0], [12, 2], [12, 3], [12, 4]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/LineString-Point.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/LineString-Polygon.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[0, 0], [12, 2], [12, 3], [12, 4]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/MultiPoint-LineString.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [[2, 2], [0, 0]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/MultiPoint-MultiPoint.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [[0, 0], [13, 13]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [[1, 1], [12, 12]]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/MultiPoint-Point.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [[1, 1], [12, 12]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/MultiPoint-Polygon.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [[-3, -3], [-2, -2]]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-1, 2], [3, 2], [3, 3], [-1, 3], [-1, 2]]]
}
}
]
}
97 changes: 97 additions & 0 deletions turf/boolean_intersects/tests/false/MultiPolygon-Polygon.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"fill": "#ff0000"
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
122.6953125,
-19.186677697957833
],
[
128.759765625,
-19.186677697957833
],
[
128.759765625,
-15.28418511407642
],
[
122.6953125,
-15.28418511407642
],
[
122.6953125,
-19.186677697957833
]
]
],
[
[
[
123.74999999999999,
-25.918526162075153
],
[
130.25390625,
-25.918526162075153
],
[
130.25390625,
-20.715015145512087
],
[
123.74999999999999,
-20.715015145512087
],
[
123.74999999999999,
-25.918526162075153
]
]
]
]
}
},
{
"type": "Feature",
"properties": {
"fill": "#0000ff"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
116.98242187499999,
-24.647017162630352
],
[
122.87109375,
-24.647017162630352
],
[
122.87109375,
-20.34462694382967
],
[
116.98242187499999,
-20.34462694382967
],
[
116.98242187499999,
-24.647017162630352
]
]
]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/Point-LineString.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [[1, 1], [1, 2], [1, 3], [1, 4]]
}
}
]
}
21 changes: 21 additions & 0 deletions turf/boolean_intersects/tests/false/Point-Multipoint.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPoint",
"coordinates": [[1, 1], [12, 12]]
}
}
]
}

0 comments on commit ccbf7e7

Please sign in to comment.