当前位置: 首页>>代码示例>>Python>>正文


Python geometry.MultiPolygon方法代码示例

本文整理汇总了Python中shapely.geometry.MultiPolygon方法的典型用法代码示例。如果您正苦于以下问题:Python geometry.MultiPolygon方法的具体用法?Python geometry.MultiPolygon怎么用?Python geometry.MultiPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shapely.geometry的用法示例。


在下文中一共展示了geometry.MultiPolygon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _line_iterator

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def _line_iterator(obj):
    if isinstance(obj, (sg.LineString)):
        yield obj
    elif isinstance(obj, (sg.MultiLineString)):
        for obj2 in obj.geoms:
            yield obj2
    elif isinstance(obj, (sg.Polygon)):
        yield sg.LineString(obj.exterior)
        for obj2 in obj.interiors:
            yield sg.LineString(obj2)
    elif isinstance(obj, (sg.MultiPolygon)):
        for obj2 in obj.geoms:
            yield sg.LineString(obj2.exterior)
            for obj3 in obj2.interiors:
                yield sg.LineString(obj3)
    else:
        try:
            tup = tuple(obj)
        except TypeError:
            raise TypeError('Could not use type %s' % type(obj))
        else:
            for obj2 in tup:
                for line in _line_iterator(obj2):
                    yield line 
开发者ID:airware,项目名称:buzzard,代码行数:26,代码来源:_footprint.py

示例2: _any_geom_to_shapely

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def _any_geom_to_shapely(geom):
    """Any geom to shapely object. Points should have homogeneous dimensions size."""
    if isinstance(geom, (sg.LineString, sg.Point, sg.Polygon, sg.MultiPolygon)):
        return geom
    if isinstance(geom, dict):
        return sg.shape(geom['geometry'])
    if isinstance(geom, collections.Container):
        geom = np.asarray(geom)
        if geom.ndim == 1:
            return sg.Point(geom.tolist())
        elif geom.ndim == 2:
            return sg.LineString(geom.tolist())
        elif geom.ndim == 3:
            return sg.Polygon(*geom.tolist())
        elif geom.ndim == 4:
            return sg.MultiPolygon([
                sg.Polygon(*poly)
                for poly in geom.tolist()
            ])
    assert False 
开发者ID:airware,项目名称:buzzard,代码行数:22,代码来源:test_vectorsource_getsetdata_general.py

示例3: main

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def main():
    mm = 25.4
    w = 8.5 * mm
    h = 11 * mm
    p = 0.5 * mm
    states = MultiPolygon(load_shapes(STATES))
    # counties = MultiPolygon(load_shapes(COUNTIES))
    # counties = counties.simplify(100)
    g = xy.GCode.from_geometry(states)
    g = g.rotate(90)
    g = g.scale_to_fit(w, h, p).move(w / 2, p, 0.5, 0)
    # im = g.render(0, 0, w, h, 96 / mm)
    # im.write_to_png('usa.png')
    # g.save('usa.nc')
    device = xy.Device()
    device.home()
    device.gcode(g) 
开发者ID:fogleman,项目名称:xy,代码行数:19,代码来源:usa.py

示例4: main

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def main():
    paths = []
    for path in PATHS:
        path = xy.parse_svg_path(path)
        path.append(path[0])
        paths.extend(path)
    polygons = [geometry.Polygon(x) for x in paths]
    lines = geometry.MultiPolygon(polygons)
    for i in range(4):
        n = 3 - i
        o = i * 10
        for j in range(-n, n + 1):
            paths += convert(lines.buffer(o + j * 0.667))
    drawing = xy.Drawing(paths).scale(1, -1).rotate_and_scale_to_fit(315, 380, step=90)
    im = drawing.render()
    im.write_to_png('frog.png')
    # xy.draw(drawing) 
开发者ID:fogleman,项目名称:xy,代码行数:19,代码来源:frog.py

示例5: __init__

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def __init__(self, shape_list, crs, bbox_size):
        """
        :param shape_list: A list of geometrical shapes describing the area of interest
        :type shape_list: list(shapely.geometry.multipolygon.MultiPolygon or shapely.geometry.polygon.Polygon)
        :param crs: Coordinate reference system of the shapes in `shape_list`
        :type crs: CRS
        :param bbox_size: Physical size in metres of generated bounding boxes. Could be a float or tuple of floats
        :type bbox_size: int or (int, int) or float or (float, float)
        """
        super().__init__(shape_list, crs)

        self.bbox_size = self._parse_split_parameters(bbox_size, allow_float=True)

        self.shape_geometry = Geometry(self.area_shape, self.crs).transform(CRS.WGS84)

        self.utm_grid = self._get_utm_polygons()

        self._make_split() 
