Commit 908fa713 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added 'tolerance' keyword to geo.vector.topology.polyVertices_outside_poly()...


Added 'tolerance' keyword to geo.vector.topology.polyVertices_outside_poly() to avoid wring return values due to float uncertainties.
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent c0e5e3d3
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
History History
======= =======
0.14.33 (2020-08-21)
--------------------
* Added 'tolerance' keyword to geo.vector.topology.polyVertices_outside_poly()
to avoid wring return values due to float uncertainties.
0.14.32 (2020-08-18) 0.14.32 (2020-08-18)
-------------------- --------------------
......
...@@ -139,17 +139,18 @@ def find_line_intersection_point(line1, line2): ...@@ -139,17 +139,18 @@ def find_line_intersection_point(line1, line2):
return x, y return x, y
def polyVertices_outside_poly(inner_poly, outer_poly): def polyVertices_outside_poly(inner_poly, outer_poly, tolerance=0):
"""Check if a shapely polygon (inner_poly) contains vertices that do not intersect another polygon (outer_poly) """Check if a shapely polygon (inner_poly) contains vertices that do not intersect another polygon (outer_poly)
:param inner_poly: the polygon with the vertices to check :param inner_poly: the polygon with the vertices to check
:param outer_poly: the polygon where all vertices have to be inside :param outer_poly: the polygon where all vertices have to be inside
:param tolerance: tolerance of the decision
""" """
if inner_poly.within(outer_poly): if inner_poly.within(outer_poly.buffer(tolerance)):
# all vertices are inside outer_poly # all vertices are inside outer_poly
return False return False
elif inner_poly.intersects(outer_poly): elif inner_poly.intersects(outer_poly.buffer(tolerance)):
# check if all vertices intersect with outer poly # check if all vertices intersect with outer poly
GDF = GeoDataFrame(np.swapaxes(np.array(inner_poly.exterior.coords.xy), 0, 1), columns=['X', 'Y']) GDF = GeoDataFrame(np.swapaxes(np.array(inner_poly.exterior.coords.xy), 0, 1), columns=['X', 'Y'])
return False in GDF.apply(lambda GDF_row: Point(GDF_row.X, GDF_row.Y).intersects(outer_poly), axis=1).values return False in GDF.apply(lambda GDF_row: Point(GDF_row.X, GDF_row.Y).intersects(outer_poly), axis=1).values
......
...@@ -19,5 +19,5 @@ ...@@ -19,5 +19,5 @@
# You should have received a copy of the GNU Lesser General Public License along # You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.14.32' __version__ = '0.14.33'
__versionalias__ = '20200818_02' __versionalias__ = '20200821_01'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment