本文整理汇总了Python中geopandas.GeoSeries类的典型用法代码示例。如果您正苦于以下问题:Python GeoSeries类的具体用法?Python GeoSeries怎么用?Python GeoSeries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GeoSeries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makedata
def makedata(ifile, zfield, *args):
# if csv:
if ifile[-4:] == '.csv':
data = pd.read_csv(ifile, header=0)
# Filter data
data = data[(data[zfield] != -9999.0) & (data[lat] != -9999.0) & (pd.isnull(data[lat]) == False)]
# Get points and Buffer to create polygon type
coords = GeoSeries([Point(x, y) for x, y in zip(data[lon], data[lat])])
data['geometry'] = coords.buffer(0.0001)
# Filter out null types
data = data[pd.isnull(data.geometry) == False]
#Recreate index
data.index = [i for i in range(len(data))]
return GeoDataFrame(data)#
elif ifile[-4:] == '.shp':
data = GeoDataFrame.from_file(ifile)
# Polygon types
if isinstance(data.geometry[1], Polygon) == True:
data = data[pd.isnull(data.geometry) == False]
return data
# Point types
elif isinstance(data.geometry[1], Point) == True:
coords = data.geometry.buffer(0.0001)
data['geometry'] = coords
# Filter out null types
data = data[pd.isnull(data.geometry) == False]
# Recreate index
data.index = [i for i in range(len(data))]
return GeoDataFrame(data)
else:
return "Filetype not supported - Only points or polygons!"
示例2: TestLineStringPlotting
class TestLineStringPlotting(unittest.TestCase):
def setUp(self):
self.N = 10
values = np.arange(self.N)
self.lines = GeoSeries([LineString([(0, i), (9, i)]) for i in xrange(self.N)])
self.df = GeoDataFrame({'geometry': self.lines, 'values': values})
def test_single_color(self):
ax = self.lines.plot(color='green')
_check_colors(ax.get_lines(), ['green']*self.N)
ax = self.df.plot(color='green')
_check_colors(ax.get_lines(), ['green']*self.N)
ax = self.df.plot(column='values', color='green')
_check_colors(ax.get_lines(), ['green']*self.N)
def test_style_kwargs(self):
# linestyle
ax = self.lines.plot(linestyle='dashed')
ls = [l.get_linestyle() for l in ax.get_lines()]
assert ls == ['--'] * self.N
ax = self.df.plot(linestyle='dashed')
ls = [l.get_linestyle() for l in ax.get_lines()]
assert ls == ['--'] * self.N
ax = self.df.plot(column='values', linestyle='dashed')
ls = [l.get_linestyle() for l in ax.get_lines()]
assert ls == ['--'] * self.N
示例3: setup_method
class TestNonuniformGeometryPlotting:
def setup_method(self):
pytest.importorskip('matplotlib', '1.5.0')
poly = Polygon([(1, 0), (2, 0), (2, 1)])
line = LineString([(0.5, 0.5), (1, 1), (1, 0.5), (1.5, 1)])
point = Point(0.75, 0.25)
self.series = GeoSeries([poly, line, point])
self.df = GeoDataFrame({'geometry': self.series, 'values': [1, 2, 3]})
def test_colors(self):
# default uniform color
ax = self.series.plot()
_check_colors(1, ax.collections[0].get_facecolors(), [MPL_DFT_COLOR])
_check_colors(1, ax.collections[1].get_edgecolors(), [MPL_DFT_COLOR])
_check_colors(1, ax.collections[2].get_facecolors(), [MPL_DFT_COLOR])
# colormap: different colors
ax = self.series.plot(cmap='RdYlGn')
cmap = plt.get_cmap('RdYlGn')
exp_colors = cmap(np.arange(3) / (3 - 1))
_check_colors(1, ax.collections[0].get_facecolors(), [exp_colors[0]])
_check_colors(1, ax.collections[1].get_edgecolors(), [exp_colors[1]])
_check_colors(1, ax.collections[2].get_facecolors(), [exp_colors[2]])
def test_style_kwargs(self):
ax = self.series.plot(markersize=10)
assert ax.collections[2].get_sizes() == [10]
ax = self.df.plot(markersize=10)
assert ax.collections[2].get_sizes() == [10]
示例4: setUp
def setUp(self):
self.t1 = Polygon([(0, 0), (1, 0), (1, 1)])
self.t2 = Polygon([(0, 0), (1, 1), (0, 1)])
self.sq = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
self.g1 = GeoSeries([self.t1, self.sq])
self.g2 = GeoSeries([self.sq, self.t1])
self.g3 = GeoSeries([self.t1, self.t2])
self.g3.crs = {"init": "epsg:4326", "no_defs": True}
self.g4 = GeoSeries([self.t2, self.t1])
self.na = GeoSeries([self.t1, self.t2, Polygon()])
self.na_none = GeoSeries([self.t1, self.t2, None])
self.a1 = self.g1.copy()
self.a1.index = ["A", "B"]
self.a2 = self.g2.copy()
self.a2.index = ["B", "C"]
self.esb = Point(-73.9847, 40.7484)
self.sol = Point(-74.0446, 40.6893)
self.landmarks = GeoSeries([self.esb, self.sol], crs={"init": "epsg:4326", "no_defs": True})
self.l1 = LineString([(0, 0), (0, 1), (1, 1)])
self.l2 = LineString([(0, 0), (1, 0), (1, 1), (0, 1)])
self.g5 = GeoSeries([self.l1, self.l2])
# Placeholder for testing, will just drop in different geometries
# when needed
self.gdf1 = GeoDataFrame({"geometry": self.g1, "col0": [1.0, 2.0], "col1": ["geo", "pandas"]})
self.gdf2 = GeoDataFrame({"geometry": self.g1, "col3": [4, 5], "col4": ["rand", "string"]})
示例5: TestNonuniformGeometryPlotting
class TestNonuniformGeometryPlotting(unittest.TestCase):
def setUp(self):
poly = Polygon([(1, 0), (2, 0), (2, 1)])
line = LineString([(0.5, 0.5), (1, 1), (1, 0.5), (1.5, 1)])
point = Point(0.75, 0.25)
self.series = GeoSeries([poly, line, point])
self.df = GeoDataFrame({'geometry': self.series, 'values': [1, 2, 3]})
return
def test_colormap(self):
ax = self.series.plot(cmap='RdYlGn')
cmap = get_cmap('RdYlGn', 3)
# polygon gets extra alpha. See #266
_check_colors(1, ax.collections[0], [cmap(0)], alpha=0.5)
# N.B. ax.collections[1] contains the edges of the polygon
_check_colors(1, ax.collections[2], [cmap(1)], alpha=1) # line
_check_colors(1, ax.collections[3], [cmap(2)], alpha=1) # point
def test_style_kwargs(self):
# markersize -> only the Point gets it
ax = self.series.plot(markersize=10)
assert ax.collections[3].get_sizes() == [10]
ax = self.df.plot(markersize=10)
assert ax.collections[3].get_sizes() == [10]
示例6: test_point_plot
def test_point_plot(self):
""" Test plotting a simple series of points """
clf()
filename = 'points_plot.png'
N = 10
points = GeoSeries(Point(i, i) for i in xrange(N))
ax = points.plot()
self._compare_images(ax=ax, filename=filename)
示例7: test_line_plot
def test_line_plot(self):
""" Test plotting a simple series of lines """
clf()
filename = 'lines_plot.png'
N = 10
lines = GeoSeries([LineString([(0, i), (9, i)]) for i in xrange(N)])
ax = lines.plot()
self._compare_images(ax=ax, filename=filename)
示例8: test_facecolor
def test_facecolor(self):
t1 = Polygon([(0, 0), (1, 0), (1, 1)])
t2 = Polygon([(1, 0), (2, 0), (2, 1)])
polys = GeoSeries([t1, t2])
df = GeoDataFrame({'geometry': polys, 'values': [0, 1]})
ax = polys.plot(facecolor='k')
_check_colors(ax.patches, ['k']*2, alpha=0.5)
示例9: test_buffer_distance_array
def test_buffer_distance_array(self):
original = GeoSeries([self.p0, self.p0])
expected = GeoSeries(
[Polygon(((6, 5), (5, 4), (4, 5), (5, 6), (6, 5))),
Polygon(((10, 5), (5, 0), (0, 5), (5, 10), (10, 5))),
])
calculated = original.buffer(np.array([1, 5]), resolution=1)
assert_geoseries_equal(calculated, expected, check_less_precise=True)
示例10: test_polygons_append
def test_polygons_append(self):
t1 = Polygon([(0, 0), (1, 0), (1, 1)])
t2 = Polygon([(0, 0), (1, 1), (0, 1)])
sq = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
s = GeoSeries([t1, t2, sq])
t = GeoSeries([t1, t2, sq], [3, 4, 5])
s = s.append(t)
self.assertEqual(len(s), 6)
self.assertEqual(s.sindex.size, 6)
示例11: test_polygons_append
def test_polygons_append(self):
t1 = Polygon([(0, 0), (1, 0), (1, 1)])
t2 = Polygon([(0, 0), (1, 1), (0, 1)])
sq = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
s = GeoSeries([t1, t2, sq])
t = GeoSeries([t1, t2, sq], [3, 4, 5])
s = s.append(t)
assert len(s) == 6
assert s.sindex.size == 6
示例12: test_empty_plot
def test_empty_plot(self):
s = GeoSeries([])
with pytest.warns(UserWarning):
ax = s.plot()
assert len(ax.collections) == 0
df = GeoDataFrame([])
with pytest.warns(UserWarning):
ax = df.plot()
assert len(ax.collections) == 0
示例13: test_poly_plot
def test_poly_plot(self):
""" Test plotting a simple series of polygons """
clf()
filename = 'poly_plot.png'
t1 = Polygon([(0, 0), (1, 0), (1, 1)])
t2 = Polygon([(1, 0), (2, 0), (2, 1)])
polys = GeoSeries([t1, t2])
ax = polys.plot()
self._compare_images(ax=ax, filename=filename)
示例14: test_explode_geoseries
def test_explode_geoseries(self):
s = GeoSeries([MultiPoint([(0, 0), (1, 1)]),
MultiPoint([(2, 2), (3, 3), (4, 4)])])
s.index.name = 'test_index_name'
expected_index_name = ['test_index_name', None]
index = [(0, 0), (0, 1), (1, 0), (1, 1), (1, 2)]
expected = GeoSeries([Point(0, 0), Point(1, 1), Point(2, 2),
Point(3, 3), Point(4, 4)],
index=MultiIndex.from_tuples(
index, names=expected_index_name))
assert_geoseries_equal(expected, s.explode())
示例15: test_isna
def test_isna(NA):
s2 = GeoSeries([Point(0, 0), NA, Point(2, 2)])
exp = pd.Series([False, True, False])
res = s2.isnull()
assert_series_equal(res, exp)
res = s2.isna()
assert_series_equal(res, exp)
res = s2.notnull()
assert_series_equal(res, ~exp)
res = s2.notna()
assert_series_equal(res, ~exp)