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.

本文标签: