当前位置: 首页>>代码示例>>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;未经允许,请勿转载。