admin管理员组文章数量:1414605
I have a code below
import geopandas as gpd # used to read the shapfile
import rasterio as rio # used to read the raster (.tif) files
from rasterio.plot import show # used to make plots using rasterio
import matplotlib.pyplot as plt #to make plots using matplotlib
points = gpd.read_file('Points.shp')
points['DEM'] = 0 #
points['Slope'] = 0
points['Aspect'] = 0
points['RD'] = 0
points['D2Road'] = 0
points['D2Res'] = 0
points['LC'] = 0
points['Temp'] = 0
DEM_raster = rio.open('Elevation.tif')
DEM_arr = DEM_raster.read(1)
Slope_raster = rio.open('Slope.tif')
Slope_arr = Slope_raster.read(1)
Aspect_raster = rio.open('Aspect.tif')
Aspect_arr = Aspect_raster.read(1)
RD_raster = rio.open('RD.tif')
RD_arr = RD_raster.read(1)
Droad_raster = rio.open('D2Road.tif')
Droad_arr = Droad_raster.read(1)
Dres_raster = rio.open('D2Res.tif')
Dres_arr = Dres_raster.read(1)
LC_raster = rio.open('LC.tif')
LC_arr = LC_raster.read(1)
Temp_raster = rio.open('Temp.tif')
Temp_arr = Temp_raster.read(1)
fig, ax = plt.subplots(figsize=(12,12))
points.plot(ax=ax, color = 'orangered')
show(DEM_raster, ax = ax)
for index, row in points.iterrows():
longitude = row['geometry'].x
latitude = row['geometry'].y
rowIndex, colIndex=DEM_raster.index(longitude,latitude)
points.loc[index, 'DEM'] = DEM_arr[rowIndex, colIndex]
points.loc[index, 'Slope'] = float(Slope_arr[rowIndex, colIndex])
points.loc[index, 'Aspect'] = float(Aspect_arr[rowIndex, colIndex])
points.loc[index, 'RD'] = float(RD_arr[rowIndex, colIndex])
points.loc[index, 'D2Road'] = float(Droad_arr[rowIndex, colIndex])
points.loc[index, 'D2Res'] = float(Dres_arr[rowIndex, colIndex])
points.loc[index, 'LC'] = float(LC_arr[rowIndex, colIndex])
points.loc[index, 'Temp'] = float(Temp_arr[rowIndex, colIndex])
points.head()
points.to_file('points_data.shp')
It always gives this warning for every columnn except DEM
which returns int
type. I don't want to force all values to int
type.
FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '168.13560485839844' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
I have tried to run without forcing thi float type, but it gives the same warning.
本文标签:
版权声明:本文标题:python - FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of panda 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744780642a2624689.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论