Commit 3700dd68 authored by jlaura's avatar jlaura Committed by Kelvin Rodriguez
Browse files

Fixes issues with empty polys (#363)

* Fixes issues with empty polys

* Fixes test due to change to ceil

* Update overlap.py
parent 762166e6
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
from math import isclose
from math import isclose, ceil
import warnings

import pandas as pd
@@ -344,8 +344,8 @@ def distribute_points(geom, nspts, ewpts):
    return valid

def distribute_points_in_geom(geom,
                              nspts_func=lambda x: int(round(x,1)*10),
                              ewpts_func=lambda x: int(round(x,1)*5)):
                              nspts_func=lambda x: ceil(round(x,1)*10),
                              ewpts_func=lambda x: ceil(round(x,1)*5)):
    """
    Given a geometry, attempt a basic classification of the shape.
    RIght now, this simply attempts to determine if the bounding box
@@ -381,7 +381,7 @@ def distribute_points_in_geom(geom,
    """
    coords = list(zip(*geom.envelope.exterior.xy))
    short = np.inf
    lng = -np.inf
    long = -np.inf
    shortid = 0
    longid = 0
    for i, p in enumerate(coords[:-1]):
@@ -389,10 +389,10 @@ def distribute_points_in_geom(geom,
        if d < short:
            short = d
            shortid = i
        if d > lng:
            lng = d
        if d > long:
            long = d
            longid = i
    ratio = short/lng
    ratio = short/long
    ns = False
    ew = False
    valid = []
@@ -403,16 +403,17 @@ def distribute_points_in_geom(geom,
        ns = True
    elif longid % 2 == 0:
        ew = True
    
    # Decision Tree
    if ratio < 0.16 and geom.area < 0.01:
        # Class: Slivers - ignore.
        return
        return []
    elif geom.area <= 0.004 and ratio >= 0.25:
        # Single point at the centroid
        valid = single_centroid(geom)
    elif ns==True:
        # Class, north/south poly, multi-point
        nspts = nspts_func(lng)
        nspts = nspts_func(long)
        ewpts = ewpts_func(short)
        if nspts == 1 and ewpts == 1:
            valid = single_centroid(geom)
@@ -421,10 +422,11 @@ def distribute_points_in_geom(geom,
    elif ew == True:
        # Since this is an LS, we should place these diagonally from the 'lower left' to the 'upper right'
        nspts = ewpts_func(short)
        ewpts = nspts_func(lng)
        ewpts = nspts_func(long)
        if nspts == 1 and ewpts == 1:
            valid = single_centroid(geom)
        else:
            valid = distribute_points(geom, nspts, ewpts)

    else:
        print('WTF Willy')
    return valid
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ def test_voronoi_keypoint_intersection(keypoints):
@pytest.mark.parametrize("polygon, nexpected",[
    (Polygon([(0,0), (.2,0), (.2,1), (0,1), (0,0)]), 10),
    (Polygon([(0,0), (1,0), (1,.2), (0,.2), (0,0)]), 10),
    (Polygon([(0,0), (.2, .1), (.2,1.1), (-0.1, 1), (0,0)]), 11)
    (Polygon([(0,0), (.2, .1), (.2,1.1), (-0.1, 1), (0,0)]), 22)
],
    ids=['vertical', 'horizontal', 'verticalskewed'])
def test_points_in_geom(polygon, nexpected):
+0 −3
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ def place_points_in_overlaps(nodes, size_threshold=0.0007,
        points.extend(place_points_in_overlap(overlapnodes, o.geom, dem=dem, cam_type=cam_type,
                                              iterative_phase_kwargs=iterative_phase_kwargs,
                                              distribute_points_kwargs=distribute_points_kwargs))

    Points.bulkadd(points)

def cluster_place_points_in_overlaps(size_threshold=0.0007,
@@ -168,7 +167,6 @@ def place_points_in_overlap(nodes, geom, dem=dem, cam_type="csm",
    semi_minor = config['spatial']['semiminor_rad']
    ecef = pyproj.Proj(proj='geocent', a=semi_major, b=semi_minor)
    lla = pyproj.Proj(proj='latlon', a=semi_major, b=semi_minor)

    valid = compgeom.distribute_points_in_geom(geom, **distribute_points_kwargs)
    if not valid:
        warnings.warn('Failed to distribute points in overlap')
@@ -193,7 +191,6 @@ def place_points_in_overlap(nodes, geom, dem=dem, cam_type="csm",
        point = Points(apriori=geom,
                       adjusted=geom,
                       pointtype=2) # Would be 3 or 4 for ground

        if cam_type == "csm":
            gnd = csmapi.EcefCoord(x, y, z)
            sic = source.camera.groundToImage(gnd)