Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the best solution to publish postgis rasters using Geoserver?

I have spent a lot of time trying to create a Raster datasource using Image Mosaic JDBC but with no luck.

Steps performed:
1. Downloaded and Installed the JDBC Image Mosaic extension (worked ok)
2. Created the "Connection Parameter" files:

connect.postgis.xml.inc:

<connect>
  <dstype value="DBCP"/>
  <username value="postgres" />
  <password value="password" />
  <jdbcUrl value="jdbc:postgresql://localhost:5432/db1" />
  <driverClassName value="org.postgresql.Driver"/>
  <maxActive value="10"/>
  <maxIdle value="0"/>
</connect>


mapping.postgis.xml.inc:

<spatialExtension name="postgis"/>
<mapping>
    <masterTable name="mosaic" >
        <coverageNameAttribute name="name"/>
        <maxXAttribute name="maxX"/>
        <maxYAttribute name="maxY"/>
        <minXAttribute name="minX"/>
        <minYAttribute name="minY"/>
        <resXAttribute name="resX"/>
        <resYAttribute name="resY"/>
        <tileTableNameAtribute name="tiletable" />
    </masterTable>
    <tileTable>
        <blobAttributeName name="rast" />
    </tileTable>
</mapping>


osm.postgis.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE ImageMosaicJDBCConfig [
  <!ENTITY mapping PUBLIC "mapping"  "mapping.postgis.xml.inc">
  <!ENTITY connect PUBLIC "connect"  "connect.postgis.xml.inc">]>
<config version="1.0">
  <coverageName name="gfm"/>
  <coordsys name="EPSG:25832"/>
  <!-- interpolation 1 = nearest neighbour, 2 = bilinear, 3 = bicubic -->
  <scaleop  interpolation="1"/>
  <verify cardinality="false"/>
  &mapping;
  &connect;
</config>

where "mosaic" is a table (columns: name, titletable,minX,minY,maxX,maxY,resX,resY) containing one row: "gfm, testrastertable, , , , , , ,"

3. Saved the config files in ../geoserver/data_dir/coverages/
4. While trying to add an Image Mosaic JDBC data store I receive the following error:

Error: Could not list layers for this store, an error occurred retrieving them: Unable to acquire a reader for this coverage with format: ImageMosaicJDBC



Update: Geoserver log

2012-10-24 14:09:11,404 DEBUG [org.geoserver] - Thread 14 locking in mode WRITE
2012-10-24 14:09:11,404 DEBUG [org.geoserver] - Thread 14 got the lock in mode WRITE
2012-10-24 14:09:11,406 DEBUG [geoserver.config] - Persisting coverage store raster_store
2012-10-24 14:09:11,408 DEBUG [geoserver.config] - Persisted org.geoserver.catalog.impl.CoverageStoreInfoImpl to /opt/geoserver/data_dir/workspaces/raster/raster_store/coveragestore.xml
2012-10-24 14:09:11,416 DEBUG [geoserver.config] - Persisted $Proxy15 to /opt/geoserver/data_dir/global.xml
2012-10-24 14:09:11,438 ERROR [imagemosaic.jdbc] - 
2012-10-24 14:09:11,438 WARN [imagemosaic.jdbc] - 
java.io.IOException
    at org.geotools.gce.imagemosaic.jdbc.ImageMosaicJDBCReader.<init>(ImageMosaicJDBCReader.java:163)
    at org.geotools.gce.imagemosaic.jdbc.ImageMosaicJDBCFormat.getReader(ImageMosaicJDBCFormat.java:209)
....
2012-10-24 14:09:11,439 INFO [geoserver.web] - Getting list of coverages for saved store file:coverages/osm.postgis.xml
java.lang.RuntimeException: Could not list layers for this store, an error occurred retrieving them: Unable to acquire a reader for this coverage with format: ImageMosaicJDBC
    at org.geoserver.web.data.layer.NewLayerPageProvider.getItems(NewLayerPageProvider.java:115)
...
Caused by: java.lang.Exception: Unable to acquire a reader for this coverage with format: ImageMosaicJDBC
    at org.geoserver.catalog.CatalogBuilder.buildCoverage(CatalogBuilder.java:812)
    at org.geoserver.web.data.layer.NewLayerPageProvider.getItems(NewLayerPageProvider.java:82)
    ... 95 more
2012-10-24 14:09:11,441 DEBUG [geoserver.config] - Removing coverage store raster_store
2012-10-24 14:09:11,446 DEBUG [geoserver.config] - Persisted $Proxy15 to /opt/geoserver/data_dir/global.xml
2012-10-24 14:09:11,459 DEBUG [org.geoserver] - Thread 14 releasing the lock in mode WRITE
share|improve this question
    
turn logging up to verbose and check the log file – iant Oct 24 '12 at 10:59
    
just updated with the log...doesn't tell me too much – asp Oct 24 '12 at 11:21
    
As no-one here seems able to help, you could try the GeoServer mailing list: geoserver.org/display/GEOS/Mailing+Lists – GIS-Jonathan Nov 9 '12 at 14:49
    
Any update on this question? – Pablo Mar 15 '13 at 17:13
    
No updates... I had to drop the idea of creating a JDBC Image Mosaic because i just couldn't create it in Geoserver. I am using now the ImagePyramid store and files are kept on the disk. – asp Mar 25 '13 at 17:35

I know this is too late for the OP, but hopefully it will help someone like me who came accross this question. I worked through several issues trying to use a postgis raster in geoserver similar to the OP, the below is how I succesfully loaded by raster data.

Preconfiguration. A BNG geotiff layer, generated from FME, has been imported into postgis using raster2pgsql. The command used was:

raster2pgsql -s 27700 -I -M -C {geotiffName}.tif -t 100x100 -l 2,4,6 {schema}.{tableName} | psql -U {user} -d {database}

This created the raster table along with its pyramid tables.

Currently my server has an instance of Geoserver 2.6.2, to use Postgis rasters it requires the extension JDBC Image Mosaic which can be downloaded from http://geoserver.org/release/2.6.2/ The extension .jar was then extracted into WEB-INF/lib This will then enable geoserver to use rasters from postgis. However to access the data several settings need configuring.

Following the instructions in http://docs.geotools.org/latest/userguide/library/coverage/pgraster.html but slightly tweaked:

create table {schema}.MOSAIC (NAME varchar(254) not null,
     TileTable varchar(254)not null,
     minX FLOAT8,minY FLOAT8, maxX FLOAT8, maxY FLOAT8,resX FLOAT8, resY FLOAT8, primary key (NAME,TileTable))

Now insert records for a "coverage", named oek in the example, these are your raster tables: the master one and pyramid ones.

insert into {schema}.MOSAIC (name, tiletable) values ('oek', {Main raster table name});
insert into {schema}.MOSAIC (name, tiletable) values ('oek', {raster pyramid 2 table name});
insert into {schema}.MOSAIC (name, tiletable) values ('oek', {raster pyramid 4 table name});
insert into {schema}.MOSAIC (name, tiletable) values ('oek', {raster pyramid 6 table name});

Also according to the docs, for Postgis JDBC drivers < version 9 it is necessary to set a property in the database:

ALTER DATABASE dbname SET bytea_output TO 'escape'

Now Geoserver configuration:

Within your Geoserver data directory create a directory /data/coverages this needs to contain 3 files: connect.pgraster.xml.inc, mapping.pgraster.xml.inc, oek.pgraster.xml

Follow http://docs.geotools.org/latest/userguide/library/coverage/pgraster.html for their naming and contents. Obviously adjust the database connection string and username/password settings in connect.pgraster.xml.inc

mapping.pgraster.xml.inc is where we need to reference the raster tables correctly.

<spatialExtension name="pgraster"/>
 <mapping>
  <masterTable name="MOSAIC" >
          <coverageNameAttribute name="name"/>
          <maxXAttribute name="maxX"/>
          <maxYAttribute name="maxY"/>
          <minXAttribute name="minX"/>
          <minYAttribute name="minY"/>
          <resXAttribute name="resX"/>
          <resYAttribute name="resY"/>
          <tileTableNameAtribute  name="tiletable" />
  </masterTable>
  <tileTable>
          <blobAttributeName name="rast" />
  </tileTable>
</mapping>

So this will get the values we added to the MOSAIC table, the name values are the columns of MOSAIC, which link to our raster table and pyramid tables. rast is the name of the raster column in the raster tables.

In oek.pgraster.xml make sure your SRS is correctly set, 27700 BNG in this case.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE ImageMosaicJDBCConfig [
  <!ENTITY mapping PUBLIC "mapping"  "mapping.pgraster.xml.inc">
  <!ENTITY connect PUBLIC "connect"  "connect.pgraster.xml.inc">
]>

<config version="1.0">
  <coverageName name="oek"/>
  <coordsys name="EPSG:27700"/>
  <!-- interpolation 1 = nearest neighbour, 2 = bipolar, 3 = bicubic -->
  <scaleop  interpolation="1"/>
<axisOrder ignore="false"/>
  &mapping;
  &connect;
</config

In Geoserver we can now add a new datastore.

Go to new Add new store.

Select ImageMosaicJDBC

Give it a name and the set the URL to file:coverages/oek.pgraster.xml

Save this, and fingers crossed no errors are returned, if they are check geoserver logs which hopefully will indicate what the issue was, hopefully just a typo or naming issue.

Go to add a new layer and select the new raster data store.

Select your new layer/coverage named oek and publish it.

Then in the layer settings adjust your coordinate system and bounding boxes appropriately.

To style the raster follow docs here: http://docs.geoserver.org/latest/en/user/styling/sld-reference/rastersymbolizer.html

I added a style:

<RasterSymbolizer>
 <Opacity>1.0</Opacity>
  <ColorMap>
   <ColorMapEntry color="#ffffff" quantity="1" label="label1" opacity="1"/>
   <ColorMapEntry color="#0000ff" quantity="200" label="label2" opacity="1"/>
  </ColorMap>
</RasterSymbolizer>

This colored my rasters blue where they had a value.

You should then have a usable layer.

Disclaimer: I am no GIS expert, and a lot of what i worked through was trial and error. I have no doubt that there are better ways to do it, but for the time being I'm only working on a proof of concept to confirm if we have the capability to use raster data in postgis. Finer details like raster values and styling are things I still need to iron out, if I make any further progress I will update my answer.

share|improve this answer

Following the configuration instructions for the PostGIS raster plugin, you should try replacing

<spatialExtension name="postgis"/>

with

<spatialExtension name="pgraster"/>

in configration file mapping.postgis.xml.inc.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.