GIS PY S3E15 geopandas初识

Table of Contents

geopandas的组成

  • geopandas=pandas+shapely

geopandas数据结构

  • GeoDataFrame – 表
  • Series – 列、行

geopandas要素

  • index – 行维度上的标记
  • column – 列上的标记

数据的操作包括几部分

读增(数据的还原)

fp = "C:\\Users\\tomye\\Documents\\山东.shp"
data = gpd.read_file(fp,encoding='utf-8')
data.head(2)
pfp=r'C:\Users\tomye\Documents\山东旅游景点.geojson'
points=gpd.read_file(pfp,encoding='utf-8')
points.head(2)

新增

newdata = gpd.GeoDataFrame()
coordinates = [(24.950899, 60.169158), (24.953492, 60.169158), (24.953510, 60.170104), (24.950958, 60.169990)]
poly = Polygon(coordinates)
newdata.loc[0, 'geometry'] = poly
newdata.loc[0, 'Location'] = 'Senaatintori'
newdata.crs = from_epsg(4326)
newdata

复制增加

data_copy=data.copy()

添加一列

data['area']=data.area

s1 = pd.Series(pd.date_range('20130102', periods=405),index=data.index)
data['date']=s1

表的叠加

newdata = gpd.GeoDataFrame(pd.concat( [newdata,newdata1], ignore_index=True))

表的对接

查(最重要)

基本信息

data.index
data.columns

行切片查询

data.head()
data.tail()
data.loc[1:3]
data.loc[:3]
grouped= data.groupby('PAC')
for key,values in grouped:
    v=values

列切片

data['PAC']
data.loc[:,['PAC','NAME','geometry']]

按条件查询

data[data['PAC']==370521.0]
data[(data['PAC']==370521.0) & (data['Shape_Leng']>0.024149)]
data[data['NAME'].isin(['垦利县','市中区'])]

查找单元格

data.at[74,'PAC']
data.iat[74,1]

查找统计结果

data['PAC'].max()
data['PAC'].min()
data['PAC'].mean()

排序

data.sort_index(axis=0, ascending=False)
data.sort_values(by='Shape_Area', ascending=False)

  • 删 = 增copy+查(取反)

按条件改

index=data.loc[data['NAME']=='垦利县'].index
data.loc[index,'NAME']='东营市垦利县'

修改列名

data.rename(columns={'PAC':'省际标识'})

根据列删除为空的行

points.dropna(subset=['geometry'],inplace=True)
Subscribe
提醒
guest

0 评论
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
交流思想,留下评论.x