Skip to content

Commit

Permalink
Implement store_raster_output method
Browse files Browse the repository at this point in the history
Implement store_raster_output method that stores output raster data to a PostGIS database using the raster2pgsql command
  • Loading branch information
janpisl committed Jun 9, 2018
1 parent e024b1e commit a09dfc6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pywps/inout/storage/db/pg.py
Expand Up @@ -67,6 +67,7 @@ def store_vector_output(self, file_name, identifier):
# connect to a database and copy output there
LOGGER.debug("Connect string: {}".format(self.target))
dsc_in = ogr.Open(file_name)

if dsc_in is None:
raise Exception("Reading data failed.")
dsc_out = ogr.Open("PG:" + self.target)
Expand All @@ -82,16 +83,27 @@ def store_vector_output(self, file_name, identifier):
return identifier

def store_raster_output(self, file_name, identifier):
pass

from subprocess import call

try:
call(["raster2pgsql", file_name, self.schema_name + "." + identifier, "|", "psql", "-d", self.dbname])
except:
raise Exception("Writing output data to the database failed.")

return identifier


def store(self, output):
""" Creates reference that is returned to the client (database name, schema name, table name)
"""
assert(output.output_format.data_type in (0,1))

if output.output_format.data_type == 0:
self.store_vector_output(output.file, output.identifier)
elif output.output_format.data_type == 0:
else:
self.store_raster_output(output.file, output.identifier)

url = '{}.{}.{}'.format(self.dbname, self.schema_name, output.identifier)
# returns value for database storage defined in the STORE_TYPE class,
# name of the output file and a reference
Expand Down

0 comments on commit a09dfc6

Please sign in to comment.