GISarabia.org
PostGIS › الدليل الرسمي › 11. مرجع الرستر › 11.3. منشئات الرستر
PostGIS 3.6 · Official Manual · ترجمة عربية

ST_AddBand

الصفحة الأصلية بالإنجليزية postgis.net ↗

الاسم

ST_AddBand — تُعيد رسترًا أُضيف إليه نطاق (أو نطاقات) جديد من النوع المحدد بالقيمة الأولية المحددة في موضع الفهرس المحدد. إذا لم يُحدَّد فهرس، يُضاف النطاق في النهاية.

المختصر

(1) raster ST_AddBand(raster rast, addbandarg[] addbandargset);

(2) raster ST_AddBand(raster rast, integer index, text pixeltype, double precision initialvalue=0, double precision nodataval=NULL);

(3) raster ST_AddBand(raster rast, text pixeltype, double precision initialvalue=0, double precision nodataval=NULL);

(4) raster ST_AddBand(raster torast, raster fromrast, integer fromband=1, integer torastindex=at_end);

(5) raster ST_AddBand(raster torast, raster[] fromrasts, integer fromband=1, integer torastindex=at_end);

(6) raster ST_AddBand(raster rast, integer index, text outdbfile, integer[] outdbindex, double precision nodataval=NULL);

(7) raster ST_AddBand(raster rast, text outdbfile, integer[] outdbindex, integer index=at_end, double precision nodataval=NULL);

الوصف

تُعيد رسترًا أُضيف إليه نطاق جديد في الموضع (الفهرس) المحدد، من النوع المحدد، بالقيمة الأولية المحددة، وبقيمة nodata المحددة. إذا لم يُحدَّد فهرس، يُضاف النطاق في النهاية. وإذا لم يُحدَّد fromband، يُفترض النطاق 1. نوع البكسل تمثيل نصي لأحد أنواع البكسل المحددة في ST_BandPixelType. إذا حُدّد فهرس موجود، تُزاد فهارس جميع النطاقات اللاحقة >= ذلك الفهرس بمقدار 1. وإذا حُدّدت قيمة أولية أكبر من الحد الأقصى لنوع البكسل، تُضبط القيمة الأولية على أعلى قيمة يسمح بها نوع البكسل.

في الصيغة التي تأخذ مصفوفة من addbandarg (الصيغة 1)، تكون قيمة الفهرس في addbandarg معيّن نسبيةً إلى الرستر في اللحظة التي يُضاف فيها النطاق الموصوف بذلك addbandarg إلى الرستر. انظر مثال النطاقات الجديدة المتعددة أدناه.

في الصيغة التي تأخذ مصفوفة من الرسترات (الصيغة 5)، إذا كانت torast تساوي NULL، يُجمَّع النطاق fromband من كل رستر في المصفوفة في رستر جديد.

في الصيغ التي تأخذ outdbfile (الصيغتان 6 و7)، يجب أن تتضمن القيمة المسار الكامل لملف الرستر. ويجب أن يكون الملف أيضًا قابلًا للوصول من عملية خادم postgres.

حُسّنت في: 2.1.0 أُضيف دعم addbandarg.

حُسّنت في: 2.1.0 أُضيف دعم النطاقات الجديدة المخزّنة خارج قاعدة البيانات (out-db).

أمثلة: نطاق جديد واحد

-- Add another band of type 8 bit unsigned integer with pixels initialized to 200
UPDATE dummy_rast
    SET rast = ST_AddBand(rast,'8BUI'::text,200)
WHERE rid = 1;
                
-- Create an empty raster 100x100 units, with upper left  right at 0, add 2 bands (band 1 is 0/1 boolean bit switch, band2 allows values 0-15)
-- uses addbandargs
INSERT INTO dummy_rast(rid,rast)
    VALUES(10, ST_AddBand(ST_MakeEmptyRaster(100, 100, 0, 0, 1, -1, 0, 0, 0),
    ARRAY[
        ROW(1, '1BB'::text, 0, NULL),
        ROW(2, '4BUI'::text, 0, NULL)
            ]::addbandarg[]
     )
    );

-- output meta data of raster bands to verify all is right --
SELECT  (bmd).*
FROM (SELECT ST_BandMetaData(rast,generate_series(1,2)) As bmd
    FROM dummy_rast WHERE rid = 10) AS foo;
 --result --
 pixeltype | nodatavalue | isoutdb | path
-----------+----------------+-------------+---------+------
 1BB       |             | f       |
 4BUI      |             | f       |


-- output meta data of raster -
SELECT  (rmd).width, (rmd).height, (rmd).numbands
FROM (SELECT ST_MetaData(rast) As rmd
    FROM dummy_rast WHERE rid = 10) AS foo;
-- result --
 upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
------------+------------+-------+--------+------------+------------+-------+-------+------+----------
          0 |          0 |   100 |    100 |      1 |     -1 |     0 |     0 |   0 |        2
                

أمثلة: نطاقات جديدة متعددة

SELECT
    *
FROM ST_BandMetadata(
    ST_AddBand(
        ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0),
        ARRAY[
            ROW(NULL, '8BUI', 255, 0),
            ROW(NULL, '16BUI', 1, 2),
            ROW(2, '32BUI', 100, 12),
            ROW(2, '32BF', 3.14, -1)
        ]::addbandarg[]
    ),
    ARRAY[]::integer[]
);

 bandnum | pixeltype | nodatavalue | isoutdb | path
---------+-----------+-------------+---------+------
       1 | 8BUI      |           0 | f       |
       2 | 32BF      |          -1 | f       |
       3 | 32BUI     |          12 | f       |
       4 | 16BUI     |           2 | f       |
                
-- Aggregate the 1st band of a table of like rasters into a single raster
-- with as many bands as there are test_types and as many rows (new rasters) as there are mice
-- NOTE: The ORDER BY test_type is only supported in PostgreSQL 9.0+
-- for 8.4 and below it usually works to order your data in a subselect (but not guaranteed)
-- The resulting raster will have a band for each test_type alphabetical by test_type
-- For mouse lovers: No mice were harmed in this exercise
SELECT
    mouse,
    ST_AddBand(NULL, array_agg(rast ORDER BY test_type), 1) As rast
FROM mice_studies
GROUP BY mouse;
                

أمثلة: نطاق جديد خارج قاعدة البيانات (out-db)

SELECT
    *
FROM ST_BandMetadata(
    ST_AddBand(
        ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0),
        '/home/raster/mytestraster.tif'::text, NULL::int[]
    ),
    ARRAY[]::integer[]
);

 bandnum | pixeltype | nodatavalue | isoutdb | path
---------+-----------+-------------+---------+------
       1 | 8BUI      |             | t       | /home/raster/mytestraster.tif
       2 | 8BUI      |             | t       | /home/raster/mytestraster.tif
       3 | 8BUI      |             | t       | /home/raster/mytestraster.tif