2

I would like to read raster from PostGIS. I can do it from files on disk, but I'm having difficulties to find examples reading from PostGIS. What do I have to change to set up the reader from files to PostGIS? This is how I do it with files:

        file= new File(filepath);
        }
        MainDialog.lastInputDir = file;
        AbstractGridFormat format = GridFormatFinder.findFormat(file);
        Hints hints = new Hints();
        if (format instanceof GeoTiffFormat) {
            hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
        }
        try {
            reader = format.getReader(file, hints);
            Style rasterStyle = null;
            GridCoverage2D cov = null;
            try {
                cov = reader.read(null);
            } catch (IOException giveUp) {
                throw new RuntimeException(giveUp);
            }

1 Answer 1

1

You will need the unsupported gt-postgis-raster module - which is currently being resurrected from being broken by the demise of the JDBC Image Mosaic module.

From the readme you need an XML file like:

<!-- 
  postgis raster config format, * = required element 
-->
<pgraster>
  <name></name>                       <!-- * name of the resulting coverage -->

  <!-- 
  database connection info, either name,host,port,etc... is required or jndi
  -->
  <database>                  
    <host></host>                     <!-- db hostname, defaults to 'localhost' -->
    <port></port>                     <!-- db port, defaults to '5432' -->
    <name></name>                     <!-- database name -->
    <user></user>                     <!-- database user -->
    <passwd></passwd>.                <!-- database password -->
    <jndi></jndi>                     <!-- JNDI data source name -->
  </database>

  <!--
  raster table / column config
  -->
  <raster>
    <table></table>                   <!-- * raster table name -->
    <schema></schema>                 <!-- raster table schema, defaults to 'public' -->
    <column></schema>                 <!-- raster table column, defaults to 'rast' -->
  </raster>

  <!--
  time column config
  -->
  <time>                              <!-- time dimension configuration -->
    <column>dstamp</column>           <!-- name of data/time column -->
  </time>

  <!-- 
  https://postgis.net/docs/postgis_gdal_enabled_drivers.html 
  -->
  <enableDrivers></enabledDrivers>.   <!-- Example: ENABLE_ALL -->
</pgraster>

And it looks like you read that in with something like:

PGRasterConfig config = new PGRasterConfig(file);
PGRasterReader reader = new PGRasterReader(config, null, null);
GridCoverage2D rast = reader.read(null);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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