开发者ID:sentinel-hub,项目名称:sentinelhub-py,代码行数:20,代码来源:areas.py

示例6: test_results

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def test_results(self):
        for test_case in self.test_cases:
            with self.subTest(msg='Test case {}'.format(test_case.name)):
                iterator = test_case.request

                features = list(iterator)
                dates = iterator.get_dates()
                geometries = iterator.get_geometries()
                tiles = iterator.get_tiles()

                for result_list, expected_type in [(features, dict), (dates, datetime.datetime),
                                                   (geometries, MultiPolygon), (tiles, tuple)]:
                    self.assertEqual(len(result_list), test_case.result_len)
                    for result in result_list:
                        self.assertTrue(isinstance(result, expected_type),
                                        msg='Expected type {}, got type {}'.format(expected_type, type(result))) 
开发者ID:sentinel-hub,项目名称:sentinelhub-py,代码行数:18,代码来源:test_ogc.py

示例7: test_cover_geometry_empty_geoms

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def test_cover_geometry_empty_geoms(tiler):
    """Empty geometries should return empty iterators."""
    assert not cover_geometry(tiler, geometry.Point(), 0) == True
    assert not cover_geometry(tiler, geometry.Point(), [0, 1]) == True
    assert not cover_geometry(tiler, geometry.MultiPoint(), 0) == True
    assert not cover_geometry(tiler, geometry.MultiPoint(), [0, 1]) == True
    assert not cover_geometry(tiler, geometry.LineString(), 0) == True
    assert not cover_geometry(tiler, geometry.LineString(), [0, 1]) == True
    assert not cover_geometry(tiler, geometry.MultiLineString(), 0) == True
    assert not cover_geometry(tiler, geometry.MultiLineString(), [0, 1]) == True
    assert not cover_geometry(tiler, geometry.Polygon(), 0) == True
    assert not cover_geometry(tiler, geometry.Polygon(), [0, 1]) == True
    assert not cover_geometry(tiler, geometry.MultiPolygon(), 0) == True
    assert not cover_geometry(tiler, geometry.MultiPolygon(), [0, 1]) == True
    assert not cover_geometry(tiler, geometry.GeometryCollection(), 0) == True
    assert not cover_geometry(tiler, geometry.GeometryCollection(), [0, 1]) == True 
开发者ID:DigitalGlobe,项目名称:tiletanic,代码行数:18,代码来源:test_tilecover.py

示例8: AttemptCollapse

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def AttemptCollapse(name, zone):
  overlaps = False
  for i in range(0,len(zone)):
    for j in range(i+1, len(zone)):
      if zone[i].overlaps(zone[j]):
        overlaps = True
        break
    if overlaps:
      break

  if overlaps:
    print 'Found overlapping zone on %s!' % name
    mp = SMultiPolygon(zone)
    collapsed = cascaded_union(mp)
    if type(collapsed) == SPolygon:
      return [collapsed]
    else:
      print 'Got multipolygon len %d' % len(collapsed.geoms)
      return collapsed.geoms
  else:
    print 'Non-overlapping zone on %s (%d)' % (name, len(zone))
    return zone 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:24,代码来源:protection_zones.py

示例9: test_remove_small_holes

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def test_remove_small_holes(self):
    # Test all degenerate shapes (points, lines) have area zero
    # Use a small sw=quare centered around 60degree latitude, so radius is half
    # on the longitude
    square = sgeo.Polygon([(4, 59), (6, 59), (6, 61), (4, 61)])
    hole = sgeo.Polygon([(5, 60), (5.01, 60.01), (5, 60.02)])
    square_with_hole = sgeo.Polygon([(4, 59), (6, 59), (6, 61), (4, 61)],
                                    [[(5, 60), (5.01, 60.01), (5, 60.02)]])
    square_cleaned = utils.PolyWithoutSmallHoles(square_with_hole,
                                                 min_hole_area_km2= 0.62)
    multipoly = sgeo.MultiPolygon([square_with_hole, hole])
    multipoly_cleaned = utils.PolyWithoutSmallHoles(multipoly,
                                                    min_hole_area_km2= 0.62)
    area = utils.GeometryArea(square)
    area_with_hole = utils.GeometryArea(square_with_hole)
    self.assertAlmostEqual(area - area_with_hole, 0.617, 3)
    self.assertEqual(square, square_cleaned)
    self.assertEqual(multipoly_cleaned, sgeo.MultiPolygon([square, hole])) 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:20,代码来源:utils_test.py

示例10: test_shrinks_polygon

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def test_shrinks_polygon(self):
    with open(os.path.join(TEST_DIR, 'test_shrink.json'), 'r') as fd:
      ppa = json.load(fd)
    geometry = ppa['features'][0]['geometry']
    self.assertTrue(geometry['type'], 'Polygon')
    spoly = utils.ToShapely(geometry)
    mpoly = sgeo.MultiPolygon([sgeo.Point(0,0).buffer(1),
                               sgeo.Point(2,0).buffer(0.1)])
    poly1 = utils.ShrinkAndCleanPolygon(geometry, 1e-2)
    poly2 = utils.ShrinkAndCleanPolygon(spoly, 1e-2)
    self.assertTrue(poly2.area < spoly.area)
    with self.assertRaises(ValueError):
      poly = utils.ShrinkAndCleanPolygon(mpoly, 1e-2)
    self.assertEqual(poly1['type'], 'Polygon')
    self.assertTrue(isinstance(poly2, sgeo.Polygon))
    spoly1 = utils.ToShapely(poly1)
    self.assertEqual(poly2.difference(spoly1).area, 0)
    self.assertEqual(spoly1.difference(poly2).area, 0) 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:20,代码来源:utils_test.py

示例11: _GeoJsonToShapelyGeometry

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def _GeoJsonToShapelyGeometry(geometry):
  """Returns a |shapely| geometry from a GeoJSON geometry.

  Args:
    geometry: A dict or string representing a GeoJSON geometry.

  Raises:
    ValueError: If invalid GeoJSON geometry is passed.
  """
  if isinstance(geometry, basestring):
    geometry = json.loads(geometry)
  if not isinstance(geometry, dict) or 'type' not in geometry:
    raise ValueError('Invalid GeoJSON geometry.')

  if 'geometries' in geometry:
    return sgeo.GeometryCollection([_GeoJsonToShapelyGeometry(g)
                                    for g in geometry['geometries']])
  geometry = sgeo.shape(geometry)
  if isinstance(geometry, sgeo.Polygon) or isinstance(geometry, sgeo.MultiPolygon):
    geometry = geometry.buffer(0)
  return geometry 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:23,代码来源:utils.py

示例12: PolyWithoutSmallHoles

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def PolyWithoutSmallHoles(poly, min_hole_area_km2=0.5):
  """Returns input |shapely| geometry with small internal holes removed.

  Args:
    poly: A shapely polygon geometry (Polygon or MultiPolygon) defined in WGS84
       or in NAD83 (lon, lat) coordinates (degrees).
  min_hole_area_km2: the minimum area for holes to be kept (in km2).

  Returns:
    (a |shapely| geometry) The input geometry with all small holes removed.
  """
  if isinstance(poly, sgeo.Polygon):
    interiors = [interior
                 for interior in poly.interiors
                 if GeometryArea(sgeo.Polygon(interior)) > min_hole_area_km2]
    if len(interiors) == len(poly.interiors):
      return poly
    else:
      return sgeo.Polygon(poly.exterior, interiors)
  elif isinstance(poly, sgeo.MultiPolygon):
    return sgeo.MultiPolygon([PolyWithoutSmallHoles(p, min_hole_area_km2)
                              for p in poly])
  else:
    raise ValueError('Input geometry is not a shapely Polygon or MultiPolygon') 
开发者ID:Wireless-Innovation-Forum,项目名称:Spectrum-Access-System,代码行数:26,代码来源:utils.py

示例13: _force_geometry_2d

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def _force_geometry_2d(geometry):
    """ Convert a geometry to 2d
    """
    if geometry["type"] in ["Polygon", "MultiLineString"]:
        geometry["coordinates"] = [
            _force_linestring_2d(l) for l in geometry["coordinates"]
        ]
    elif geometry["type"] in ["LineString", "MultiPoint"]:
        geometry["coordinates"] = _force_linestring_2d(geometry["coordinates"])
    elif geometry["type"] == "Point":
        geometry["coordinates"] = geometry["coordinates"][:2]
    elif geometry["type"] == "MultiPolygon":
        geometry["coordinates"] = [
            [_force_linestring_2d(l) for l in g] for g in geometry["coordinates"]
        ]

    return geometry 
开发者ID:OpenBounds,项目名称:Processing,代码行数:19,代码来源:fiona_dataset.py

示例14: surround_with_holes

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [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

示例15: _poly_iterator

# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import MultiPolygon [as 别名]
def _poly_iterator(obj):
    if isinstance(obj, (sg.Polygon)):
        yield obj
    elif isinstance(obj, (sg.MultiPolygon)):
        for obj2 in obj.geoms:
            yield obj2
    else:
        try:
            tup = tuple(obj)
        except TypeError:
            raise TypeError('Could not use type %s' % type(obj))
        else:
            for obj2 in tup:
                for poly in _poly_iterator(obj2):
                    yield poly 
开发者ID:airware,项目名称:buzzard,代码行数:17,代码来源:_footprint.py


注:本文中的shapely.geometry.MultiPolygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。