本文整理汇总了Python中geopandas.GeoSeries方法的典型用法代码示例。如果您正苦于以下问题:Python geopandas.GeoSeries方法的具体用法?Python geopandas.GeoSeries怎么用?Python geopandas.GeoSeries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geopandas
的用法示例。
在下文中一共展示了geopandas.GeoSeries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_network_false_nodes
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_network_false_nodes(self):
test_file_path2 = mm.datasets.get_path("tests")
self.false_network = gpd.read_file(test_file_path2, layer="network")
fixed = mm.network_false_nodes(self.false_network)
assert len(fixed) == 55
assert isinstance(fixed, gpd.GeoDataFrame)
assert self.false_network.crs.equals(fixed.crs)
fixed_series = mm.network_false_nodes(self.false_network.geometry)
assert len(fixed_series) == 55
assert isinstance(fixed_series, gpd.GeoSeries)
assert self.false_network.crs.equals(fixed_series.crs)
with pytest.raises(TypeError):
mm.network_false_nodes(list())
multiindex = self.false_network.explode()
fixed_multiindex = mm.network_false_nodes(multiindex)
assert len(fixed_multiindex) == 55
assert isinstance(fixed, gpd.GeoDataFrame)
示例2: _get_centerline_lonlat
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def _get_centerline_lonlat(gdir):
"""Quick n dirty solution to write the centerlines as a shapefile"""
cls = gdir.read_pickle('centerlines')
olist = []
for j, cl in enumerate(cls[::-1]):
mm = 1 if j == 0 else 0
gs = gpd.GeoSeries()
gs['RGIID'] = gdir.rgi_id
gs['LE_SEGMENT'] = np.rint(np.max(cl.dis_on_line) * gdir.grid.dx)
gs['MAIN'] = mm
tra_func = partial(gdir.grid.ij_to_crs, crs=wgs84)
gs['geometry'] = shp_trafo(tra_func, cl.line)
olist.append(gs)
return olist
示例3: gaussian_polygons
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def gaussian_polygons(points, n=10):
"""
Returns an array of approximately `n` `shapely.geometry.Polygon` objects for an array of
`shapely.geometry.Point` objects.
"""
gdf = gpd.GeoDataFrame(
data={'cluster_number': classify_clusters(points, n=n)}, geometry=points
)
polygons = []
for i in range(n):
sel_points = gdf[gdf['cluster_number'] == i].dropna().geometry
polygons.append(shapely.geometry.MultiPoint([(p.x, p.y) for p in sel_points]).convex_hull)
polygons = [
p for p in polygons if (
(not isinstance(p, shapely.geometry.Point)) and
(not isinstance(p, shapely.geometry.LineString)))
]
return gpd.GeoSeries(polygons)
示例4: paint_clip
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def paint_clip(self):
clip = self.kwargs.pop('clip')
clip = _to_geom_geoseries(self.df, clip, "clip")
if clip is not None:
if self.projection is not None:
xmin, xmax, ymin, ymax = self.ax.get_extent(crs=ccrs.PlateCarree())
extent = (xmin, ymin, xmax, ymax)
clip_geom = self._get_clip(extent, clip)
feature = ShapelyFeature([clip_geom], ccrs.PlateCarree())
self.ax.add_feature(feature, facecolor=(1,1,1), linewidth=0, zorder=2)
else:
xmin, xmax = self.ax.get_xlim()
ymin, ymax = self.ax.get_ylim()
extent = (xmin, ymin, xmax, ymax)
clip_geom = self._get_clip(extent, clip)
xmin, xmax = self.ax.get_xlim()
ymin, ymax = self.ax.get_ylim()
polyplot(
gpd.GeoSeries(clip_geom), facecolor='white', linewidth=0, zorder=2,
extent=extent, ax=self.ax
)
示例5: test_cluster_is_within_envelope
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_cluster_is_within_envelope(get_dataframe):
"""
Test that all the clusters are within the enveloped formed by all the towers in the cluster.
"""
cd = CallDays(
SubscriberLocations(
"2016-01-01", "2016-01-04", spatial_unit=make_spatial_unit("versioned-site")
)
)
hartigan = HartiganCluster(calldays=cd, radius=50)
har_df = hartigan.to_geopandas()
sites = Sites().to_geopandas().set_index(["site_id", "version"])
towers = GeoSeries(har_df.apply(lambda x: get_geom_point(x, sites), 1))
s = har_df.intersects(towers)
assert all(s)
示例6: test_multiple_holes_of_union
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_multiple_holes_of_union(self):
# 00000
# 0 0 0
# 00000
geometries = geopandas.GeoSeries(
[
square_at(point)
for point in product([0, 1, 2, 3, 4], [0, 1, 2])
if point not in [(1, 1), (3, 1)]
]
)
result = holes_of_union(geometries)
assert len(result) == 2
squares = [square_at((1, 1)), square_at((3, 1))]
assert (result[0].equals(squares[0]) and result[1].equals(squares[1])) or (
result[1].equals(squares[0]) and result[0].equals(squares[1])
)
示例7: test_multipolygon
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_multipolygon(self):
# 000 000
# 0 0 0 0
# 000 000
geometries = geopandas.GeoSeries(
[
square_at(point)
for point in product([0, 1, 2], [0, 1, 2])
if point != (1, 1)
]
+ [
square_at(point)
for point in product([4, 5, 6], [0, 1, 2])
if point != (5, 1)
]
)
result = holes_of_union(geometries)
assert len(result) == 2
squares = [square_at((1, 1)), square_at((5, 1))]
assert (result[0].equals(squares[0]) and result[1].equals(squares[1])) or (
result[1].equals(squares[0]) and result[0].equals(squares[1])
)
示例8: test_can_impose_relative_area_threshold
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_can_impose_relative_area_threshold(self):
# 001
# 0 1
# 001
pacman = Polygon(
[(0, 0), (0, 3), (2, 3), (2, 2), (1, 2), (1, 1), (2, 1), (2, 0)]
)
bar = Polygon([(2, 0), (2, 3), (3, 3), (3, 0)])
geometries = geopandas.GeoSeries([pacman, bar])
fixed = close_gaps(geometries, relative_threshold=0.01)
# Since the gap is more than 1% of the area, the gap is not closed
assert fixed[1].equals(bar)
assert fixed[0].equals(pacman)
geometries = geopandas.GeoSeries([pacman, bar])
fixed = close_gaps(geometries, relative_threshold=0.5)
# Since the gap is less than 50% of the area, the gap is closed
assert fixed[1].equals(bar)
assert fixed[0].equals(Polygon([(0, 0), (0, 3), (2, 3), (2, 0)]))
示例9: test_assigns_overlap_by_max_shared_perimeter
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_assigns_overlap_by_max_shared_perimeter(self):
"""The overlapping area should be assigned to the polygon that shares
the most perimeter with the overlap.
"""
# 000
# 00x1
# 00x1
square1 = square_at((0, 0), side_length=3)
square2 = square_at((2, 0), side_length=2)
geometries = geopandas.GeoSeries([square1, square2])
result = resolve_overlaps(geometries, relative_threshold=None)
# Expected:
# 000
# 0001
# 0001
assert result[0].equals(square1)
assert result[1].equals(Polygon([(3, 0), (3, 2), (4, 2), (4, 0)]))
示例10: test_threshold
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_threshold(self):
# 000
# 00x1
# 00x1
square1 = square_at((0, 0), side_length=3)
square2 = square_at((2, 0), side_length=2)
geometries = geopandas.GeoSeries([square1, square2])
# This threshold is low enough that nothing should happen:
result = resolve_overlaps(geometries, relative_threshold=0.0001)
# Expected:
# 000
# 00x1
# 00x1
print(result)
assert result[0].equals(square1)
assert result[1].equals(square2)
示例11: test_threshold_rules_out_one_but_not_both
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_threshold_rules_out_one_but_not_both(self):
# 000
# 00x1
# 00x1
square1 = square_at((0, 0), side_length=3)
square2 = square_at((2, 0), side_length=2)
geometries = geopandas.GeoSeries([square1, square2])
# It's under threshold w.r.t square1 but not square 2
result = resolve_overlaps(geometries, relative_threshold=0.4)
# Expected:
# 000
# 00x1
# 00x1
assert result[0].equals(square1)
assert result[1].equals(square2)
示例12: test_fat_ops
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_fat_ops(self):
features = read_test_features()
gdf = GeoDataFrame.from_features(features)
self.assertIsNotNone(gdf.crs)
from cate.ops.data_frame import data_frame_min, data_frame_max
df_min = data_frame_min(gdf, 'C')
self.assertIsInstance(df_min, gpd.GeoDataFrame)
self.assertEqual(len(df_min), 1)
# assertCountEqual ignores the order of the list
self.assertCountEqual(list(df_min.columns), ['A', 'B', 'C', 'geometry'])
self.assertIsInstance(df_min.geometry, gpd.GeoSeries)
self.assertIsNotNone(df_min.crs)
df_max = data_frame_max(gdf, 'C')
self.assertIsInstance(df_max, gpd.GeoDataFrame)
self.assertEqual(len(df_max), 1)
# assertCountEqual ignores the order of the list
self.assertCountEqual(list(df_max.columns), ['A', 'B', 'C', 'geometry'])
self.assertIsInstance(df_max.geometry, gpd.GeoSeries)
self.assertIsNotNone(df_max.crs)
示例13: _prepare_gdf_for_mask
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def _prepare_gdf_for_mask(geodataframe, method, numbers):
from geopandas import GeoDataFrame, GeoSeries
if not isinstance(geodataframe, (GeoDataFrame, GeoSeries)):
raise TypeError("input must be a geopandas 'GeoDataFrame' or 'GeoSeries'")
if method == "legacy":
raise ValueError("method 'legacy' not supported in 'mask_geopandas'")
lon_min = geodataframe.bounds["minx"].min()
lon_max = geodataframe.bounds["maxx"].max()
is_180 = _is_180(lon_min, lon_max)
polygons = geodataframe.geometry.tolist()
if numbers is not None:
numbers = geodataframe[numbers]
_check_missing(numbers, "numbers")
_check_duplicates(numbers, "numbers")
else:
numbers = geodataframe.index.values
return polygons, is_180, numbers
示例14: test_vector_feature_types
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def test_vector_feature_types(self):
eop = EOPatch()
invalid_entries = [
{}, [], 0, None
]
for feature_type in FeatureTypeSet.VECTOR_TYPES:
for entry in invalid_entries:
with self.assertRaises(ValueError,
msg='Invalid entry {} for {} should raise an error'.format(entry, feature_type)):
eop[feature_type]['TEST'] = entry
crs_test = CRS.WGS84.pyproj_crs()
geo_test = GeoSeries([BBox((1, 2, 3, 4), crs=CRS.WGS84).geometry], crs=crs_test)
eop.vector_timeless['TEST'] = geo_test
self.assertTrue(isinstance(eop.vector_timeless['TEST'], GeoDataFrame),
'GeoSeries should be parsed into GeoDataFrame')
self.assertTrue(hasattr(eop.vector_timeless['TEST'], 'geometry'), 'Feature should have geometry attribute')
self.assertEqual(eop.vector_timeless['TEST'].crs, crs_test, 'GeoDataFrame should still contain the crs')
with self.assertRaises(ValueError, msg='Should fail because there is no TIMESTAMP column'):
eop.vector['TEST'] = geo_test
示例15: makeLineMap
# 需要导入模块: import geopandas [as 别名]
# 或者: from geopandas import GeoSeries [as 别名]
def makeLineMap(line):
line_plot = gpd.GeoSeries(line)
line_plot = line_plot.plot(figsize=(24, 24), color="white")
line_plot.set_facecolor("#111111")
line_plot.spines["bottom"].set_color("white")
line_plot.spines["left"].set_color("white")
line_plot.xaxis.label.set_color("white")
line_plot.tick_params(axis="x", colors="white")
line_plot.yaxis.label.set_color("white")
line_plot.tick_params(axis="y", colors="white")
line_plot.set_xlabel("Longitude")
line_plot.set_ylabel("Latitude")
return line_plot