I am trying to import information from a Bathymetric Attributed Grid (BAG) file into PostGIS using Python and psycopg2. I'm working, for now, on a Windows box with pre-compiled packages, so I don't have GDAL
, osgeo
, or ogr
support for BAGs directly.
I can open and parse the BAG with h5py
and ElementTree
, no problem. I can add simple geo objects (e.g., bounding box as box2d) with no problems. I can't figure out how to add the BAG values. I'm trying to add the elevation and uncertainty arrays as two bands in a raster.
relevant, non-working code extract:
elevation = hierarchy["/BAG_root/elevation"]
width = len(elevation)
height = len(elevation[0])
uncertainty = hierarchy["/BAG_root/uncertainty"]
el_array = elevation[0:][0:]
un_array = uncertainty[0:][0:]
update_string = "UPDATE %s SET el_un = ST_SetValues(ST_AddBand(ST_MakeEmptyRaster( %%s, %%s, %%s, %%s, %%s), ARRAY[ %%s, %%s ]::addbandarg[])) WHERE filename = %%s;" %(tablename, )
print cursor.mogrify(update_string, (width, height, left, top, 1.00, el_array, un_array, basefn))
This gives a can't adapt type 'numpy.ndarray'
error. I've tried several variations on this (without the slices, with tolist()
, explicitly using numpy, etc., and all have had similar errors. I hope I'm missing something simple, due to my lack of PostGIS familiarity. For that matter, I may be able to copy the raster2pgsql
output for another file type, suitably modified, but don't know how to encode the VALUES( '...'::raster)
data value - is there some documentation for that I haven't been able to find?
I hope to soon move to a Linux box where I can add formats and recompile GDAL
and other packages if needed, so answers using GDAL in Python or executables that are made with additional supported formats are welcome. I'd use raster2pgsql.exe
, but it doesn't support the BAG format, at least as is. Is there an easy way to write out one of the formats it does accept by default?