Reputation: 21
I have a bitmap in memory that I would like to load as a raster to PostgreSQL.
An unfavorable option is saving the bitmap to file and then use raster2pgsql, but as we have several cameras that produce images at high rate, we can't afford saving them to files just for sake of insertion to the DB.
I'm looking for a solution for loading the bitmap directly from memory. Any suggestions?
I'm using PostgrSQL 9.2 using PostGIS2.0 on Windows 7. The images are plain gray level, if it matters.
Upvotes: 2
Views: 472
Reputation: 324771
Assuming that you don't need to transform the image (say, via some PostGIS-specific API), this is exactly what the PostgreSQL large object API is for.
You haven't mentioned the programming language you're using, so it's rather hard to be more detailed. Assuming you're using C, you can use libpq
's lo_write
, etc. See large objects in the manual.
If that won't cut it, you might have to open a pipe to the raster2pgsql
tool and do a streaming write. Not all programs can cope with reading from a pipe, some need random access to the file, and in that case you're probably stuck with writing a temp file. A quick look at the raster2pgsql
docs suggest that it just writes out SQL, so take a look at the SQL code it generates. See if you can link to it as a library and use it inside your code, or adapt it to read from a pipe. You could even create a shared memory region accessible as a file (on UNIX) and point it at that.
I suspect you'll land up using the GDAL library to do the same work raster2pgsql
does inside your app.
(BTW, for the PostGIS-specific side of things you might have more luck on https://gis.stackexchange.com/)
Upvotes: 2