wiki:WKTRaster/SpecificationWorking03

Version 25 (modified by pracine, 14 years ago) ( diff )

PostGIS WKT Raster Beta 03 (and up) Working Specifications


Objective 02 - Being able to intersect vector and raster to produce raster.

ST_Intersects(raster, raster)
ST_AsRaster(geometry, pixelsize) → raster
ST_Intersection(geometry, val, raster, band) → raster

The first series of variant return a raster having the same extent as the provided raster.

Variant 1: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue) → raster

Variant 2: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue) → raster

Variant 3: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue) → raster

Variant 4: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue) → raster

The second series of variant return a raster having the minimal extent.

Variant 5: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue, 'TRIM') → raster

Variant 6: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue, 'TRIM') → raster

Variant 7: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue, 'TRIM') → raster

Variant 8: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue, 'TRIM') → raster

Returns a two bands raster the first band containing only the pixels from the provided raster intersecting with the geometry and the second band containing the same area filled with the provided value.

The second band gets its pixeltype and nodatavalue from the parameters.

Non intersecting pixels are filled with nodata values.

Variant 1 return a raster having the same extent as the provided raster.

Variant 3, 4, 7 and 8 defaults the band number to 1.

Variant 5 to 8 "trim" or "crop" the raster to the withvalue extent (removing extra nodata value pixels surrounding the extent of the resulting withvalue extent).

Open question

PR: Shoud we return one raster per raster/geometry couple or split the raster into as many small rasters as there are areas sharing a same value? The second behavior seems more coherent with the present behavior of ST_Intersection(raster, geometry) → geometry even if this would produce tons of small two bands rasters.

Implementation details

Rasterize the geometry as a new raster (ST_AsRaster(geometry, pixeltype, val, nodataval, raster)) and then copy only pixels for which both raster bands have a value. Should be implemented as a wrapper around ST_MapAlgebra after rasterizing the geometry to a raster having the same alignment as the raster.


Objective 03 - Being able to use "group by" to accumulate tiles to form a new raster.

ST_Union(raster|geometry, raster|geometry, ‘raster’|’geometry’) → raster/geometry
ST_Accum(raster set|geometry set, ‘raster’|’geometry’) → raster/geometry


Objective 05 - Being able to reproject a raster.

ST_Transform(raster|geometry, SRID) → same type as input


Objective 06 - Being able to do some base raster operations.

ST_Area(raster|geometry) → double
ST_Count(raster, value) → integer

ST_Resample(raster, method, originx, originy, pixelsizex, pixelsizey) → raster

Variant

1) ST_Resample(raster, method, raster) → raster

Recompute a raster in order to change its pixel size and/or the position of its upper left corner.

The second parameter is the resampling method performed when computing new pixel values:

1) 'NEAREST NEIGHBOR'
2) 'LINEAR'
3) 'BICUBIC'

The 3rd or 3rd-6th parameters define the pixel size of the resampling operation. For the 3rd parameter variant, the pixel size is taken from the pixel size of the raster parameter. For the 3rd-6th parameter variant, the pixel origin and dimensions are explicitly defined.

ST_SelectByValue(raster|geometry, ‘expression’) → same type as first argument
ST_Reclass(raster|geometry,string) → same type as first argument

ST_MapAlgebra(raster|geometry, [raster|geometry,…] ‘mathematical expression’, ‘raster’ |’geometry’) → raster/geometry

Variant 1: ST_MapAlgebra(raster|geometry, [raster|geometry,…] ‘mathematical expression’, ‘raster’ |’geometry’, originx, originy, pixelsizex, pixelsizey) → raster/geometry

Variant 2: ST_MapAlgebra(raster|geometry, [raster|geometry,…] 'mathematical expression', 'raster' |'geometry', integer) →raster/geometry

Variant 3: ST_MapAlgebra(raster|geometry, [raster|geometry,…] 'mathematical expression', 'raster' |'geometry', raster) →raster/geometry

ST_MapAlgebra performs the specified mathematical expression on the input rasters, returning a raster or geometry. Both rasters must have the same SRID. If both rasters do not have the same SRID, ST_MapAlgebra will return an error:

ERROR: Operation on two geometries with different SRIDs

The first raster passed to ST_MapAlgebra is the 'master' raster, unless either:

1 additional parameter specifies the index (in the parameter list) of the 'master' raster.
1 additional parameter specifies a raster whose origin and cell size should be used to compute the output raster.
4 additional parameters are passed specifying the origin, cell size, and raster rotation.

This function implicitly calls ST_Intersects(raster|geometry, [raster|geometry,…]) to detect if the rasters are overlapping before performing any computation. Additionally, the resulting raster will have the same extent as the result of ST_Intersection(raster, integer, geometry).

One of the implications of the ST_Intersects inclusion is that:

SELECT ST_MapAlgebra(rast1, rast2, mathExpr) FROM mytable WHERE ST_Intersects(rast1, rast2)

will be faster than:

SELECT ST_MapAlgebra(rast1, rast2, mathExpr) FROM mytable

