我有两个 GeoDataFrame。一个是爱荷华州,另一个是预测未来 72 小时北美的降雨。我想创建一个覆盖爱荷华州的降雨预报的 GeoDataFrame。但我得到一个错误。
state_rain = gpd.overlay(NA_rain,iowa,how='intersection')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-39-ba8264ed63c2> in <module>()
3 #ws_usa[['WTRSHD_ID','QPF']].groupby('WTRSHD_ID').max().reset_index()
4 #state_rain = sjoin(usa_r,usa,how='inner',op='intersects')
----> 5 state_rain = gpd.overlay(usa_r,joined_states,how='intersection')
6 ws_state = gpd.overlay(ws,joined_states,how='intersection')
7 #print ws_usa.loc[ws_usa.WTRSHD_ID == 'IA-04']['QPF']
C:\Anaconda2\lib\site-packages\geopandas\tools\overlay.pyc in overlay(df1, df2, how, use_sindex)
95
96 # Collect the interior and exterior rings
---> 97 rings1 = _extract_rings(df1)
98 rings2 = _extract_rings(df2)
99 mls1 = MultiLineString(rings1)
C:\Anaconda2\lib\site-packages\geopandas\tools\overlay.pyc in _extract_rings(df)
50 # geom from layer is not valid attempting fix by buffer 0"
51 geom = geom.buffer(0)
---> 52 rings.append(geom.exterior)
53 rings.extend(geom.interiors)
54
AttributeError: 'MultiPolygon' object has no attribute 'exterior'
我检查了 type == 'MultiPolygon',但 GeoDataFrame 都不包含任何内容。
print NA_rain[NA_rain.geometry.type == 'MulitPolygon']
print iowa[iowa.geometry.type == 'MultiPolygon']
Empty GeoDataFrame
Columns: [END_TIME, ID, ISSUE_TIME, PRODUCT, QPF, START_TIME, UNITS, VALID_TIME, geometry]
Index: []
Empty GeoDataFrame
Columns: [sid, AFFGEOID, ALAND, AWATER, GEOID, LSAD, NAME, STATEFP, STATENS, STUSPS, geometry]
Index: []
如果我执行以下操作,则交叉点有效。
NA_rain.geometry = NA_rain.geometry.map(lambda x: x.convex_hull)
我的问题是双重的:1.为什么没有任何 MultiPolygons 出现在我的 NA_rain GeoDataFrame 中,以及 2.除了将每个 Polygon 变成一个 convex_hull 之外,这会破坏 Polygon 的详细轮廓,您建议如何处理 MultiPolygon 问题。