當前位置: 首頁>>代碼示例>>Python>>正文


Python prepared.prep方法代碼示例

本文整理匯總了Python中shapely.prepared.prep方法的典型用法代碼示例。如果您正苦於以下問題:Python prepared.prep方法的具體用法?Python prepared.prep怎麽用?Python prepared.prep使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在shapely.prepared的用法示例。


在下文中一共展示了prepared.prep方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: surround_with_holes

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def surround_with_holes(geometry, hole_spacing, hole_radius, padding, max_distance):
    """
    Surrounds the given geometry with holes, which are arranged in a square lattice around the structure.
    This can be used for generating vortex traps like presented in https://doi.org/10.1103/PhysRevApplied.11.064053

    :param geometry: The geometry around which the holes are generated
    :param hole_spacing: Spacing between the holes
    :param hole_radius: Radius of the holes
    :param padding: Padding around the geometry
    :param max_distance: Maximum distance of a hole from the geometry
    :return: Shapely object, which describes the holes
    """
    geometry = geometric_union(geometry if isinstance(geometry, (tuple, list)) else (geometry,))
    buffer_around_waveguide = geometry.buffer(max_distance)
    area_for_holes = prep(buffer_around_waveguide.difference(geometry.buffer(hole_radius + padding)))
    area = buffer_around_waveguide.bounds
    points = (Point(x, y) for x in np.arange(area[0], area[2], hole_spacing) for y in
              np.arange(area[1], area[3], hole_spacing))
    return MultiPolygon([point.buffer(hole_radius) for point in points if area_for_holes.contains(point)]) 
開發者ID:HelgeGehring,項目名稱:gdshelpers,代碼行數:21,代碼來源:vortex_traps.py

示例2: getBridgesPoly

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def getBridgesPoly(o):
    if not hasattr(o, 'bridgespolyorig'):
        bridgecollectionname = o.bridges_collection_name
        bridgecollection = bpy.data.collections[bridgecollectionname]
        shapes = []
        bpy.ops.object.select_all(action='DESELECT')

        for ob in bridgecollection.objects:
            if ob.type == 'CURVE':
                ob.select_set(state=True)
        bpy.context.view_layer.objects.active = ob
        bpy.ops.object.duplicate();
        bpy.ops.object.join()
        ob = bpy.context.active_object
        shapes.extend(curveToShapely(ob, o.use_bridge_modifiers))
        ob.select_set(state=True)
        bpy.ops.object.delete(use_global=False)
        bridgespoly = sops.unary_union(shapes)

        # buffer the poly, so the bridges are not actually milled...
        o.bridgespolyorig = bridgespoly.buffer(distance=o.cutter_diameter / 2.0)
        o.bridgespoly_boundary = o.bridgespolyorig.boundary
        o.bridgespoly_boundary_prep = prepared.prep(o.bridgespolyorig.boundary)
        o.bridgespoly = prepared.prep(o.bridgespolyorig) 
開發者ID:vilemduha,項目名稱:blendercam,代碼行數:26,代碼來源:utils.py

示例3: get_geometry_cells

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def get_geometry_cells(self, geometry, bounds=None):
        if bounds is None:
            bounds = self._get_geometry_bounds(geometry)
        minx, miny, maxx, maxy = bounds

        height, width = self.data.shape
        minx = max(minx, self.x)
        miny = max(miny, self.y)
        maxx = min(maxx, self.x + width)
        maxy = min(maxy, self.y + height)

        from shapely import prepared
        from shapely.geometry import box

        cells = np.zeros_like(self.data, dtype=np.bool)
        prep = prepared.prep(geometry)
        res = self.resolution
        for iy, y in enumerate(range(miny * res, maxy * res, res), start=miny - self.y):
            for ix, x in enumerate(range(minx * res, maxx * res, res), start=minx - self.x):
                if prep.intersects(box(x, y, x + res, y + res)):
                    cells[iy, ix] = True

        return cells 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:25,代碼來源:indexed.py

示例4: _tiles_inside_geom

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def _tiles_inside_geom(tilescheme, tiles, geom):
    """Filters out tiles do not contain the geometry geom

    Consider the nine adjacent tiles:

       -------------
       | 1 | 2 | 3 |
       -------------
       | 4 | 5 | 6 |
       -------------
       | 7 | 8 | 9 |
       -------------

    if the AOI is 5, _tiles_inside_geom will only return 5.  Note that
    tiletanic.tilecover.cover_geometry returns all 9 tiles

    Args:
      tilescheme: The tile scheme to use.
      tiles: list iterable collection of tiles
      geom: Shapely Geometry area of interest
    """
    prep_geom = prepared.prep(geom)
    for t in tiles:
        coords = tilescheme.bbox(t)
        tile_geom = geometry.Polygon(((coords.xmin, coords.ymin),
                                      (coords.xmax, coords.ymin),
                                      (coords.xmax, coords.ymax),
                                      (coords.xmin, coords.ymax),
                                      (coords.xmin, coords.ymin)))

        # Touches: The Geometries have at least one boundary point in
        # common, but no interior points
        if not prep_geom.touches(tile_geom):
            yield t 
開發者ID:DigitalGlobe,項目名稱:tiletanic,代碼行數:36,代碼來源:cli.py

