Geopandas python空的几何图形缺失值

问题描述 投票:0回答:1

我正在运行一个python代码使用geopandas分析数据。问题出在最后5行而这里是 我用的数据 : https:/www.fr.freelancer.comusersl.php?url=https:%2F%2Fapp.box.com%2Fshared%2Fstatic%2Fyig4yill3xl83n7361c5q88kehikhje0.zip&sig=ec739bd7319b7823aa4c1d776a8d5ffc3c2da5040abfa799549180c82f1f93bd。 以下是代码

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import geopandas as gpd
from descartes.patch import PolygonPatch
from mpl_toolkits.axes_grid1 import make_axes_locatable

svi = gpd.read_file(r'C:\Users\Hamza\Desktop\Freelancer\SVI_IL2018.shp') # use a Tab key after you type data/ to select a file in the folder
svi.head() # show SVI by tracts in Ilinois

type(svi)
type(svi['geometry'])
svi['geometry'].geom_type
svi['geometry'].area
svi.crs
svi2 = svi.to_crs('epsg:3723')  # change CRS to UTM 16N
svi.plot()  # plot a GeoDataFrame. This shows tracts in Illinois
svi2 = svi.to_crs('epsg:3723')  # change CRS to UTM 16N
svi2.plot()
svi2.head()
ilcounty = svi2.dissolve(by='STCNTY')  # dissolve tracts by county
# map overall percentile ranking of social vulnerability
svi2.plot(column='RPL_THEMES', figsize=(6, 8), legend=True)  # figsize = (width, height) in inches, default (6.4, 4.8)
svi2['RPL_THEMES'].describe()  # get descriptive statistics of RPL_THEMES
svi2['RPL_THEMES'].hist()  # show histogram of RPL_THEMES
svi3 = svi2.replace(-999, np.nan)  # replace -999 with NaN (null values)
svi3['RPL_THEMES'].describe()
svi3.plot(column='RPL_THEMES', figsize=(8, 10), legend=True)
svi3.plot(column='RPL_THEMES', figsize=(8, 10), legend=True, cmap='YlOrBr')
svi3.plot(column='RPL_THEMES', figsize=(8, 10), legend=True, cmap='hot_r')
tri = gpd.read_file(r'C:\Users\Hamza\Desktop\Freelancer\TRI.geojson')
tri.crs
schools = gpd.read_file(r'C:\Users\Hamza\Desktop\Freelancer\schools.shp')
schools.head()
# 3) show the CRS of a GeoDataFrame schools. They should be in SPCS83
schools.crs
type(schools)
type(schools['geometry'])
tri.plot()
schools.plot()
svi3.plot()
# create fig (figure object) and ax (axis object)
fig, ax = plt.subplots(figsize=(8, 10))
# by default this creates a figure with one subplot (axis) as parameters for nrows and ncols are omitted
# if you create multiple axes, it would be good to name axes instead of ax

# plot three GeoDataFrames on the ax object created above
svi3.plot(ax=ax, column='RPL_THEMES')  # plot 'RPL_THEMES' on ax
tri.plot(ax=ax, color='r')  # plot tri on ax in red
schools.plot(ax=ax, color='g')  # plot schools on ax in green
svi4 = svi3.to_crs('epsg:3435')  # change CRS to UTM 16N
svi4.crs
# show three GeoDataFrames in one figure
fig, ax = plt.subplots(figsize=(8, 10))

svi4.plot(ax=ax, column='RPL_THEMES')  # map 'RPL_THEMES'
tri.plot(ax=ax, color='r')  # show tri in red
schools.plot(ax=ax, color='g')  # show schools in green
path = 'https://data.cityofchicago.org/api/geospatial/cauq-8yn6?method=export&format=GeoJSON'
comm = gpd.read_file(path)
comm.head()
comm.crs
comm = comm.to_crs('epsg:3435')  # change WGS84 to SPC IL East
comm.crs
# clip svi4 by comm
svi5 = gpd.clip(svi4, comm)

# clip tri by comm
tri2 = gpd.clip(tri, comm)
# warning of change in functionality. you can ignore this.

这里是错误的 C:Users/Hamza/AppData/Local/Programs/Python/Python37lib/sit-packages/geopandas/geoseries.py:358: UserWarning: GeoSeries.notna() GeoSeries.notna()以前对缺失(None)和空的几何图形都返回False。现在,它只对缺失值返回False。由于调用的GeoSeries包含空的几何体,因此与之前的GeoPandas版本相比,结果已经发生了变化。给定一个GeoSeries's',你可以使用'~s.is_empty & s.notna()'来恢复旧的行为。

要进一步忽略这个警告,你可以这样做: import warnings; warnings.filterwarnings('ignore', 'GeoSeries.notna', UserWarning) return self.notna()

python geopandas
1个回答
0
投票

这不是一个错误,而是GeoPandas在改变了以前的一个版本的行为后显示的一个警告。如果问题出在最后一行,很可能是由以下原因造成的 clip所以这应该不是一个问题。在这种情况下,GeoPandas应该将警告静音。你可以愉快地忽略它。

© www.soinside.com 2019 - 2024. All rights reserved.