def setUp(self):
     line = Geometry("LineString(0 0 0, 1 2 3)")
     point = Geometry("Point(0 0 0)")
     self.rays = gpd.GeoSeries([line] * 4, crs=cn.epsg_wgs84_cart)
     self.points = gpd.GeoSeries([point] * 4, crs=cn.epsg_wgs84_cart)
     self.d = {
         "time": pd.Series([pd.Timestamp(year=2020, month=1, day=1)] * 4),
         "svid": pd.Series(["G01", "E01", "R01", "C01"])
     }
def test_coverage_union_overlapping_inputs():
    polygon = Geometry("POLYGON ((1 1, 1 0, 0 0, 0 1, 1 1))")

    # Overlapping polygons raise an error
    with pytest.raises(
            pygeos.GEOSException,
            match="CoverageUnion cannot process incorrectly noded inputs."):
        pygeos.coverage_union(
            polygon, Geometry("POLYGON ((1 0, 0.9 1, 2 1, 2 0, 1 0))"))
Exemple #3
0
@pytest.mark.parametrize("pattern", [b"*********", 10, None])
def test_relate_pattern_non_string(pattern):
    with pytest.raises(TypeError, match="expected string"):
        pygeos.relate_pattern(point, polygon, pattern)


def test_relate_pattern_non_scalar():
    with pytest.raises(ValueError, match="only supports scalar"):
        pygeos.relate_pattern([point] * 2, polygon, ["*********"] * 2)


@pytest.mark.skipif(pygeos.geos_version < (3, 7, 0), reason="GEOS < 3.7")
@pytest.mark.parametrize(
    "geom, expected",
    [
        (Geometry("LINEARRING (0 0, 0 1, 1 1, 0 0)"), False),
        (Geometry("LINEARRING (0 0, 1 1, 0 1, 0 0)"), True),
        (Geometry("LINESTRING (0 0, 0 1, 1 1, 0 0)"), False),
        (Geometry("LINESTRING (0 0, 1 1, 0 1, 0 0)"), True),
        (Geometry("LINESTRING (0 0, 1 1, 0 1)"), False),
        (Geometry("LINESTRING (0 0, 0 1, 1 1)"), False),
        (point, False),
        (polygon, False),
        (geometry_collection, False),
        (None, False),
    ],
)
def test_is_ccw(geom, expected):
    assert pygeos.is_ccw(geom) == expected

def test_voronoi_polygons_only_edges():
    # example from PostGIS docs
    original = Geometry("MULTIPOINT (50 30, 60 30, 100 100, 10 150, 110 120)")
    actual = pygeos.voronoi_polygons(original, only_edges=True)
    assert pygeos.get_num_geometries(actual) == 7
def test_voronoi_polygons():
    original = Geometry("MULTIPOINT (50 30, 60 30, 100 100, 10 150, 110 120)")
    actual = pygeos.voronoi_polygons(original)
    assert pygeos.get_num_geometries(actual) == 5
def test_delaunay_triangles_only_edges():
    original = Geometry("MULTIPOINT (50 30, 60 30, 100 100, 10 150, 110 120)")
    actual = pygeos.delaunay_triangles(original, only_edges=True)
    assert pygeos.get_num_geometries(actual) == 7
Exemple #7
0
def test_clip_by_rect_empty(geom):
    # TODO empty point
    actual = pygeos.clip_by_rect(geom, 0, 0, 1, 1)
    assert actual == Geometry("GEOMETRYCOLLECTION EMPTY")
Exemple #8
0
@pytest.mark.skipif(pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8")
def test_build_area_none():
    actual = pygeos.build_area(None)
    assert actual is None


@pytest.mark.skipif(pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8")
@pytest.mark.parametrize(
    "geom,expected",
    [
        (point, empty),  # a point has no area
        (line_string, empty),  # a line string has no area
        # geometry collection of two polygons are combined into one
        (
            Geometry(
                "GEOMETRYCOLLECTION(POLYGON((0 0, 3 0, 3 3, 0 3, 0 0)), POLYGON((1 1, 1 2, 2 2, 1 1)))"
            ),
            Geometry("POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 2 2, 1 2, 1 1))"),
        ),
        (empty, empty),
        ([empty], [empty]),
    ],
)
def test_build_area(geom, expected):
    actual = pygeos.build_area(geom)
    assert actual is not expected
    assert actual == expected


@pytest.mark.skipif(pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8")
def test_make_valid_none():

@pytest.mark.skipif(pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8")
def test_make_valid_none():
    actual = pygeos.make_valid(None)
    assert actual is None


@pytest.mark.skipif(pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8")
@pytest.mark.parametrize(
    "geom,expected",
    [
        (point, point),  # a valid geometry stays the same (but is copied)
        # an L shaped polygon without area is converted to a multilinestring
        (
            Geometry("POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))"),
            Geometry("MULTILINESTRING ((0 0, 1 1), (1 1, 1 2))"),
        ),
        # a polygon with self-intersection (bowtie) is converted into polygons
        (
            Geometry("POLYGON((0 0, 2 2, 2 0, 0 2, 0 0))"),
            Geometry(
                "MULTIPOLYGON (((1 1, 0 0, 0 2, 1 1)), ((1 1, 2 2, 2 0, 1 1)))"
            ),
        ),
        (empty, empty),
        ([empty], [empty])
    ],
)
def test_make_valid(geom, expected):
    actual = pygeos.make_valid(geom)
Exemple #10
0
        -72.2751045,
        42.9279991
      )])

def merge(p1, p2, intersection_with_former=True):
    if intersection_with_former:
        p2new = p2.difference(p1)
        p1new = p1
    else:
        p1new = p1.difference(p2)
        p2new = p2
    return p1new, p2new

p1new, p2new = (p1.difference(p2), p2.difference(p1))

pyg_p1new = Geometry(p1new.wkt)
pyg_p2new = Geometry(p2new.wkt)

x = p1.intersection(p2)


# converting to list of lists
coordinates = x.exterior.coords
minlat, minlon, maxlat, maxlon = (coordinates[0][0], coordinates[0][1], coordinates[0][0], coordinates[0][1])
print(coordinates[0])
for i, coord in enumerate(coordinates):
    minlat = min(minlat, coord[0])
    minlon = min(minlon, coord[1])
    maxlat = max(maxlat, coord[0])
    maxlon = max(maxlon, coord[1])