def test_points_in_shape(): f = feature(0, 8, population=100) population = f.properties["population"] geom = geometry.shape(f.geometry) points = dotdensity.points_in_shape(geom, population) assert len(points) == population
def test_missing_field(): f = feature(1, 5, population=100, cats=None) points = dotdensity.points_in_feature(f, ["households"], coerce=True) points = list(points) assert len(points) == 0 points = dotdensity.points_in_feature(f, ["cats"], coerce=True) assert len(list(points)) == 0
def test_total_area(): f = feature(0, population=100) geom = geometry.shape(f.geometry) triangles = [t for t in triangulate(geom) if t.within(geom)] ratios = [t.area / geom.area for t in triangles] counts = [r * f.properties["population"] for r in ratios] # account for floats tolerance = 0.0001 # should match assert geom.area == sum(t.area for t in triangles) # make sure we get close assert 1 - sum(ratios) < tolerance # should add up assert abs(sum(counts) - f.properties["population"]) < tolerance
def test_coerce_to_int(): f = feature(None, 5, geoid="01", population="100") points = dotdensity.points_in_feature(f, ["population"], coerce=True) assert 100 == len(list(points))
def test_custom_fid(): f = feature(None, 5, geoid="01", population=100) points = dotdensity.points_in_feature(f, ["population"], fid_field="geoid") for point in points: assert "01" == point.fid