-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
line 611, in _patch_area_ser return self._cached_patch_area_ser AttributeError: 'Landscape' object has no attribute '_cached_patch_area_ser' #49
Comments
Hi Marti, I want to thank you for creating Pylandstats because it is great having a package in Python for calculating landscape metrics. Nevertheless, ever since I have been using Pylandstats, I have received the error " I would appreciate it if you could help to resolve the error. Best, |
Hello Bahareh, thank you for your kind words and for using pylandstats. The Best, |
Hello, At first I want to thank Dr. Marti Bosch for developing this valuable package. I encountered Bahare's problem yesterday and tried to resolve it, finally by Marti's guide about input layers I found that: |
Description
D:\anaconda\python.exe "D:\lhflearn\指数计算\landscape level1.py"
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 611, in _patch_area_ser
return self._cached_patch_area_ser
AttributeError: 'Landscape' object has no attribute '_cached_patch_area_ser'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\lhflearn\指数计算\landscape level1.py", line 14, in
landscape_metrics_df = za.compute_landscape_metrics_df(metrics=metrics)
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\multilandscape.py", line 233, in compute_landscape_metrics_df
] = landscape.compute_landscape_metrics_df(
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 3943, in compute_landscape_metrics_df
metrics_dict[metric] = getattr(self, metric)(**metric_kws)
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 1711, in area_mn
return self._metric_mn(
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 792, in _metric_mn
return self._metric_reduce(
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 778, in _metric_reduce
patch_metrics = patch_metric_method(
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 882, in area
area_ser = self._get_patch_area_ser(class_val=class_val)
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 727, in _get_patch_area_ser
patch_area_ser = self._patch_area_ser
File "C:\Users\Administrator\AppData\Roaming\Python\Python39\site-packages\pylandstats\landscape.py", line 614, in _patch_area_ser
np.concatenate(
File "<array_function internals>", line 5, in concatenate
ValueError: need at least one array to concatenate
进程已结束,退出代码1
What I Did
import geopandas as gpd
import pandas as pd
from pylandstats import ZonalAnalysis
读取矢量区域块数据
gdf = gpd.read_file(r"D;\ .shp")
tif_file = r" D;\ .tif"
创建 ZonalAnalysis 实例并指定文件路径
za = ZonalAnalysis(landscape_filepath=tif_file, zones=gdf)
定义要计算的指标
metrics = ['area_mn']
计算景观级别指标
landscape_metrics_df = za.compute_landscape_metrics_df(metrics=metrics)
将结果存储到 Excel 文件
output_file = r"D:\lhf\ybds\景观级别指标.xlsx"
landscape_metrics_df.to_excel(output_file, index=False)
print("景观级别指标已保存到 Excel 文件:", output_file)
The text was updated successfully, but these errors were encountered: