h2gis icon indicating copy to clipboard operation
h2gis copied to clipboard

H2 native raster functions

Open nicolas-f opened this issue 9 years ago • 29 comments

  • [x] raster::geometry
    • Convex hull of the raster (taking account of rotation)
  • [x] ST_MetaData( RASTER ) ->ARRAY (Coordinate X, Coordinate Y, Width, Height, ScaleX, ScaleY, SkewX, SkewY, SRID, bands count)
    • Get WKB metadata
  • [x] ST_RasterFromImage( BLOB, upperLeftX, upperLeftY, scaleX, scaleY, skewX, skewY, srid)
    • Convert image stream into Raster using ImageIO (JAI can extend supported formats)
  • [x] ST_ImageFromRaster( RASTER, FormatSuffix )
    • FormatSuffix ex: png tiff
    • ImageIO support also MimeType, but this is less user friendly.
  • [x] ImageIO driver for reading WKBRaster as a Raster and/or BufferedImage.
    • Image cannot be read if Blob is freed or connection is closed.
  • [x] ImageIO ImageInputStream driver, that create ImageInputStream from JDBC Blob
  • [x] ST_MakeEmptyRaster
  • [ ] ST_AddBand with offdb image file (delivered with H2GIS)
  • [x] ST_BandMetaData(raster rast, integer bandnum=1)
  • [x] FILE_WRITE( lob, String ) ??
  • [x] Image IO WKB Raster
  • [ ] Image IO WKB Raster with offDb bands
  • [x] LobDB, RenderedImage wrapping (in order to not break JAI processing chains)

nicolas-f avatar Sep 17 '15 12:09 nicolas-f

ST_ImageFromRaster must detect the format suffix no ?

ebocher avatar Sep 17 '15 12:09 ebocher

The format of Raster is WKB Raster. This function must translate into another format, defined by the user.

nicolas-f avatar Sep 17 '15 12:09 nicolas-f

So this functions is used to convert ?

ebocher avatar Sep 17 '15 12:09 ebocher

Yes this is the inverse of ST_RasterFromImage. So you should call something like that:

SELECT ST_ImageFromRaster(ST_RASTERFROMIMAGE(FILE_READ('/home/user/aerial.png'), 150, 200, 1, 1, 0, 0, 4326), 'bmp') bmpData;

nicolas-f avatar Sep 17 '15 12:09 nicolas-f

Perfect

ebocher avatar Sep 17 '15 13:09 ebocher

Added ImageIO drivers

nicolas-f avatar Sep 22 '15 07:09 nicolas-f

Added ST_ImageFromRaster

nicolas-f avatar Sep 23 '15 13:09 nicolas-f

Maybe implement FILE_WRITE( lob, String ), to write image obtained through ImageFromRaster ?

nicolas-f avatar Sep 24 '15 12:09 nicolas-f

Yes you are right

ebocher avatar Sep 24 '15 12:09 ebocher

Add ST_MakeEmptyRaster

nicolas-f avatar Sep 25 '15 13:09 nicolas-f

Raster.toString() is converted into human readable metadata: w:10 h:10 bands:3 srid:27572 x:0.00000 y:0.00000 scalex:1.00000 scaley:-1.00000 skewx:0.00000 skewy:0.00000

nicolas-f avatar Sep 25 '15 13:09 nicolas-f

@nicolas-f Maybe its more clear to write ST_MakeEmptyRaster ?

gpetit avatar Sep 25 '15 13:09 gpetit

ok..

nicolas-f avatar Sep 25 '15 13:09 nicolas-f

Add ST_BandMetaData

nicolas-f avatar Sep 28 '15 08:09 nicolas-f

Currently WKB Image parsing is slow because there is absolutely no pixel cache. Here a sample of what is done currently:

I want RGB of pixel 500 red = Blob.getInputStream().skip(adressOfRedBandPixelZero) green = stream.skip(adressOfGreenPixelZero) blue = stream.skip(adressOfBluePixelZero)

I want RGB of Pixel 501 The problem here is the stream is in the blue band area. We have to reopen the stream and skip to the red band for pixel 501.

One solution

The class WKBRasterDataBuffer should cache the bands values for a row. The goal is to reset the minimum of times the stream and reduce the seek amount.

nicolas-f avatar Oct 08 '15 14:10 nicolas-f

Add ST_WorldToRasterCoord ST_WorldToRasterCoordX ST_WorldToRasterCoordY

nicolas-f avatar Oct 09 '15 12:10 nicolas-f

To be consistent with geometry drivers, ST_RasterFromFile function will be renamed by ST_WorldFileImageRead (eg SHPRead) and a new function ST_WorldFileImageWrite will be added.

ebocher avatar Oct 13 '15 08:10 ebocher

Note : I don't want to use raster because it's a type (a category of datatype) and not a format like worldfile, geotiff.

ebocher avatar Oct 13 '15 08:10 ebocher

what about ST_RasterFromWorldFile ?

nicolas-f avatar Oct 13 '15 08:10 nicolas-f

No because we must also write st_geometryfromfile ;-)

ebocher avatar Oct 13 '15 08:10 ebocher

ST_WorldFileImageWrite will have the following signature

ST_WorldFileImageWrite(RASTER, '/tmp/toto.png')

Usages

SELECT ST_WorldFileImageWrite(the_raster, '/tmp/toto.png') from myRasterTable limit 1;
SELECT ST_WorldFileImageWrite(the_raster,concat( concat( '/tmp/toto_', pkValue), '.png')) from myRasterTable;

ebocher avatar Oct 13 '15 08:10 ebocher

@nico any input about this feature ? We are looking forward using raster in H2GIS ;-)

gpetit avatar Mar 01 '18 15:03 gpetit

Note : The TIFF format will be integrated in JAVA 9 http://openjdk.java.net/jeps/262

ebocher avatar Mar 01 '18 15:03 ebocher

Nice.

@gpetit I've merged the raster branch with the last h2 update. I have to write documentation and then create a pull request to h2 database.

nicolas-f avatar Mar 02 '18 08:03 nicolas-f

+1 We can help you to write the documentation.

ebocher avatar Mar 02 '18 08:03 ebocher

The branch is here https://github.com/nicolas-f/h2database/tree/georaster_patch

Off db raster is still not supported yet. But band metadata can already store the path of the external image.

nicolas-f avatar Mar 02 '18 08:03 nicolas-f

Add a unit test ? SELECT FILE_WRITE(ST_IMAGEFROMRASTER(data, 'png'), '/tmp/test.png') FROM test @nicolas-f

ebocher avatar Mar 08 '18 11:03 ebocher

Test done

ebocher avatar Mar 08 '18 14:03 ebocher

A good day https://github.com/h2database/h2database/pull/945

ebocher avatar Mar 08 '18 15:03 ebocher