• 金仓数据库 KingbaseGIS 使用手册(8.7. 栅格编辑函数、8.8. 栅格波段编辑函数)


    8.7. 栅格编辑函数

     

    8.7.1. ST_SetGeoReference

    ST_SetGeoReference —单次函数调用中设置6个地理参考值。参数之间相互用空格隔开。接受的输入类型可以是GDAL或ESRI格式,默认是GDAL格式

    用法

    raster ST_SetGeoReference(raster rast, text georefcoords, text format=GDAL);
    raster ST_SetGeoReference(raster rast, double precision upperleftx, double precision upperlefty,
       double precision scalex, doubleprecision scaley,
       double precision skewx, double precision skewy);

    描述

    单次函数调用中设置6个地理参考值。接受的输入类型可以是GDAL或ESRI格式,默认是GDAL格式。 如果没有提供6个值,该函数将会返回NULL。 GDAL和ESRI格式如下:

    GDAL格式:

    scalex skewy skewx scaley upperleftx upperlefty

    ESRI格式:

    scalex skewy skewx scaley upperleftx + scalex*0.5 upperlefty + scaley*0.5

    注意

    如果栅格有数据库之外的波段,修改地理参考可能会导致栅格外部存储数据的不正确访问。

    样例

    WITH foo AS (
    SELECT ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0) AS rast
    )
    SELECT
    0 AS rid, (ST_Metadata(rast)).*
    FROM foo
    UNION ALL
    SELECT
    1, (ST_Metadata(ST_SetGeoReference(rast,'10 0 0 -10 0.1 0.1', 'GDAL'))).*
    FROM foo
    UNION ALL
    SELECT
    2, (ST_Metadata(ST_SetGeoReference(rast,'10 0 0 -10 5.1 -4.9', 'ESRI'))).*
    FROM foo
    UNION ALL
    SELECT
    3, (ST_Metadata(ST_SetGeoReference(rast,1, 1, 10, -10, 0.001, 0.001))).*
    FROM foo;
    
    rid| upperleftx         | upperlefty         | width| height| scalex | scaley| skewx | skewy| srid | numbands
    ---+--------------------+--------------------+------+-------+--------+-------+-------+------+------+----------
    0  | 0                  | 0                  | 5    | 5     | 1      | -1    | 0     | 0    | 0    | 0
    1  | 0.1                | 0.1                | 5    | 5     | 10     | -10   | 0     | 0    | 0    | 0
    2  | 0.0999999999999996 | 0.0999999999999996 | 5    | 5     | 10     | -10   | 0     | 0    | 0    | 0
    3  | 1                  | 1                  | 5    | 5     | 10     | -10   | 0.001 | 0.001| 0    | 0

    参考

    ST_GeoReference, ST_ScaleX, ST_ScaleY, ST_UpperLeftX, ST_UpperLeftY

    8.7.2. ST_SetRotation

    ST_SetRotation —设置栅格的旋转弧度。

    用法

    float8 ST_SetRotation(raster rast, float8 rotation);

    描述

    统一设置栅格的旋转弧度。参考World File(https://en.wikipedia.org/wiki/World_file)获取更多信息。

    样例

    SELECT
    ST_ScaleX(rast1), ST_ScaleY(rast1), ST_SkewX(rast1), ST_SkewY(rast1),
    ST_ScaleX(rast2), ST_ScaleY(rast2), ST_SkewX(rast2), ST_SkewY(rast2)
    FROM (
    SELECT ST_SetRotation(rast, 15) AS rast1, rast as rast2 FROM dummy_rast
    ) AS foo;
    
    st_scalex           | st_scaley          | st_skewx           | st_skewy          | st_scalex| st_scaley|st_skewx| st_skewy
    --------------------+--------------------+--------------------+-------------------+----------+----------+--------+---------
    -1.51937582571764   | -2.27906373857646  | 1.95086352047135   | 1.30057568031423  |2         | 3        | 0      | 0
    -0.0379843956429411 | -0.0379843956429411| 0.0325143920078558 | 0.0325143920078558|0.05      | -0.05    | 0      | 0

    参考

    ST_Rotation, ST_ScaleX, ST_ScaleY, ST_SkewX, ST_SkewY

    8.7.3. ST_SetScale

    ST_SetScale —设置像元的X和Y值,单位以空间参考系的坐标单位为准,就是设置像元的宽度和高度。

    用法

    raster ST_SetScale(raster rast, float8 xy);
    raster ST_SetScale(raster rast, float8 x, float8 y);

    描述

    设置像元的X和Y值,单位以空间参考系的坐标单位为准,就是设置像元的宽度和高度。如果只传递了一个值,就假定X和Y值一样。

    注意

    ST_SetScale 和函数ST_Rescale不同的是函数ST_SetScale不对栅格做重复采样来匹配栅格的边界。 它只改变栅格的元数据信息或空间参考,以便纠正原有像元大小。而函数ST_Rescale 生成一个为了适应输入栅格边界而改变宽度和高度大小的新栅格。ST_SetScale函数不修改栅格的高度和宽度。

    样例

    UPDATE dummy_rast
    SET rast = ST_SetScale(rast, 1.5)
    WHERE rid = 2;
    SELECT ST_ScaleX(rast) As pixx, ST_ScaleY(rast) As pixy, Box3D(rast) As
    newboxFROM dummy_rast WHERE rid = 2;
    
    pixx | pixy |newbox
    -----+------+----------------------------------------------
    1.5  | 1.5  | BOX(3427927.75 5793244 0, 3427935.25 5793251.5 0)
    
    UPDATE dummy_rast
    SET rast = ST_SetScale(rast, 1.5, 0.55)
    WHERE rid = 2;
    SELECT ST_ScaleX(rast) As pixx, ST_ScaleY(rast) As pixy, Box3D(rast) As
    newbox
    FROM dummy_rastWHERE rid = 2;
    
    pixx | pixy |newbox
    -----+------+------------------------------------------------------------------
    1.5  | 0.55  | BOX(3427927.75 5793244 0,3427935.25 5793247 0)

    参考

    ST_ScaleX, ST_ScaleY, Box3D

    8.7.4. ST_SetSkew

    ST_SetSkew — 设置栅格的X和Y倾斜度(或者说旋转参数)。如果只传递一个参数,那么会将X和Y值设置相同。

    用法

    raster ST_SetSkew(raster rast, float8 skewxy);
    raster ST_SetSkew(raster rast, float8 skewx, float8 skewy);

    描述

    设置栅格的X和Y倾斜度(或者说旋转参数)。如果只传递一个参数,那么会将X和Y值设置相同。参考World File(https://en.wikipedia.org/wiki/World_file)获取更多信息。

    样例

    样例 1,x和y轴的倾斜设为不同的值:

    UPDATE dummy_rast SET rast = ST_SetSkew(rast,1,2) WHERE rid = 1;
    SELECT
    rid, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy,
    ST_GeoReference(rast) as georef
    FROM dummy_rast WHERE rid = 1;
    
    rid| skewx | skewy | georef
    ---+-------+-------+----------------------------------------------------------------------------------------
    1  | 1     | 2     | 2.0000000000 : 2.0000000000: 1.0000000000 : 3.0000000000: 0.5000000000 : 0.5000000000

    样例 2,x和y轴的倾斜设为相同的值:

    UPDATE dummy_rast SET rast = ST_SetSkew(rast,0) WHERE rid = 1;
    SELECT
    rid, ST_SkewX(rast) As skewx, ST_SkewY(rast) As skewy,
    ST_GeoReference(rast) as georef
    FROM dummy_rast WHERE rid = 1;
    
    rid| skewx | skewy |georef
    ---+-------+-------+--------------------------------------------------------------------------------------
    1  | 0     | 0     | 2.0000000000: 0.0000000000: 0.0000000000 : 3.0000000000: 0.5000000000 : 0.5000000000

    参考

    ST_GeoReference, ST_SetGeoReference, ST_SkewX, ST_SkewY

    8.7.5. ST_SetSRID

    ST_SetSRID — 设置栅格的SRID值。

    用法

    raster ST_SetSRID(raster rast, integer srid);

    描述

    设置栅格的SRID值。

    注意

    该函数不以任何方式转换栅格。它只是改变了栅格的参考系信息,对于后面的栅格空间转换很有用。

    参考

    3.3.1节, ST_SRID

    8.7.6. ST_SetUpperLeft

    ST_SetUpperLeft — 把左上角的的像元的值设置为投影的X和Y坐标。

    用法

    raster ST_SetUpperLeft(raster rast, double precision x, double precisiony);

    描述

    把左上角的的像元的值设置为投影的X和Y坐标。

    样例

    SELECT ST_SetUpperLeft(rast,-71.01,42.37) FROM dummy_rast WHERE rid = 2;

    参考

    ST_UpperLeftX, ST_UpperLeftY

    8.7.7. ST_Resample

    ST_Resample —使用一个指定的重采样算法、新维度参数(width和height)和任意一个网格角点和一个由其他栅格定义的栅格空间参考属性(由函数的形式参数ref指定)来重采样一个栅格。

    用法

    raster ST_Resample(raster rast, integer width, integer height,
       double precision gridx=NULL, double precision gridy=NULL,
       double precision skewx=0, double precision skewy=0,
       text algorithm=NearestNeighbour, double precision maxerr=0.125);
    raster ST_Resample(raster rast, double precision scalex=0, double precision scaley=0,
       double precision gridx=NULL, double precision gridy=NULL,
       double precision skewx=0, double precision skewy=0,
       text algorithm=NearestNeighbor, double precision maxerr=0.125);
    raster ST_Resample(raster rast, raster ref, text algorithm=NearestNeighbour,
       double precision maxerr=0.125, boolean usescale=true);
    raster ST_Resample(raster rast, raster ref, boolean usescale,
       text algorithm=NearestNeighbour, double precision maxerr=0.125);

    描述

    使用一个指定的重采样算法、新维度参数(width和height)和任意一个网格角点(由参数gridx和gridy指定)和一个栅格空间参考属性((scalex,scaley, skewx & skewy) 或引用其他栅格属性来重采样一个栅格。 如果使用一个参考空间栅格,那么两个栅格必须拥有相同的SRID。

    新的像素值会使用NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。 默认的是NearestNeighbor算法,这个算法是最快的,但会产生最多的插值错误。如果没有指定maxerror,默认参数maxwhich值为0.125。

    注意

    参考 GDAL Warp resampling methods(http://www.gdal.org/gdalwarp.html)获取更多信息.

    参数SRID被移除了。带有引用参考栅格的函数变体不再使永引用栅格的SRID值,使用ST_Transform()来重投影栅格。 该函数支持无SRID的栅格。

    样例

    SELECT
    ST_Width(orig) AS orig_width,
    ST_Width(reduce_100) AS new_width
    FROM ( SELECT
    rast AS orig,
    ST_Resample(rast,100,100) AS reduce_100FROM aerials.boston WHERE
    ST_Intersects(rast,
    ST_Transform(
    ST_MakeEnvelope(-71.128, 42.2392,-71.1277, 42.2397, 4326),26986)
    )
    LIMIT 1
    ) AS foo;
    
    orig_width | new_width
    -----------+-------------
    200        | 100

    参考

    ST_Rescale, ST_Transform

    8.7.8. ST_Rescale

    ST_Rescale —重采样一个栅格,只调整像素的大小,新的像素值会使用 NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。 默认的是NearestNeighbor算法。

    用法

    raster ST_Rescale(raster rast, double precision scalexy,
       text algorithm=NearestNeighbour, double precision maxerr=0.125);
    raster ST_Rescale(raster rast, double precision scalex, double precision scaley,
       text algorithm=NearestNeighbour, double precision maxerr=0.125);

    描述

    重采样一个栅格,只调整像素的大小,新的像素值会使用NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。 默认的是NearestNeighbor算法,这个算法是最快的,但会产生最多的插值错误。

    参数scalex 和参数scaley定义一个新像素的size(大小)。scaley必须要减小以便适应原始栅格的边界。

    如果像素新的参数scalex 和scaley值不是栅格宽度和高度的因子(比如15的因子是1,3,5),那么函数返回的栅格的边界会扩展包围提供的栅格。

    如果没有指定maxerror,默认参数maxwhich值为0.125。

    注意

    参考: GDAL Warp resampling methods获取更多信息。

    注意

    函数ST_Rescale与函数ST_SetScale不同的地方是函数ST_SetScale不对栅格重采样以便适应原始栅格的边界。

    函数ST_SetScale值改变栅格的元数据信息(或者地理参考)纠正原有的缩放。

    函数ST_Rescale生成一个栅格,该栅格有不同的宽度和高度来适应输入栅格的边界。

    函数ST_SetScale不修改栅格的宽度和高度。

    样例

    -- A simple example rescaling a raster from a pixel
    -- size of 0.001 degree to a pixel size of 0.0015 degree.
    -- the original raster pixel size
    SELECT ST_PixelWidth(ST_AddBand(ST_MakeEmptyRaster(100, 100, 0, 0, 0.001, -0.001, 0, 0,
    4269), '8BUI'::text, 1, 0)) width;
    
    width
    ----------
    0.001
    
    -- the rescaled raster raster pixel size
    SELECT ST_PixelWidth(ST_Rescale(ST_AddBand(ST_MakeEmptyRaster(100, 100, 0, 0, 0.001,
    -0.001, 0, 0, 4269), '8BUI'::text, 1, 0), 0.0015)) width;
    
    width
    ----------
    0.0015

    参考

    ST_SetScale, ST_ScaleX, ST_ScaleY, ST_Resample, ST_Transform

    8.7.9. ST_Reskew

    ST_Reskew —重采样一个栅格,只调整像素的skew(或者说旋转参数),新的像素值会使用NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。 默认的是NearestNeighbor算法。

    用法

    raster ST_Reskew(raster rast, double precision skewxy,
       text algorithm=NearestNeighbour, double precision maxerr=0.125);
    raster ST_Reskew(raster rast, double precision skewx, double precision skewy,
       text algorithm=NearestNeighbour, double preci-sion maxerr=0.125);

    描述

    重采样一个栅格,只调整像素的skew(或者说旋转参数),新的像素值会使用NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。

    默认的是NearestNeighbor算法,这个算法是最快的,但会产生最多的插值错误。

    参数skewx和参数skewy定义了新栅格的skew(倾斜度)。

    新栅格的边界会提供的栅格边界相遇(即相交)。

    如果没有指定maxerror,默认参数maxwhich值为0.125。

    注意

    参考 GDAL Warp resampling methods(http://www.gdal.org/gdalwarp.html)获取更多信息。

    注意

    函数ST_Reskew与函数ST_SetSkew不同的地方是函数ST_SetSkew不对栅格重采样以便适应原始栅格的边界。

    函数ST_SetSkew值改变栅格的元数据信息(或者地理参考)来纠正原有的倾斜度。

    函数ST_Reskew生成一个栅格,该栅格有不同的宽度和高度来适应输入栅格的边界。

    函数ST_SetSkew不修改栅格的宽度和高度。

    样例

    -- A simple example reskewing a raster from a skew of 0.0 to a skew of 0.0015.
    -- the original raster pixel size
    SELECT ST_Rotation(ST_AddBand(ST_MakeEmptyRaster(100, 100, 0, 0, 0.001, -0.001, 0, 0, 4269) , '8BUI'::text, 1, 0));
    
     st_rotation
    -------------
             0
    (1 row)
    
    
    -- the rescaled raster raster pixel size
    SELECT ST_Rotation(ST_Reskew(ST_AddBand(ST_MakeEmptyRaster(100, 100, 0, 0, 0.001, -0.001,  0, 0, 4269), '8BUI'::text, 1, 0), 0.0015));
    
       st_rotation
    ---------------------
    -0.9827937232473289
    (1 row)

    参考

    ST_Resample, ST_Rescale, ST_SetSkew, ST_SetRotation, ST_SkewX, ST_SkewY, ST_Transform

    8.7.10. ST_SnapToGrid

    ST_SnapToGrid —重采样一个栅格,方法是把栅格分割成由任意一个角点像素(gridx & gridy)和可选的像素大小(scalex和scaley)定义的网格。 新的像素值会使用NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。 默认的是NearestNeighbor算法。

    用法

    raster ST_SnapToGrid(raster rast, double precision gridx, double precision gridy,
       text algorithm=NearestNeighbour, doubleprecision maxerr=0.125,
       double precision scalex=DEFAULT 0, double precision scaley=DEFAULT 0);
    raster ST_SnapToGrid(raster rast, double precision gridx, double precision gridy,
       double precision scalex, double precisionscaley,
       text algorithm=NearestNeighbour, double precision maxerr=0.125);
    raster ST_SnapToGrid(raster rast, double precision gridx, double precision gridy,
       double precision scalexy,
       text algorithm=NearestNeigh double precision maxerr=0.125);

    描述

    重采样一个栅格,方法是把栅格分割成由任意一个角点像素(gridx & gridy)和可选的像素大小(scalex和scaley)定义的网格。 新的像素值会使用NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。 默认的是NearestNeighbor算法,这个算法是最快的,但会产生最多的插值错误。

    参数gridx和参数gridy定义了新网格的任意角点。这对新栅格的左上角点不是必须的参数。角点也不必在新栅格边界里面或者边上。可以选择性定义新网格的像素size(即通过参数scalex和scaley)。

    新栅格的边界会提供的栅格边界相遇(即相交)。

    如果没有指定maxerror,默认参数maxwhich值为0.125。

    注意

    参考 GDAL Warp resampling methods(http://www.gdal.org/gdalwarp.html)获取更多信息。

    注意

    如果想控制更多关于栅格参数的使用,请使用函数ST_Resample。

    样例

    -- A simple example snapping a raster to a slightly different grid.
    -- the original raster pixel size
    SELECT ST_UpperLeftX(ST_AddBand(ST_MakeEmptyRaster(10, 10, 0, 0, 0.001, -0.001, 0, 0, 4269)  , '8BUI'::text, 1, 0));
    
     st_upperleftx
    ---------------
                0
    (1 row)
    
    
    -- the rescaled raster raster pixel size
    SELECT ST_UpperLeftX(ST_SnapToGrid(ST_AddBand(ST_MakeEmptyRaster(10, 10, 0, 0, 0.001, -0.001, 0, 0, 4269), '8BUI'::text, 1, 0), 0.0002, 0.0002));
    
     st_upperleftx
    ---------------
          -0.0008
    (1 row)

    参考

    ST_Resample, ST_Rescale, ST_UpperLeftX, ST_UpperLeftY

    8.7.11. ST_Resize

    ST_Resize —重新设定栅格的高度和宽度。

    用法

    raster ST_Resize(raster rast, integer width, integer height,
       text algorithm=NearestNeighbor, double precision maxerr=0.125);
    raster ST_Resize(raster rast,
       double precision percentwidth, double precision percentheight,
       text algorithm=NearestNeighbor,double precision maxerr=0.125);
    raster ST_Resize(raster rast, text width, text height,
       text algorithm=NearestNeighbor, double precision maxerr=0.125);

    描述

    重新设定栅格的高度和宽度。新的宽度和高度可以设定为像元的个数或者原栅格的高度和宽度的百分比。

    新的像素值会使用 NearestNeighbor、Bilinear、Cubic、CubicSpline 或 Lanczos 重采样算法来进行计算。 默认的是NearestNeighbor算法,这个算法是最快的,但会产生最多的插值错误。

    函数变体1需要输出栅格的实际参数width和参数height函数变体2需要表示占有输入栅格的width和height比例的decimal值,范围在0到1之间。

    函数变体3需要输出栅格的实际参数width和参数height值或者表示占有输入栅格的width和height比例的decimal值,范围在0到1之间。

    样例

    WITH foo AS(
    SELECT
    1 AS rid,
    ST_Resize(
    ST_AddBand(
    ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0)
    , 1, '8BUI', 255, 0
    )
    , '50%', '500') AS rast
    UNION ALL
    SELECT
    2 AS rid,
    ST_Resize(
    ST_AddBand(
    ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0)
    , 1, '8BUI', 255, 0
    )
    , 500, 100) AS rast
    UNION ALL
    SELECT
    3 AS rid,
    ST_Resize(
    ST_AddBand(
    ST_MakeEmptyRaster(1000, 1000, 0, 0, 1, -1, 0, 0, 0)
    , 1, '8BUI', 255, 0
    )
    , 0.25, 0.9) AS rast
    ), bar AS (
    SELECT rid, ST_Metadata(rast) AS meta, rast
    )
    SELECT rid, (meta).* FROM bar
    FROM foo
    
    rid|upperleftx| upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
    ---+----------+------------+-------+--------+--------+--------+-------+-------+------+----------
    1  | 0        | 0          | 500   | 500    | 1      | -1     | 0     | 0     | 0    | 1
    2  | 0        | 0          | 500   | 100    | 1      | -1     | 0     | 0     | 0    | 1
    3  | 0        | 0          | 250   | 900    | 1      | -1     | 0     | 0     | 0    | 1
    (3 rows)

    参考

    ST_Resample, ST_Rescale, ST_Reskew, ST_SnapToGrid

    8.7.12. ST_Transform

    ST_Transform—根据给定的投影算法,将一个栅格的一种空间参考系转换到另一个空间参考系中。 提供的投影算法有NearestNeighbor、Bilinear、Cubic、CubicSpline、Lanczos,默认是NearestNeighbor算法。

    用法

    raster ST_Transform(raster rast, integer srid,
       text algorithm=NearestNeighbor,
       double precision maxerr=0.125, double precisionscalex, double precision scaley);
    raster ST_Transform(raster rast, integer srid,
       double precision scalex, double precision scaley,
       text algorithm=NearestNeighbor,double precision maxerr=0.125);
    raster ST_Transform(raster rast, raster alignto,
       text algorithm=NearestNeighbor, double precision maxerr=0.125);

    描述

    通过指定的像素变形算法把一个栅格从一个已知的空间参考系变换到另一个已知的空间参考系。 如果没有指定算法,那么使用算法’NearestNeighbor’,如果没有指定参数maxerr,那么默认使用参数0.125。 可选的算法有:NearestNeighbor、Bilinear、Cubic、CubicSpline 和 Lanczos。参考GDAL Warp resamplingmethods获取更多细节。

    函数ST_Transform进程会和函数ST_SetSRID()弄混淆。 实际上函数ST_Transform只把栅格的坐标从一个参考系转换成另一个参考系下的坐标(同时也重采样栅格的值),而函数ST_SetSRID()值修改栅格的SRID值。 与其他函数变体不同,函数变体3需要一个用于对齐的引用栅格即参数alignto表示的栅格。 被转换的栅格将会被转换到引用栅格的所在的空间参考系下(SRID值一致),并且对齐方式也和引用栅格的对齐方式一致(通过参数ST_SameAlignment = TRUE控制)。

    样例

    SELECT ST_Width(mass_stm) As w_before, ST_Width(wgs_84) As w_after,
    ST_Height(mass_stm) As h_before, ST_Height(wgs_84) As h_after
    FROM
    ( SELECT rast As mass_stm, ST_Transform(rast,4326) As wgs_84
    , ST_Transform(rast,4326, 'Bilinear') AS wgs_84_bilin
    FROM aerials.o_2_boston WHERE ST_Intersects(rast,
    ST_Transform(ST_MakeEnvelope(-71.128, 42.2392,-71.1277, 42.2397,
    4326),26986) )
    LIMIT 1) As foo;
    
    w_before  | w_after | h_before |h_after
    ----------+---------+----------+---------
    200       | 228     | 200      | 170

    正在上传…重新上传取消

    样例 : Variant 1

    -- The following shows the difference between
    -- using ST_Transform(raster, srid) and ST_Transform(raster, alignto)
    WITH foo AS (
    SELECT 0 AS rid, ST_AddBand(ST_MakeEmptyRaster(2, 2, -500000, 600000, 100, -100, 0, 0, 2163), 1, '16BUI', 1, 0) AS rast UNION ALL
    SELECT 1, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499800, 600000, 100, -100, 0, 0, 2163), 1, '16BUI', 2, 0) AS rast UNION ALL
    SELECT 2, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499600, 600000, 100, -100, 0, 0, 2163), 1, '16BUI', 3, 0) AS rast UNION ALL
    SELECT 3, ST_AddBand(ST_MakeEmptyRaster(2, 2, -500000, 599800, 100, -100, 0, 0, 2163), 1, '16BUI', 10, 0) AS rast UNION ALL
    SELECT 4, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499800, 599800, 100, -100, 0, 0, 2163), 1, '16BUI', 20, 0) AS rast UNION ALL
    SELECT 5, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499600, 599800, 100, -100, 0, 0, 2163), 1, '16BUI', 30, 0) AS rast UNION ALL
    SELECT 6, ST_AddBand(ST_MakeEmptyRaster(2, 2, -500000, 599600, 100, -100, 0, 0, 2163), 1, '16BUI', 100, 0) AS rast UNION ALL
    SELECT 7, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499800, 599600, 100, -100, 0, 0, 2163), 1, '16BUI', 200, 0) AS rast UNION ALL
    SELECT 8, ST_AddBand(ST_MakeEmptyRaster(2, 2, -499600, 599600, 100, -100, 0, 0, 2163), 1, '16BUI', 300, 0) AS rast
    ), bar AS ( SELECT
    ST_Transform(rast, 4269) AS alignto
    FROM fooLIMIT 1
    ), baz AS (
    SELECT
    rid,
    rast,
    ST_Transform(rast, 4269) AS not_aligned,
    ST_Transform(rast, alignto) AS aligned
    FROM foo
    CROSS JOIN bar
    )
    SELECT
    ST_SameAlignment(rast) AS rast,
    ST_SameAlignment(not_aligned) AS not_aligned,
    ST_SameAlignment(aligned) AS aligned
    FROM baz;
    
    rast  | not_aligned | aligned
    ------+-------------+---------
    t     | f           | t

    参考

    ST_Transform, ST_SetSRID

    8.8. 栅格波段编辑函数

    8.8.1. ST_SetBandNoDataValue

    ST_SetBandNoDataValue —把给定的波段设置为NODATA值,如果没有指定波段,则默认波段1。要标记一个波段没有NODATA值,把NODTA值设置为NULL。

    用法

    raster ST_SetBandNoDataValue(raster rast, double precision nodatavalue);
    raster ST_SetBandNoDataValue(raster rast, integer band,
       double precision nodatavalue, boolean forcechecking=false);

    描述

    把给定的波段设置为NODATA值,如果没有指定波段,则默认波段1。 这会影响函数ST_Polygon,ST_DumpAsPolygons,和ST_PixelAs...()这一类函数的结果。

    样例

    -- change just first band no data value
    UPDATE dummy_rast
    SET rast = ST_SetBandNoDataValue(rast,1, 254)
    WHERE rid = 2;
    
    -- change no data band value of bands 1,2,3
    UPDATE dummy_rast
    SET rast =
    ST_SetBandNoDataValue( ST_SetBandNoDataValue(
    ST_SetBandNoDataValue( rast,1, 254)
    ,2,99),
    3,108)
    WHERE rid = 2;
    
    -- wipe out the nodata value this will ensure
    -- all pixels are considered for all processing functions
    UPDATE dummy_rast
    SET rast = ST_SetBandNoDataValue(rast,1, NULL)
    WHERE rid = 2;

    参考

    ST_BandNoDataValue, ST_NumBands

    8.8.2. ST_SetBandIsNoData

    ST_SetBandIsNoData —把波段的isnodata标识未TRUE。

    用法

    raster ST_SetBandIsNoData(raster rast, integer band=1);

    描述

    把波段的isnodata标识未TRUE。如果没有指定波段,则默认为波段1。 该函数只有在flag被认为损坏的情况下才应该调用。 flag被损坏的意思是调用函数ST_BandIsNoData的最后一个参数值TRUE的结果和不传递该参数值的结果不同,则认为flag被损坏了。

    样例

    -- Create dummy table with one raster column
    create table dummy_rast (rid integer, rast raster);
    
    -- Add raster with two bands, one pixel/band. In the first band,
    -- nodatavalue = pixel value = 3.
    -- In the second band, nodatavalue = 13, pixel value = 4
    insert into dummy_rast values(1,
    (
    '01' -- little endian (uint8 ndr)
    ||
    '0000' -- version (uint16 0)
    ||
    '0200' -- nBands (uint16 0)
    ||
    '17263529ED684A3F' -- scaleX (float64 0.000805965234044584)
    ||
    'F9253529ED684ABF' -- scaleY (float64 -0.00080596523404458)
    ||
    '1C9F33CE69E352C0' -- ipX (float64 -75.5533328537098)
    ||
    '718F0E9A27A44840' -- ipY (float64 49.2824585505576)
    ||
    'ED50EB853EC32B3F' -- skewX (float64 0.000211812383858707)
    ||
    '7550EB853EC32B3F' -- skewY (float64 0.000211812383858704)
    ||
    'E6100000' -- SRID (int32 4326)
    ||
    '0100' -- width (uint16 1)
    ||
    '0100' -- height (uint16 1)
    ||
    '4' -- hasnodatavalue set to true, isnodata value set to false (when it should be true)
    ||
    '2' -- first band type (4BUI)
    ||
    '03' -- novalue==3
    ||
    '03' -- pixel(0,0)==3 (same that nodata)
    ||
    '0' -- hasnodatavalue set to false
    ||
    '5' -- second band type (16BSI)
    ||
    '0D00' -- novalue==13
    ||
    '0400' -- pixel(0,0)==4
    )::raster
    );
    
    select st_bandisnodata(rast, 1) from dummy_rast where rid = 1; -- Expected false
    
     st_bandisnodata
    -----------------
    f
    (1 row)
    
    select st_bandisnodata(rast, 1, TRUE) from dummy_rast where rid = 1; -- Expected true
    
     st_bandisnodata
    -----------------
    t
    (1 row)
    
    
    -- The isnodata flag is dirty. We are going to set it to true
    update dummy_rast set rast = st_setbandisnodata(rast, 1) where rid = 1;
    
    select st_bandisnodata(rast, 1) from dummy_rast where rid = 1; -- Expected true
    
     st_bandisnodata
    -----------------
    t
    (1 row)

    参考

    ST_BandNoDataValue, ST_NumBands, ST_SetBandNoDataValue, ST_BandIsNoData

  • 相关阅读:
    Tensor、Numpy、PIL格式转换以及图像显示
    企业服务器租用对性能有什么要求呢?
    买卖股票的最佳时机
    SpringMvc--综合案例
    打破数据孤岛,开启新篇章
    node版本管理工具nvm
    【数据结构】哈希应用——位图、布隆过滤器
    SpringAMQP之队列和交换机
    BiDi光纤通过哪些方式增强宽带传输能力?
    观点|周鸿祎:大模型真正的竞争在于使其与用户场景相结合
  • 原文地址:https://blog.csdn.net/arthemis_14/article/details/126346310