Changes between Version 119 and Version 120 of WKTRaster/SpecificationWorking01


Ignore:
Timestamp:
Apr 7, 2010, 11:20:21 AM (14 years ago)
Author:
pracine
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • WKTRaster/SpecificationWorking01

    v119 v120  
    169169== '''Objective 0.1.6e - Being able to intersect vector and raster to produce vector.''' ==
    170170
    171 List of PostGIS functions similar or related to ST_GetBBox(), ST_Envelope() and ST_Shape():
     171List of PostGIS functions similar or related to ST_GetBBox(), ST_Envelope() and ST_Polygon():
    172172
    173173[http://postgis.refractions.net/documentation/manual-1.4/ST_Boundary.html ST_Boundary(geometry)] (not really - always return a geometry a dimension lower - i.e. the boundary of a polygon is a polyline.)
     
    232232 This function is actually already implemented by the ST_raster_envelope() function which is wrongly named. There is also a ticket (#348) related to this function: http://trac.osgeo.org/postgis/ticket/348
    233233
    234 '''ST_Shape(raster, integer) -> polygon geometry''' - Returns a geometry encomparsing every pixel having a significant value (different than the NODATA value) for the provided band.
     234'''ST_Polygon(raster, integer) -> polygon geometry''' - Returns a geometry encomparsing every pixel having a significant value (different than the NODATA value) for the provided band.
    235235
    236236 This polygon geometry might contain holes if some internal areas of the raster contain pixels with NODATA values.
    237237
    238  Variant 1: ST_Shape(raster) -> polygon geometry -- default to band # 1
     238 Variant 1: ST_Polygon(raster) -> polygon geometry -- default to band # 1
    239239
    240240 '''Implementation details'''
     
    242242 Could also be named ST_Outline().
    243243
    244  This function could be roughly implemented as a SQL function looking like 'SELECT ST_Collect((ST_AsPolygon(raster)).geom)'. For sure a more specialised version could be faster than ST_AsPolygon.
    245 
    246 '''ST_AsPolygon(raster, integer) -> geomval set''' - Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided band.
     244 This function could be roughly implemented as a SQL function looking like 'SELECT ST_Collect((ST_DumpAsPolygons(raster)).geom)'. For sure a more specialised version could be faster than ST_AsPolygon.
     245
     246'''ST_DumpAsPolygons(raster, integer) -> geomval set''' - Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided band.
    247247
    248248 This is a set-returning function (SRF). A "geomval" value is a complex type composed of a polygon geometry (one for each group of pixel sharing the same value) and the value associated with this geometry. These values are always returned as a value of type double precision. The shape of each polygon follow pixels edges.
    249249
    250  Variant 1: ST_AsPolygon(raster) -> geomval set -- default to band # 1
    251 
    252  Variant 2: ST_AsPolygon(raster, integer, 'CONTIGUOUS')[[BR]] -- the second parameter is the raster band number
    253  Variant 3: ST_AsPolygon(raster, 'CONTIGUOUS') -- default to band # 1
    254 
    255  This function should be used with precaution on raster with float pixel type as it could return one "geomval" (or polygon) per pixel. This kind of raster should be reclassified (using the planned ST_Reclassify(raster,...) function) before using ST_AsPolygon().
    256 
    257  Variant 2 & 3 splits every resulting complex polygon sharing the same value into simple (or singlepart) polygons.
     250 Variant 1: ST_DumpAsPolygons(raster) -> geomval set -- default to band # 1
     251
     252 This function should be used with precaution on raster with float pixel type as it could return one "geomval" (or polygon) per pixel. This kind of raster should be reclassified (using the planned ST_Reclassify(raster,...) function) before using ST_DumpAsPolygons().
    258253
    259254 '''Implementation details'''
     
    263258 The "CONTIGUOUS" version could be implemented by "dumping" (see geometry_dump in PostGIS) the complex polygon into separate simple polygons.
    264259
    265  To avoid linking directly with PostGIS (see "Why avoid to link with PostGIS?" below) It should be implemented as a SQL wrapper around ST_AsWKTPolygon() looking something like this:
     260 To avoid linking directly with PostGIS (see "Why avoid to link with PostGIS?" below) It should be implemented as a SQL wrapper around DumpAsWKTPolygons() looking something like this:
    266261
    267262 CREATE TYPE geomval AS (geom geometry, val float8);[[BR]]
    268263 CREATE TYPE wktgeomval AS (wktgeom text, val float8);
    269264
    270  CREATE OR REPLACE FUNCTION ST_AsPolygon(rast raster) RETURNS SETOF geomval AS $$[[BR]]
    271      SELECT ST_GeomFromText(wktgeomval.wktgeom), wktgeomval.val FROM ST_AsWKTPolygon(%1) AS wktgeomval;[[BR]]
     265 CREATE OR REPLACE FUNCTION ST_DumpAsPolygons(rast raster) RETURNS SETOF geomval AS $$[[BR]]
     266     SELECT ST_GeomFromText(wktgeomval.wktgeom), wktgeomval.val FROM DumpAsWKTPolygons(%1) AS wktgeomval;[[BR]]
    272267 $$ LANGUAGE SQL;
    273268
    274269 It should then be used like this:
    275270
    276  SELECT (gv).val, (gv).geom FROM (SELECT ST_AsPolygon(rast) gv FROM sometable) foo
     271 SELECT (gv).val, (gv).geom FROM (SELECT ST_DumpAsPolygons(rast) gv FROM sometable) foo
    277272
    278273[[Image(WKTRasterAsPolygon.gif)]]
    279274
    280 '''ST_AsWKTPolygon(raster, integer) -> wktgeomval set''' - Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided band.
    281 
    282  Variant 1: ST_AsWKTPolygon(raster) -> wktgeomval set -- default to band # 1
     275'''DumpAsWKTPolygons(raster, integer) -> wktgeomval set''' - Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided band.
     276
     277 Variant 1: DumpAsWKTPolygons(raster) -> wktgeomval set -- default to band # 1
    283278
    284279 This is a set-returning function (SRF). A "wktgeomval " value is a complex type composed of a the wkt representation of a geometry (one for each group of pixel sharing the same value) and the value associated with this geometry. These values are always returned as a value of type double precision. The shape of each polygon follow pixels edges. Areas with NODATA values are not included in the resulting set.
    285280
    286  This function should be used with precaution on raster with float pixel type as it could return one "geomval" (or polygon) per pixel. This kind of raster should be reclassified (using the planned ST_Reclassify(raster,...) function) before using ST_AsWKTPolygon().
    287 
    288  ST_AsWKTPolygon() should not be used directly. Use ST_AsPolygon() instead.
     281 This function should be used with precaution on raster with float pixel type as it could return one "geomval" (or polygon) per pixel. This kind of raster should be reclassified (using the planned ST_Reclassify(raster,...) function) before using DumpAsWKTPolygons().
     282
     283 DumpAsWKTPolygons() should not be used directly. Use ST_DumpAsPolygons() instead.
    289284
    290285 '''Implementation details'''
     
    311306 2) If the first test returns TRUE, it checks if the geometry returned by ST_ConvexHull(raster) intersects with the geometry.
    312307
    313  3) If the second test returns TRUE, it checks if the geometry returned by ST_Shape(raster, integer) intersects with the geometry. This test is slower since it involve the computation of the raster shape and it might involve the geometry shape. This test takes NODATA values into account. i.e. A geometry intersecting only with a NODATA value area of a raster is NOT actually not intersecting with this raster. This behavior may be controled by limiting the test to certain conditions as stated below.
     308 3) If the second test returns TRUE, it checks if the geometry returned by ST_Polygon(raster, integer) intersects with the geometry. This test is slower since it involve the computation of the raster shape and it might involve the geometry shape. This test takes NODATA values into account. i.e. A geometry intersecting only with a NODATA value area of a raster is NOT actually not intersecting with this raster. This behavior may be controled by limiting the test to certain conditions as stated below.
    314309
    315310 Variant 4 proceeds in a very similar way except that convex hulls of both rasters are computed and compared in step 2) and both shape of raster are computed and compared in step 3).
     
    361356  ST_Intersection(raster, raster, 'geometry') -> geometry -- default both raster to band # 1
    362357
    363  This is a set-returning function (SRF). It returns a set of "geomval" representing the point set intersection of the geometry and the areas of the raster sharing a common meaningfull value (NODATA values ARE taken into account). The raster is first polygonised using ST_AsPolygon(raster) and ST_Intersection(geometry, geometry) is then performed between the provided geometry and all the geometries resulting from the polygonisation of the raster.
     358 This is a set-returning function (SRF). It returns a set of "geomval" representing the point set intersection of the geometry and the areas of the raster sharing a common meaningfull value (NODATA values ARE taken into account). The raster is first polygonised using ST_DumpAsPolygons(raster) and ST_Intersection(geometry, geometry) is then performed between the provided geometry and all the geometries resulting from the polygonisation of the raster.
    364359
    365360 If the geometries do not share any space (are disjoint), then an empty geometry collection is returned.
     
    373368 If you only want to compute the intersection between the shape of the raster without polygonising it to group of pixels sharing a common value, do:
    374369
    375   ST_Intersection(ST_Shape(raster), geometry)
     370  ST_Intersection(ST_Polygon(raster), geometry)
    376371
    377372 '''Implementation details'''
    378373
    379  This function should be implemented as a pl/pgSQL function (possibly only a SQL function) performing the intersection between the provided geometry and the table generated by ST_AsPolygon(raster).
     374 This function should be implemented as a pl/pgSQL function (possibly only a SQL function) performing the intersection between the provided geometry and the table generated by ST_DumpAsPolygons(raster).
    380375
    381376 Priority 1 should be given to the raster/geometry variants (original and variant 1) returning a geometry.
     
    736731  a. ML: ST_AsTIFF - Do we aim to depend on libgeotiff?[[BR]][[BR]]
    737732  a. ML: Is there any function that would require/fit GDAL dependency?[[BR]][[BR]]
    738   a. Pierre: We should maybe investigate the cost of using GDAL and have a general ST_AsImage(format, params) instead of using the individual tiff, jpeg and png libraries. Those will anyway also have a cost I guess... And we will probably have to link with GDAL for AsPolygon(rast) and AsRaster(geom) anyway.[[BR]][[BR]]
     733  a. Pierre: We should maybe investigate the cost of using GDAL and have a general ST_AsImage(format, params) instead of using the individual tiff, jpeg and png libraries. Those will anyway also have a cost I guess... And we will probably have to link with GDAL for DumpAsPolygons(rast) and AsRaster(geom) anyway.[[BR]][[BR]]
    739734 1. '''Implementing raster -> vector conversion for intersections().''' How to do it? Possible using only plpgsql? So we don't have to link with liblwgeos and we can have our own release schedule.
    740735   * polygonize with GDAL or GRASS, that generates some internal structure for those libraries, and you turn that into a WKT form of polygon. That can be passed to PostGIS, and you don't need to link to liblwgeom.[[BR]][[BR]]