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


Python geometry.GeometryCollection方法代碼示例

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


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

示例1: test_cover_geometry_empty_geoms

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [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

示例2: _GeoJsonToShapelyGeometry

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [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

示例3: _make_split

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def _make_split(self):
        """ Split each UTM grid into equally sized bboxes in correct UTM zone
        """
        size_x, size_y = self.bbox_size
        self.bbox_list = []
        self.info_list = []

        index = 0

        for utm_cell in self.utm_grid:
            utm_cell_geom, utm_cell_prop = utm_cell
            # the UTM MGRS grid definition contains four 0 zones at the poles (0A, 0B, 0Y, 0Z)
            if utm_cell_prop['zone'] == 0:
                continue
            utm_crs = self._get_utm_from_props(utm_cell_prop)

            intersection = utm_cell_geom.intersection(self.shape_geometry.geometry)

            if not intersection.is_empty and isinstance(intersection, GeometryCollection):
                intersection = MultiPolygon(geo_object for geo_object in intersection
                                            if isinstance(geo_object, (Polygon, MultiPolygon)))

            if not intersection.is_empty:
                intersection = Geometry(intersection, CRS.WGS84).transform(utm_crs)

                bbox_partition = self._align_bbox_to_size(intersection.bbox).get_partition(size_x=size_x, size_y=size_y)

                columns, rows = len(bbox_partition), len(bbox_partition[0])
                for i, j in itertools.product(range(columns), range(rows)):
                    if bbox_partition[i][j].geometry.intersects(intersection.geometry):
                        self.bbox_list.append(bbox_partition[i][j])
                        self.info_list.append(dict(crs=utm_crs.name,
                                                   utm_zone=str(utm_cell_prop['zone']).zfill(2),
                                                   utm_row=utm_cell_prop['row'],
                                                   direction=utm_cell_prop['direction'],
                                                   index=index,
                                                   index_x=i,
                                                   index_y=j))
                        index += 1 
開發者ID:sentinel-hub,項目名稱:sentinelhub-py,代碼行數:41,代碼來源:areas.py

示例4: _get_flat_poly_iter

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def _get_flat_poly_iter(cls, poly):
        if (isinstance(poly, shgeo.MultiPolygon) or
                isinstance(poly, shgeo.MultiLineString) or
                isinstance(poly, shgeo.GeometryCollection)):
            yield from poly
        else:
            yield poly 
開發者ID:ucb-art,項目名稱:BAG_framework,代碼行數:9,代碼來源:template.py

示例5: geometry_collection

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def geometry_collection():
    return geometry.GeometryCollection(
        (
            geometry.Point(0, 0),
            geometry.LineString([(0, 0), (0.8, 0.8), (1.8, 0.95), (2.6, 0.5)]),
            geometry.Polygon([[0, 0], [0, 4], [4, 4], [4, 0]]),
        )
    ) 
開發者ID:fitodic,項目名稱:centerline,代碼行數:10,代碼來源:conftest.py

示例6: HasCorrectGeoJsonWinding

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def HasCorrectGeoJsonWinding(geometry):
  """Returns True if a GeoJSON geometry has correct windings.

  A GeoJSON polygon should follow the right-hand rule with respect to the area it
  bounds, ie exterior rings are CCW and holes are CW.

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

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

  def _HasSinglePolygonCorrectWinding(coords):
    exterior = coords[0]
    if not sgeo.LinearRing(exterior).is_ccw:
      return False
    for hole in coords[1:]:
      if sgeo.LinearRing(hole).is_ccw:
        return False
    return True

  if geometry['type'] == 'Polygon':
    coords = geometry['coordinates']
    return _HasSinglePolygonCorrectWinding(coords)
  elif geometry['type'] == 'MultiPolygon':
    for coords in geometry['coordinates']:
      if not _HasSinglePolygonCorrectWinding(coords):
        return False
    return True
  elif geometry['type'] == 'GeometryCollection':
    for subgeo in geometry['geometries']:
      if not HasCorrectGeoJsonWinding(subgeo):
        return False
    return True
  else:
    return True 
開發者ID:Wireless-Innovation-Forum,項目名稱:Spectrum-Access-System,代碼行數:43,代碼來源:utils.py

示例7: GetUrbanAreas

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def GetUrbanAreas(simplify_deg=1e-3):
  """Gets the US urban area as a |shapely.GeometryCollection|.

  Note: Client code should cache it as expensive to load (and not cached here).

  Args:
    simplify_deg: if defined, simplify the zone with given tolerance (degrees).
      Default is 1e-3 which corresponds roughly to 100m in continental US.
  """
  kml_file = os.path.join(CONFIG.GetNtiaDir(), URBAN_AREAS_FILE)
  zones = _ReadKmlZones(kml_file, root_id_zone='Document', simplify=simplify_deg)
  urban_areas = sgeo.GeometryCollection(zones.values())  # ops.unary_union(zones.values())
  return urban_areas 
開發者ID:Wireless-Innovation-Forum,項目名稱:Spectrum-Access-System,代碼行數:15,代碼來源:zones.py

示例8: shapely_to_mpl

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def shapely_to_mpl(geometry):
    """
    convert a shapely Polygon or Multipolygon to a matplotlib Path
    :param polygon: shapely Polygon or Multipolygon
    :return: MplPathProxy
    """
    if isinstance(geometry, Polygon):
        return MplPolygonPath(geometry)
    elif isinstance(geometry, MultiPolygon) or geometry.is_empty or isinstance(geometry, GeometryCollection):
        return MplMultipolygonPath(geometry)
    raise TypeError 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:13,代碼來源:mpl.py

示例9: wrapped_geom

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def wrapped_geom(self):
        if not self.wrapped_geojson['coordinates']:
            return GeometryCollection()
        return shapely_shape(self.wrapped_geojson) 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:6,代碼來源:geometry.py

示例10: assert_multipolygon

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def assert_multipolygon(geometry: Union[Polygon, MultiPolygon, GeometryCollection]) -> List[Polygon]:
    """
    given a Polygon or a MultiPolygon, return a list of Polygons
    :param geometry: a Polygon or a MultiPolygon
    :return: a list of Polygons
    """
    if geometry.is_empty:
        return []
    if isinstance(geometry, Polygon):
        return [geometry]
    return [geom for geom in geometry.geoms if isinstance(geom, Polygon)] 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:13,代碼來源:geometry.py

示例11: assert_multilinestring

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def assert_multilinestring(geometry: Union[LineString, MultiLineString, GeometryCollection]) -> List[LineString]:
    """
    given a LineString or MultiLineString, return a list of LineStrings
    :param geometry: a LineString or a MultiLineString
    :return: a list of LineStrings
    """
    if geometry.is_empty:
        return []
    if isinstance(geometry, LineString):
        return [geometry]
    return [geom for geom in geometry.geoms if isinstance(geom, LineString)] 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:13,代碼來源:geometry.py

示例12: hybrid_union

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def hybrid_union(geoms):
    if not geoms:
        return HybridGeometry(GeometryCollection(), ())
    if len(geoms) == 1:
        return geoms[0]
    add_faces = {}
    for other in geoms:
        for crop_id, faces in other.add_faces.items():
            add_faces[crop_id] = add_faces.get(crop_id, ()) + faces
    return HybridGeometry(geom=unary_union(tuple(geom.geom for geom in geoms)),
                          faces=tuple(chain(*(geom.faces for geom in geoms))),
                          add_faces=add_faces,
                          crop_ids=reduce(operator.or_, (other.crop_ids for other in geoms), set())) 
開發者ID:c3nav,項目名稱:c3nav,代碼行數:15,代碼來源:hybrid.py

示例13: at

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def at(self, idx):
        """Generate a PV segment geometry for the desired index.

        Parameters
        ----------
        idx : int
            Index to use to generate PV segment geometry

        Returns
        -------
        segment : :py:class:`~pvfactors.geometry.base.PVSurface` \
        or :py:class:`~shapely.geometry.GeometryCollection`
            The returned object will be an empty geometry if its length is
            really small, otherwise it will be a PV surface geometry
        """
        if self.length[idx] < DISTANCE_TOLERANCE:
            # return an empty geometry
            return GeometryCollection()
        else:
            # Get normal vector at idx
            n_vector = (self.n_vector[:, idx] if self.n_vector is not None
                        else None)
            # Get params at idx
            # TODO: should find faster solution
            params = _get_params_at_idx(idx, self.params)
            # Return a pv surface geometry with given params
            return PVSurface(self.coords.at(idx), shaded=self.shaded,
                             index=self.index, normal_vector=n_vector,
                             param_names=self.param_names,
                             params=params) 
開發者ID:SunPower,項目名稱:pvfactors,代碼行數:32,代碼來源:timeseries.py

示例14: get_extract_population_data

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def get_extract_population_data(city_ref, data_source, pop_shapefile=None, pop_data_file=None, to_crs={'init': 'epsg:4326'}, polygons_gdf=None):
	"""
	Get data population extract of desired data source for input city, calculating the convex hull of input buildings geodataframe
	The population data frame is projected to the desired coordinate reference system
	Stores the extracted shapefile
	Returns the stored population data for input 'data source' and 'city reference' if it was previously stored

	Parameters
	----------
	city_ref : string
		name of input city
	data_source : string
		desired population data source
	pop_shapefile : string
		path of population count shapefile
	pop_data_file : string
		path of population data additional file (required for INSEE format)
	to_crs : dict
		desired coordinate reference system
	polygons_gdf : geopandas.GeoDataFrame
		polygons (e.g. buildings) for input region of interest which will determine the shape to extract

	Returns
	----------
	geopandas.GeoDataFrame
		returns the extracted population data
	"""
	# Input data source type given?
	assert( data_source in DATA_SOURCES )

	# Population extract exists?
	if ( os.path.exists( get_population_extract_filename(city_ref, data_source) ) ):
		log("Population extract exists for input city: "+city_ref)
		return gpd.read_file( get_population_extract_filename(city_ref, data_source) )

	# Input shape given?
	assert( not ( np.all(polygons_gdf is None ) ) )
	# Input population shapefile given?
	assert( not pop_shapefile is None )
	# All input files given?
	assert( not ( (data_source == 'insee') and (pop_data_file is None) ) )

	# Get buildings convex hull
	polygon = GeometryCollection( polygons_gdf.geometry.values.tolist() ).convex_hull
	# Convert to geo-dataframe with defined CRS
	poly_gdf = gpd.GeoDataFrame([polygon], columns=["geometry"], crs=polygons_gdf.crs)
	
	# Compute extract
	df_pop = get_population_df(pop_shapefile, pop_data_file, data_source, to_crs, poly_gdf)
	
	# Save to shapefile
	df_pop.to_file( get_population_extract_filename(city_ref, data_source), driver='ESRI Shapefile' )
	return df_pop 
開發者ID:lgervasoni,項目名稱:urbansprawl,代碼行數:55,代碼來源:data_extract.py

示例15: test_mem

# 需要導入模塊: from shapely import geometry [as 別名]
# 或者: from shapely.geometry import GeometryCollection [as 別名]
def test_mem(driver_mem, gtype, geoms, ftypes, fields):
    driver = driver_mem
    ds = Dataset(allow_none_geometry=1)

    with ds.acreate_vector('', gtype, ftypes, driver=driver, options=[], sr=SR1['wkt']).close as v:
        for geom in geoms:
            v.insert_data(geom, fields)

        # TESTS 0
        assert srs.wkt_same(v.wkt_stored, SR1['wkt'])
        assert srs.wkt_same(v.wkt_virtual, SR1['wkt'])
        for ftype, ftype_stored in zip(ftypes, v.fields):
            for key, value in ftype.items():
                assert ftype_stored[key] == value
        assert v.mode == 'w'
        assert v.type.lower() == gtype.lower()

        # TESTS 1
        datas = list(v.iter_data())
        assert len(datas) == len(geoms)
        assert len(v) == len(geoms)
        # assert v.layer in {0, ''}

        if not sg.GeometryCollection(geoms).is_empty:
            assert eq(
                v.bounds,
                v.bounds_stored,
                v.extent[[0, 2, 1, 3]],
                v.extent_stored[[0, 2, 1, 3]],
                sg.GeometryCollection(geoms).bounds
            )

        for geom, data in zip(geoms, datas):
            if not isinstance(data, tuple):
                data = (data,)
            read_geom, *read_fields = data
            if read_geom is None or read_geom.is_empty:
                assert geom.is_empty
            else:
                assert (geom ^ read_geom).is_empty, (
                    geom.wkt,
                    read_geom.wkt,
                ) 
開發者ID:airware,項目名稱:buzzard,代碼行數:45,代碼來源:test_vectorsource_opencreate.py


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