geopandas 的使用以及相关问题

geopandas 的使用以及相关问题

Geoff Boeing

Michelle Fullwood

%matplotlib  inline
import pandas as pd
import geopandas as gpd
from geopandas import GeoDataFrame, read_file
from geopandas.tools import sjoin
from shapely.geometry import Point, mapping,shape
import time
from geopandas.geoseries import Polygon
from geopandas import GeoSeries
p1 = Polygon([(0, 0), (1, 0), (1, 1)])
p2 = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
p3 = Polygon([(2, 0), (3, 0), (3, 1), (2, 1)])
g=GeoSeries([p1,p2,p3])
g
0         POLYGON ((0 0, 1 0, 1 1, 0 0))
1    POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
2    POLYGON ((2 0, 3 0, 3 1, 2 1, 2 0))
dtype: object
g.plot()

这里写图片描述

g.area
0    0.5
1    1.0
2    1.0
dtype: float64
g.buffer(1).plot()

这里写图片描述

boros=GeoDataFrame.from_file(r'D:\下载\nybb_16a\nybb_16a\nybb.shp'.decode('utf-8'))
### IPython 带有中文的路径编码为uft-8,需更改编码为acci编码,win下才能识别。
r="D:\下载\nybb_16a\nybb_16a\nybb.shp"
import chardet
chardet.detect(r)
{‘confidence’: 0.7525, ‘encoding’: ‘utf-8’}
boros.set_index('BoroCode',inplace=True)
aa=boros.loc[5]['geometry']
boros.loc[5]
BoroName                                          Staten Island
Shape_Area                                          1.62382e+09
Shape_Leng                                               330470
geometry      (POLYGON ((970217.0223999023 145643.3322143555...
Name: 5, dtype: object
world=gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.crs
{‘init’: u’epsg:4326’}
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
world.head()
continentgdp_md_estgeometryiso_a3namepop_est
0Asia22270.0POLYGON ((61.21081709172574 35.65007233330923,…AFGAfghanistan28400000.0
1Africa110300.0(POLYGON ((16.32652835456705 -5.87747039146621…AGOAngola12799293.0
2Europe21810.0POLYGON ((20.59024743010491 41.85540416113361,…ALBAlbania3639453.0
3Asia184300.0POLYGON ((51.57951867046327 24.24549713795111,…AREUnited Arab Emirates4798491.0
4South America573900.0(POLYGON ((-65.50000000000003 -55.199999999999…ARGArgentina40913584.0
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
world.head()
continentgdp_md_estgeometryiso_a3namepop_est
0Asia22270.0POLYGON ((61.21081709172574 35.65007233330923,…AFGAfghanistan28400000.0
1Africa110300.0(POLYGON ((16.32652835456705 -5.87747039146621…AGOAngola12799293.0
2Europe21810.0POLYGON ((20.59024743010491 41.85540416113361,…ALBAlbania3639453.0
3Asia184300.0POLYGON ((51.57951867046327 24.24549713795111,…AREUnited Arab Emirates4798491.0
4South America573900.0(POLYGON ((-65.50000000000003 -55.199999999999…ARGArgentina40913584.0
from geopandas import GeoDataFrame  as df
# from pandas import DataFrame as df
from geopandas.geoseries import Point
df1 = df.set_geometry([Point(0,0), Point(1,1), Point(2,2)])
df2 = df.set_geometry('geom1')
-----------------------------------------------------------------------

修改默认的notebook的显示的图片大小

import matplotlib.pylab as pylab
import matplotlib.pyplot as plt
pylab.rcParams['figure.figsize'] = 20, 20
world.plot() 

这里写图片描述

%matplotlib  inline
world.plot(color='white',figsize=(20, 20))

控制图像 需要认真的研究bokeh 一个Python 交互式的绘图包

import bokeh
from bokeh import mpl
from bokeh.plotting import output_file, show
citys=cities.to_crs(world.crs)
# base=world.plot(color='white')
# cities.plot(ax=base,color='red',figsize=(100,100))
# show(mpl.to_bokeh())

将交互式的画面显示在notebook 中,bokeh教程,实例

from ipywidgets import interact
import numpy as np

from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook()

x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
p = figure(title="simple line example", plot_height=300, plot_width=600, y_range=(-5,5))
r = p.line(x, y, color="#2222aa", line_width=3)

def update(f, w=1, A=1, phi=0):
    if   f == "sin": func = np.sin
    elif f == "cos": func = np.cos
    elif f == "tan": func = np.tan
    r.data_source.data['y'] = A * func(w * x + phi)
    push_notebook()
show(p)
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值