Closed mmann1123 closed 2 years ago
Tracked down the row that was giving me trouble:
(IPdb [3]): dfrow
R_NAME SNNP
R_CODE 7
Z_NAME Derashe Lyiu Wereda
Z_CODE 716
W_NAME Derashe Special
W_CODE 71601
KK_NAME None
KK_CODE 0
Remark None
T_NAME None
T_CODE 0
RK_NAME Onota
RK_CODE 71601010.0
EA_NAME 010-04
UK_NAME None
UK_CODE None
EA_ID None
UK_ID None
EA_CODE 4
W_code_t 071601
KK_cd_T None
RK_Code1 None
FID 4714
id 4715
geometry POLYGON ((37.49745968170024 5.653699819037462,...
Name: 4714, dtype: object
(IPdb [4]): sample_feature(dfrow,
id_column,
df_columns,
data.crs,
data.res,
all_touched,
meta,
frac,
min_frac_area)
*** ValueError: cannot set a frame with no defined index and a scalar
In sample_feature1 seems like
rasterize` is returning an empty array...
feature_array = features.rasterize([geom],
out_shape=geom_info.shape,
fill=0,
out=None,
transform=geom_info.affine,
all_touched=all_touched,
default_value=1,
dtype='int32')
feature_array
array([[0]], dtype=int32)
That creates an empty geodataframe
fea_df = gpd.GeoDataFrame(data=np.c_[fid_, np.arange(0, n_samples)],
geometry=gpd.points_from_xy(x_coords, y_coords),
crs=crs,
columns=[id_column, 'point'])
fea_df
Empty GeoDataFrame
Columns: [id, point, geometry]
Index: []
So then transferring column data back throws an error:
for col in other_cols:
fea_df.loc[:, col] = df_row[col]
*** ValueError: cannot set a frame with no defined index and a scalar
One possible solution
if not fea_df.empty:
for col in other_cols:
fea_df.loc[:, col] = df_row[col]
else:
pass
Although not sure if you prefer a try except...
@jgrss I am running into issues with gw.extract again. I think its related to the issue above. Just wondering if we have any thoughts on a solution
@mmann1123 have you tested this proposed solution?
if not fea_df.empty:
for col in other_cols:
fea_df.loc[:, col] = df_row[col]
else:
pass
I would be happy with this.
@mmann1123 have you tested this proposed solution?
@jgrss Yes this solves the issue for me. I've tested it in a few different scenarios
Hey Jordan, I am trying to extract values to a large set of polygons. Just not sure how to interpret. Any ideas? I am using the lastest git version.