Changes between Version 119 and Version 120 of WKTRaster/SpecificationWorking01
- Timestamp:
- Apr 7, 2010, 11:20:21 AM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WKTRaster/SpecificationWorking01
v119 v120 169 169 == '''Objective 0.1.6e - Being able to intersect vector and raster to produce vector.''' == 170 170 171 List of PostGIS functions similar or related to ST_GetBBox(), ST_Envelope() and ST_ Shape():171 List of PostGIS functions similar or related to ST_GetBBox(), ST_Envelope() and ST_Polygon(): 172 172 173 173 [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.) … … 232 232 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 233 233 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. 235 235 236 236 This polygon geometry might contain holes if some internal areas of the raster contain pixels with NODATA values. 237 237 238 Variant 1: ST_ Shape(raster) -> polygon geometry -- default to band # 1238 Variant 1: ST_Polygon(raster) -> polygon geometry -- default to band # 1 239 239 240 240 '''Implementation details''' … … 242 242 Could also be named ST_Outline(). 243 243 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. 247 247 248 248 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. 249 249 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(). 258 253 259 254 '''Implementation details''' … … 263 258 The "CONTIGUOUS" version could be implemented by "dumping" (see geometry_dump in PostGIS) the complex polygon into separate simple polygons. 264 259 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: 266 261 267 262 CREATE TYPE geomval AS (geom geometry, val float8);[[BR]] 268 263 CREATE TYPE wktgeomval AS (wktgeom text, val float8); 269 264 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]] 272 267 $$ LANGUAGE SQL; 273 268 274 269 It should then be used like this: 275 270 276 SELECT (gv).val, (gv).geom FROM (SELECT ST_ AsPolygon(rast) gv FROM sometable) foo271 SELECT (gv).val, (gv).geom FROM (SELECT ST_DumpAsPolygons(rast) gv FROM sometable) foo 277 272 278 273 [[Image(WKTRasterAsPolygon.gif)]] 279 274 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 # 1275 '''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 283 278 284 279 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. 285 280 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. 289 284 290 285 '''Implementation details''' … … 311 306 2) If the first test returns TRUE, it checks if the geometry returned by ST_ConvexHull(raster) intersects with the geometry. 312 307 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. 314 309 315 310 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). … … 361 356 ST_Intersection(raster, raster, 'geometry') -> geometry -- default both raster to band # 1 362 357 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. 364 359 365 360 If the geometries do not share any space (are disjoint), then an empty geometry collection is returned. … … 373 368 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: 374 369 375 ST_Intersection(ST_ Shape(raster), geometry)370 ST_Intersection(ST_Polygon(raster), geometry) 376 371 377 372 '''Implementation details''' 378 373 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). 380 375 381 376 Priority 1 should be given to the raster/geometry variants (original and variant 1) returning a geometry. … … 736 731 a. ML: ST_AsTIFF - Do we aim to depend on libgeotiff?[[BR]][[BR]] 737 732 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]] 739 734 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. 740 735 * 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]]