Changes between Version 203 and Version 204 of WKTRaster/SpecificationWorking03


Ignore:
Timestamp:
Dec 15, 2011, 4:04:42 PM (12 years ago)
Author:
Bborie Park
Comment:

ST_Intersection(raster, raster) and ST_Intersection(raster, geometry)

Legend:

Unmodified
Added
Removed
Modified
  • WKTRaster/SpecificationWorking03

    v203 v204  
    1818== ''Note that accomplished objectives have been moved at the bottom of the page.'' ==
    1919
    20 
    21 ----
    22 
    23 == '''Objective FV.02 - Being able to intersect vector and raster to produce raster.''' ==
    24  
    25 
    26 '''ST_Intersects(raster, raster) -> boolean - done see below'''[[BR]]
    27 
    28 '''ST_AsRaster(geometry, pixeltype, val, nodataval, ulx, uly, width, height, pixelsizex, pixelsizey, skewx, skewy) -> raster - done see below'''
    29 
    30 '''ST_Intersection(geometry, val, raster, band) -> raster'''
    31 
    32  The first series of variant return a raster having the same extent as the provided raster.
    33 
    34   Variant 1: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue) -> raster
    35 
    36   Variant 2: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue) -> raster
    37 
    38   Variant 3: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue) -> raster
    39 
    40   Variant 4: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue) -> raster
    41 
    42  The second series of variant return a raster having the minimal extent.
    43 
    44   Variant 5: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue, 'TRIM') -> raster
    45 
    46   Variant 6: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster
    47 
    48   Variant 7: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue, 'TRIM') -> raster
    49 
    50   Variant 8: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster
    51 
    52  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.
    53 
    54  The second band gets its pixeltype and nodatavalue from the parameters.
    55 
    56  Non intersecting pixels are filled with nodata values.
    57 
    58  Variant 1 return a raster having the same extent as the provided raster.
    59 
    60  Variant 3, 4, 7 and 8 defaults the band number to 1.
    61 
    62  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).
    63 
    64  
    65  '''Open questions'''
    66 
    67  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.
    68 
    69  '''Implementation details'''
    70 
    71  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.
    72  Should be implemented as a wrapper around ST_MapAlgebra after rasterizing the geometry to a raster having the same alignment as the raster.
    7320
    7421----
     
    382329
    383330----
    384 == '''Objective FV.14 - Being able to intersect two rasters to get a raster.''' ==
    385  
    386 '''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.
    387 
    388  '''Variants'''
    389 
    390   1) ST_Intersection(raster, integer, raster, integer) -> raster -- the integer parameters are the band number of the rasters[[BR]]
    391   2) ST_Intersection(raster, raster, integer) -> raster -- default first raster to band # 1[[BR]]
    392   3) ST_Intersection(raster, integer, raster) -> raster -- default second raster to band # 1[[BR]]
    393   4) ST_Intersection(raster, raster) -> raster -- default both rasters to band # 1
    394 
    395 ----
    396331== '''Objective FV.15 - Being able to intersect two rasters to get a geometry.''' ==
    397332 
     
    14951430~~ -How does GDAL/ArcGIS select which value to assign to the pixel when two or more features intersect with the pixel?~~
    14961431
     1432'''ST_Intersection(raster, band, geometry) -> raster'''
     1433
     1434ST_Intersection is plpgsql function wrapping the two-raster ST_MapAlgebra functions.  Performance should be about the same as calling ST_MapAlgebra directly except for the case where returnband is BOTH as that results in two separate ST_MapAlgebra calls.
     1435
     1436A set of ST_Intersection functions for raster, raster.
     1437
     1438{{{
     14391. ST_Intersection(
     1440    rast1 raster, nband1 int,
     1441    rast2 raster, nband2 int,
     1442    returnband text DEFAULT 'BOTH',
     1443    otheruserfunc regprocedure DEFAULT NULL
     1444);
     1445}}}
     1446
     1447  returnband: can be FIRST, SECOND, BOTH, OTHER
     1448
     1449    * FIRST returns the band of rast1 in the intersecting extent. returning raster will have one band.
     1450    * SECOND returns the band of rast2 in the intersecting extent. returning raster will have one band.
     1451    * BOTH returns the bands of rast1 and rast2 in the intersection extent. returning raster will have two bands.
     1452    * OTHER returns the computed band based upon rast1 and rast2 in the intersecting extent. returning raster will have one band. If OTHER, must provide a regprocedure to otherfunc
     1453
     1454  otheruserfunc: function to call when returnband = OTHER. Function format must be identical to tworastuserfunc of 2-raster ST_MapAlgebraFct.
     1455
     1456{{{
     14572. ST_Intersection(
     1458    rast1 raster, nband1 int,
     1459    rast2 raster, nband2 int,
     1460    otheruserfunc regprocedure
     1461);
     1462}}}
     1463
     1464{{{
     14653. ST_Intersection(
     1466    rast1 raster,
     1467    rast2 raster,
     1468    returnband text DEFAULT 'BOTH',
     1469    otheruserfunc regprocedure DEFAULT NULL
     1470);
     1471}}}
     1472
     1473{{{
     14744. ST_Intersection(
     1475    rast1 raster,
     1476    rast2 raster,
     1477    otheruserfunc regprocedure
     1478);
     1479}}}
     1480
     1481A set of ST_Intersection functions for raster, geometry (converted to raster).
     1482
     1483{{{
     14841. ST_Intersection(
     1485    rast raster, nband int,
     1486    geom geometry,
     1487    extent text DEFAULT 'INTERSECTION',
     1488    otheruserfunc regprocedure DEFAULT NULL
     1489)
     1490}}}
     1491
     1492  extent: can be INTERSECTION, FIRST, SECOND, UNION though FIRST and INTERSECTION will probably be the most commonly used
     1493
     1494{{{
     14952. ST_Intersection(
     1496    rast raster, nband int,
     1497    geom geometry,
     1498    otheruserfunc regprocedure
     1499);
     1500}}}
     1501
     1502{{{
     15033. ST_Intersection(
     1504    rast raster,
     1505    geom geometry,
     1506    extent text DEFAULT 'INTERSECTON',
     1507    otheruserfunc regprocedure DEFAULT NULL
     1508);
     1509}}}
     1510
     1511{{{
     15124. ST_Intersection(
     1513    rast raster,
     1514    geom geometry,
     1515    otheruserfunc regprocedure
     1516);
     1517}}}
     1518
     1519~~ The first series of variant return a raster having the same extent as the provided raster.
     1520
     1521~~  Variant 1: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue) -> raster
     1522
     1523~~  Variant 2: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue) -> raster
     1524
     1525~~  Variant 3: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue) -> raster
     1526
     1527~~  Variant 4: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue) -> raster
     1528
     1529~~ The second series of variant return a raster having the minimal extent.
     1530
     1531~~  Variant 5: ST_Intersection(geometry, val, raster, band, pixeltype, nodatavalue, 'TRIM') -> raster
     1532
     1533~~  Variant 6: ST_Intersection(raster, band, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster
     1534
     1535~~  Variant 7: ST_Intersection(geometry, val, raster, pixeltype, nodatavalue, 'TRIM') -> raster
     1536
     1537~~  Variant 8: ST_Intersection(raster, geometry, val, pixeltype, nodatavalue, 'TRIM') -> raster
     1538
     1539~~ 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.
     1540
     1541~~ The second band gets its pixeltype and nodatavalue from the parameters.
     1542
     1543~~ Non intersecting pixels are filled with nodata values.
     1544
     1545~~ Variant 1 return a raster having the same extent as the provided raster.
     1546
     1547~~ Variant 3, 4, 7 and 8 defaults the band number to 1.
     1548
     1549~~ 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).
     1550
     1551 
     1552~~ '''Open questions'''
     1553
     1554~~ 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.
     1555
     1556~~ '''Implementation details'''
     1557
     1558~~ 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.
     1559~~ Should be implemented as a wrapper around ST_MapAlgebra after rasterizing the geometry to a raster having the same alignment as the raster.
     1560
    14971561----
    14981562
     
    16011665ST_MapAlgebraFct(r1.rast, r2.rast, 'raster_mapalgebra_intersection(double precision, double precision, text[])'::regprocedure, '32BF', 'INTERSECTION')
    16021666}}}
     1667
     1668----
     1669== '''Objective FV.14 - Being able to intersect two rasters to get a raster.''' ==
     1670 
     1671'''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.
     1672
     1673Please look at ST_Intersection(raster, geometry) in FV.01 for complete specs.
     1674
     1675~~ '''Variants'''
     1676
     1677~~  1) ST_Intersection(raster, integer, raster, integer) -> raster -- the integer parameters are the band number of the rasters[[BR]]
     1678~~  2) ST_Intersection(raster, raster, integer) -> raster -- default first raster to band # 1[[BR]]
     1679~~  3) ST_Intersection(raster, integer, raster) -> raster -- default second raster to band # 1[[BR]]
     1680~~  4) ST_Intersection(raster, raster) -> raster -- default both rasters to band # 1
    16031681
    16041682----