Я хотел бы импортировать сжатый zstd geotiff в постгис со следующими командами (ниже), но я получаю эту ошибку: raster_fromgdalraster: не могу открыть байт с GDAL. Убедитесь, что байета имеет поддерживаемый GDAL формат . Тем не менее, у меня нет проблем с импортом несжатых геотиффских растра. Поддерживает ли GDAL импорт сжатого геотифа? Спасибо за ваши подсказки. < /P>
import psycopg2
from rasterio.io import MemoryFile
db_params = {
"dbname": "test_db",
"user": "postgres",
"password": "demo",
"host": "localhost",
"port": "5432"}
table_name = "species_UZ"
raster_column_name = 'species'
try:
conn = psycopg2.connect(**db_params)
cursor = conn.cursor()
file_path='my_raster.tif'
with rasterio.open(file_path) as src:
# You might need to adjust based on your raster structure
raster_data = src.read()
profile = src.profile
# Convert to PostGIS-compatible format (e.g., GeoTIFF in memory)
with MemoryFile() as memfile:
with memfile.open(**profile) as dst:
dst.write(raster_data)
gdal_raster_bytes = memfile.read()
create_table_sql = f"""
SET postgis.gdal_enabled_drivers = 'ENABLE_ALL';
CREATE TABLE IF NOT EXISTS {table_name} (id SERIAL PRIMARY KEY, {raster_column_name} RASTER);"""
cursor.execute(create_table_sql)
insert_sql = f"INSERT INTO {table_name} ({raster_column_name}) VALUES (ST_FromGDALRaster(%s));"
cursor.execute(insert_sql, (gdal_raster_bytes,))
conn.commit()
print(f"Raster successfully imported into {table_name}.")
except Exception as e:
print(f"Error: {e}")
finally:
if cursor:
cursor.close()
if conn:
conn.close()
Подробнее здесь: https://stackoverflow.com/questions/797 ... -in-python
Невозможно импортировать сжатый ZSTD Geotiff To Postgis в Python ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение