Ejemplo n.º 1
0
 def _geom_in_coverage_srs(self, geom, srs):
     if isinstance(geom, shapely.geometry.base.BaseGeometry):
         if srs != self.srs:
             geom = transform_geometry(srs, self.srs, geom)
     elif len(geom) == 2:
         if srs != self.srs:
             geom = srs.transform_to(self.srs, geom)
         geom = shapely.geometry.Point(geom)
     else:
         if srs != self.srs:
             geom = srs.transform_bbox_to(self.srs, geom)
         geom = bbox_polygon(geom)
     return geom
Ejemplo n.º 2
0
def load_limited_to(limited_to):
    require_geom_support()
    srs = SRS(limited_to['srs'])
    geom = limited_to['geometry']

    if not hasattr(geom, 'type'): # not a Shapely geometry
        if isinstance(geom, (list, tuple)):
            geom = bbox_polygon(geom)
        else:
            polygons = load_polygon_lines(geom.split('\n'))
            if len(polygons) == 1:
                geom = polygons[0]
            else:
                geom = shapely.geometry.MultiPolygon(polygons)

    return GeomCoverage(geom, srs, clip=True)
Ejemplo n.º 3
0
def union_coverage(coverages, clip=None):
    """
    Create a coverage that is the union of all `coverages`.
    Resulting coverage is in the SRS of the first coverage.
    """
    srs = coverages[0].srs

    coverages = [c.transform_to(srs) for c in coverages]

    geoms = []
    for c in coverages:
        if isinstance(c, BBOXCoverage):
            geoms.append(bbox_polygon(c.bbox))
        else:
            geoms.append(c.geom)

    import shapely.ops
    union = shapely.ops.cascaded_union(geoms)

    return GeomCoverage(union, srs=srs, clip=clip)
Ejemplo n.º 4
0
def intersection_coverage(coverages, clip=None):
    """
    Create a coverage by creating the intersection of all `coverages`.
    Resulting coverage is in the SRS of the first coverage.
    """
    srs = coverages[0].srs

    coverages = [c.transform_to(srs) for c in coverages]

    geoms = []
    for c in coverages:
        if isinstance(c, BBOXCoverage):
            geoms.append(bbox_polygon(c.bbox))
        else:
            geoms.append(c.geom)

    intersection = reduce(lambda a, b: a.intersection(b), geoms)

    if intersection.is_empty:
        raise EmptyGeometryError("intersection did not return any geometry")

    return GeomCoverage(intersection, srs=srs, clip=clip)
Ejemplo n.º 5
0
def diff_coverage(coverages, clip=None):
    """
    Create a coverage by subtracting all `coverages` from the first one.
    Resulting coverage is in the SRS of the first coverage.
    """
    srs = coverages[0].srs

    coverages = [c.transform_to(srs) for c in coverages]

    geoms = []
    for c in coverages:
        if isinstance(c, BBOXCoverage):
            geoms.append(bbox_polygon(c.bbox))
        else:
            geoms.append(c.geom)

    sub = shapely.ops.cascaded_union(geoms[1:])
    diff = geoms[0].difference(sub)

    if diff.is_empty:
        raise EmptyGeometryError("diff did not return any geometry")

    return GeomCoverage(diff, srs=srs, clip=clip)
Ejemplo n.º 6
0
 def test_bbox_polygon(self):
     p = bbox_polygon([5, 53, 6, 54])
     eq_(p.type, 'Polygon')