示例5: cover_geometry

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def cover_geometry(tilescheme, geom, zooms):
    """Covers the provided geometry with tiles.

    Args:
        tilescheme: The tile scheme to use.  This needs to implement
                    the public protocal of the schemes defined within
                    tiletanic.
        geom: The geometry we would like to cover.  This should be a
              shapely geometry.
        zooms: The zoom levels of the tiles to cover geom with.  If
               you provide an iterable of zoom levels, you'll get the
               biggest tiles available that cover the geometry at
               those levels.

    Yields:
        An iterator of Tile objects ((x, y, z) named tuples) that
        cover the input geometry.
    """
    # Only shapely geometries allowed.
    if not isinstance(geom, geometry.base.BaseGeometry):
        raise ValueError("Input 'geom' is not a known shapely geometry type")

    if geom.is_empty:
        return

    zooms = zooms if isinstance(zooms, Iterable) else [zooms]

    # Generate the covering.
    prep_geom = prepared.prep(geom)    
    if isinstance(geom, (geometry.Polygon, geometry.MultiPolygon)):        
        for tile in _cover_polygonal(tilescheme, Tile(0, 0, 0), prep_geom, geom, zooms):
            yield tile
    else:
        for tile in _cover_geometry(tilescheme, Tile(0, 0, 0), prep_geom, geom, zooms):
            yield tile 
開發者ID:DigitalGlobe,項目名稱:tiletanic,代碼行數:37,代碼來源:tilecover.py

示例6: fill_waveguide_with_holes_in_honeycomb_lattice

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def fill_waveguide_with_holes_in_honeycomb_lattice(waveguide, spacing, padding, hole_radius):
    """
    Fills a given waveguide with holes which are arranged in a honeycomb structure
    This can be used for generating vortex traps like presented in https://doi.org/10.1103/PhysRevApplied.11.064053

    :param waveguide: Waveguide to be filled
    :param spacing: Spacing between the holes
    :param padding: Minimum distance from the edge of the waveguide to the holes
    :param hole_radius: Radius of the holes
    :return: Shapely object, which describes the holes
    """
    center_coordinates = LineString(waveguide.center_coordinates)
    outline = prep(waveguide.get_shapely_outline().buffer(hole_radius).buffer(-padding - 2 * hole_radius))
    area_for_holes = prep(waveguide.get_shapely_object().buffer(hole_radius).buffer(-padding - 2 * hole_radius))
    circles = []

    offset = 0
    new_circles = True
    while new_circles:
        new_circles = False
        for i, pos in enumerate(np.arange(padding, center_coordinates.length - padding, np.sqrt(3 / 4) * spacing)):
            xy = np.array(center_coordinates.interpolate(pos))
            diff = np.array(center_coordinates.interpolate(pos + padding / 2)) - np.array(
                center_coordinates.interpolate(pos - padding / 2))
            d1 = np.array((-diff[1], diff[0])) / np.linalg.norm(diff)
            for direction in [-1, 1]:
                point = Point(xy + direction * (offset + spacing / 2 * (i % 2)) * d1)
                if outline.contains(point):
                    new_circles = True
                if area_for_holes.contains(point):
                    circles.append(point.buffer(hole_radius))
        offset += spacing
    return cascaded_union(circles) 
開發者ID:HelgeGehring,項目名稱:gdshelpers,代碼行數:35,代碼來源:vortex_traps.py

示例7: geometry_prep

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def geometry_prep(self):
        return prepared.prep(self.src.geometry) 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:4,代碼來源:router.py

示例8: clear_geometry_prep

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def clear_geometry_prep(self):
        return prepared.prep(self.clear_geometry) 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:4,代碼來源:router.py

示例9: __init__

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def __init__(self, geometry=None):
        self.geometry = geometry
        self.geometry_prep = None if geometry is None else prepared.prep(geometry) 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:5,代碼來源:renderdata.py

示例10: covered_by

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def covered_by(self, container):
        relevant_geometries = self.query(container)
        prepared_container = prep(container)
        return relevant_geometries[relevant_geometries.apply(prepared_container.covers)] 
開發者ID:mggg,項目名稱:maup,代碼行數:6,代碼來源:indexed_geometries.py

示例11: compute_indicatormatrix

# 需要導入模塊: from shapely import prepared [as 別名]
# 或者: from shapely.prepared import prep [as 別名]
def compute_indicatormatrix(orig, dest, orig_proj='latlong', dest_proj='latlong'):
    """
    Compute the indicatormatrix

    The indicatormatrix I[i,j] is a sparse representation of the ratio
    of the area in orig[j] lying in dest[i], where orig and dest are
    collections of polygons, i.e.

    A value of I[i,j] = 1 indicates that the shape orig[j] is fully
    contained in shape dest[j].

    Note that the polygons must be in the same crs.

    Parameters
    ---------
    orig : Collection of shapely polygons
    dest : Collection of shapely polygons

    Returns
    -------
    I : sp.sparse.lil_matrix
      Indicatormatrix
    """

    dest = reproject_shapes(dest, dest_proj, orig_proj)
    indicator = sp.sparse.lil_matrix((len(dest), len(orig)), dtype=np.float)

    try:
        from rtree.index import Index

        idx = Index()
        for j, o in enumerate(orig):
            idx.insert(j, o.bounds)

        for i, d in enumerate(dest):
            for j in idx.intersection(d.bounds):
                o = orig[j]
                area = d.intersection(o).area
                indicator[i,j] = area/o.area

    except ImportError:
        logger.warning("Rtree is not available. Falling back to slower algorithm.")

        dest_prepped = list(map(prep, dest))

        for i,j in product(range(len(dest)), range(len(orig))):
            if dest_prepped[i].intersects(orig[j]):
                area = dest[i].intersection(orig[j]).area
                indicator[i,j] = area/orig[j].area

    return indicator 
開發者ID:PyPSA,項目名稱:atlite,代碼行數:53,代碼來源:gis.py


注:本文中的shapely.prepared.prep方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。