Open Question:

DZ: Should ST_MapAlgebra resample rasters internally, or produce a raster that can be processed by ST_Resample? If so, variant 1 and variant 3 can be removed, and all ST_MapAlgebra results can be processed through ST_Resample, like:

ST_Resample(ST_MapAlgebra(raster, [raster,…] 'mathematical expression', integer), originx, originy, pixelsizex, pixelsizey)
ST_Resample(ST_MapAlgebra(raster, [raster,…] 'mathematical expression', integer), rastergrid)

PR: I think this would greatly contribute to simplify the API.

ST_Clip(raster|geometry,geometry) → same type as first argument
ST_Flip(raster|geometry, ’vertical’|’horizontal’) → same type as first argument


Objective 07 - Being able to convert a raster to standards formats.

ST_AsKML(raster|geometry) → string
ST_AsSVG(raster|geometry) → string


Objective 08 - Being able to control the validity of a raster.

ST_IsEmpty(raster|geometry) → boolean
ST_mem_size(raster|geometry) → integer
ST_isvalid(raster|geometry) → boolean


Objective 09 - Being able to use other major topological operators

ST_Within(raster|geometry A, raster|geometry B)
ST_Contains(raster|geometry A, raster|geometry B)
ST_Overlaps(raster|geometry, raster|geometry)


Objective 10 - Being able to derive a raster layer from vector layer.

ST_Interpolate(points, pixelsize, method) → raster


Objective 11 - Being able to do on rasters most operations available on geometries

ST_Centroid(raster|geometry) → point geometry
ST_PointOnSurface(raster|geometry) → point geometry
ST_Buffer(raster|geometry, double) → same type as first arg.
ST_Difference(raster|geometry A, raster|geometry B) → same type as first argument
ST_SymDifference(raster|geometry,raster|geometry,‘raster’|’geometry’) → raster/geometry


Objective 12 - Being able to use all the other topological operators

ST_Equals(raster|geometry, raster|geometry)
ST_Disjoint(raster|geometry, raster|geometry)
ST_Touches(raster|geometry, raster|geometry)
ST_Crosses(raster|geometry, raster|geometry)
ST_Covers(raster|geometry A, raster|geometry B)
ST_IsCoveredBy(raster|geometry A, raster|geometry B)
ST_Relate(raster|geometry, raster|geometry, intersectionPatternMatrix )


Objective 13 - Being able to edit a raster

ST_Affine(raster|geometry,…) → same type as input
ST_Translate(raster|geometry,…) → same type as input
ST_Scale(raster|geometry,…) → same type as input
ST_TransScale(raster|geometry,…) → same type as input
ST_RotateZ,Y,Z(raster|geometry, float8) → same type as input


Objective 14 - Being able to intersect two rasters to get a raster.

ST_Intersection(raster, integer, raster, integer) → raster - Returns a two bands raster with values only in the intersecting areas of both rasters. Integer parameters are the band number of the raster.

Variants

1) ST_Intersection(raster, integer, raster, integer) → raster — the integer parameters are the band number of the rasters
2) ST_Intersection(raster, raster, integer) → raster — default first raster to band # 1
3) ST_Intersection(raster, integer, raster) → raster — default second raster to band # 1
4) ST_Intersection(raster, raster) → raster — default both rasters to band # 1


Objective 15 - Being able to intersect two rasters to get a geometry.

ST_Intersection(raster, integer, raster, integer, 'geometry') → geometry - Returns a two bands raster with values only in the intersecting areas of both rasters. Integer parameters are the band number of the raster.

Variants

1) ST_Intersection(raster, integer, raster, integer, 'geometry') → geometry
2) ST_Intersection(raster, raster, integer, 'geometry') → geometry — default first raster to band # 1
3) ST_Intersection(raster, integer, raster, 'geometry') → geometry — default second raster to band # 1
4) ST_Intersection(raster, raster, 'geometry') → geometry — default both raster to band # 1


Objective 16 - Being able to quickly get raster statistics.

Add cached basic raster statistic to the base raster WKB format.


Objective 17 - Being able to refer to band by textual name.

Add 8 digit string to each band in the base raster WKB format.

Adjust gdal2wktraster.py to be able to give names to each band when importing.

Adjust/overlaod every function to be able to refer to raster band by name.


Objective 18 - Being able to load rasters from SQL

The idea is to change the rt_band_get_data core function so it load filesystem registered raster data using GDAL into the data base. This allow us to create a list of raster with a new ST_MakeRegisteredRaster("c:/temp/mytiff/*.tif") and to convert them witinot a CREATE TABLE with a ST_MakeBandInDB(rast, band)

Changes to the rt_band_get_data core function
ST_MakeRegisteredRaster(wildcardPath)
ST_SetPath(raster, band, string)
ST_MakeBandInDB(rast, band)


Other functions

ST_AsBinary(raster, compression)
ST_RasterFromWKB(raster, [<srid>])
ST_RasterFromText(string, [<srid>])
ST_AsText(raster)

Note: See TracWiki for help on using the wiki.