Когда я конвертирую свой .tiff в массив изображений с помощью numpy , я получаю значение 350403 для длины.
Когда я пытаюсь сделать то же самое, используя gpd.GeoDataFrame.from_features(img_src), я получаю значение 343003.Есть ли способ гарантировать, что GeoDataFrame сохранит все ячейки/пиксели?
Вот мой код, прошу прощения, что это не так. лучший.
def tiff_to_csv(tiff_file: str, csv_file: str):
Код: Выделить всё
'''
Description:
- This function converts a TIFF file to a CSV file.
Parameters:
tiff_file:
- the path to the TIFF file to be converted
csv_file:
- the path to save the CSV file
Returns:
None
'''
# Open the TIFF file
tif_image = Image.open(tiff_file)
# Convert my image to a numpy array
image_array = np.array(tif_image)
# Flatten the array to convert it to a 1D vector
vector_data = image_array.flatten()
print(len(vector_data))
# Save the pixel values to a CSV file
np.savetxt(csv_file, vector_data, delimiter=",")
with rasterio.open(tiff_file) as src:
band1 = src.read(1)
no_data = src.nodata
print(f'no_data: {no_data}')
# Generate shapes (polygons) from the raster values,
results = (
{'properties': {'raster_val': v}, 'geometry': shape(s)}
for i, (s, v) in enumerate(shapes(band1, transform=src.transform))
)
# Convert my shapes to a GeoDataFrame
gdf = gpd.GeoDataFrame.from_features(band1)
total_shapes = len(gdf)
print(f"Number of shapes (including nodata): {total_shapes}")
Подробнее здесь: https://stackoverflow.com/questions/785 ... all-raster