코드조각 저장소

PostGIS Raster Reference 본문

Programing/GIS &

PostGIS Raster Reference

basic 2021. 5. 14. 08:37

PostgreSQL + PostGIS 환경에서 래스터 자료에 대한 함수들을 테스트하면서 결과를 정리해 보았습니다.

래스터 자료 구성이 크게는 두가지로 나눌 수 있는것 같습니다.

 1.픽셀 정보 : 크기, 위치( 파일, 데이터 셋 메타데이터 기준 Row, Column[X,Y]

 2. Band : Value (Multi, Band1, Band2, ...)

https://postgis.net/docs/RT_reference.html

 

Chapter 6. Raster Reference

6.18.1.1. Directory containing many files When GDAL opens a file, GDAL eagerly scans the directory of that file to build a catalog of other files. If this directory contains many files (e.g. thousands, millions), opening that file becomes extremely slow (

postgis.net

 PostGIS에 제공하는 래스터 관련 함수들은 보통 두가지의 정보를 제어, 사용 할 수 있게 해줍니다. 이번에 테스트 한 함수들은 간단히 래스터 생성과 픽셀데이터를 다루는 함수들로 진행해 보았습니다.

Param Set
geometry geom, 
integer width, integer height, (픽셀 개수: 1000 * 1000의 픽셀로 이미지 만들기, resolution) 
text[] pixeltype, 
double precision[] value=ARRAY[1], 
double precision[] nodataval=ARRAY[0]

ST_AsRaster(
    ST_Buffer(ST_GeomFromText('LINESTRING(50 50,250 250,250 50)'), 10,'join=bevel')
    ,1000,1000
    ,ARRAY['8BUI', '8BUI', '8BUI’]
    , ARRAY[118,154,118]
    , ARRAY[0,0,0])
) as bfgeom

 

생성한 래스터의 픽셀에 관련한 함수들 입니다.

ST_PixelAsPoints — Returns a point geometry for each pixel of a raster band along with the value, the X and the Y raster coordinates of each pixel. The coordinates of the point geometry are of the pixel's upper-left corner.

ST_PixelAsCentroids — Returns the centroid (point geometry) for each pixel of a raster band along with the value, the X and the Y raster coordinates of each pixel. The point geometry is the centroid of the area represented by a pixel.

ST_PixelAsPolygons — Returns the polygon geometry that bounds every pixel of a raster band along with the value, the X and the Y raster coordinates of each pixel.

ST_DumpAsPolygons — Returns a set of geomval (geom,val) rows, from a given raster band. If no band number is specified, band num defaults to 1.

래스터 밴드의 함수들도 제공합니다만 이번에는 정사영상 래스터에서 위치와 색상정보를 출출하는 테스트를 진행해 보았습니다.

--- Get all values in bands 1,2,3 of each pixel --
SELECT x, y, ST_Value(rast, 1, x, y) As b1val,
	ST_Value(rast, 2, x, y) As b2val, ST_Value(rast, 3, x, y) As b3val
FROM dummy_rast CROSS JOIN
generate_series(1, 1000) As x CROSS JOIN generate_series(1, 1000) As y
WHERE rid =  2 AND x <= ST_Width(rast) AND y <= ST_Height(rast);

 x | y | b1val | b2val | b3val
---+---+-------+-------+-------
 1 | 1 |   253 |    78 |    70
 1 | 2 |   253 |    96 |    80
 1 | 3 |   250 |    99 |    90
 1 | 4 |   251 |    89 |    77
 1 | 5 |   252 |    79 |    62
 2 | 1 |   254 |    98 |    86
 2 | 2 |   254 |   118 |   108
 :

추가적인 내용은 이전 글을 참고하시기 바랍니다.

https://t2ols.tistory.com/24

 

정사영상 + Elevation + TIN -> RGB PointCloud

작성한 다른 글에서 사용하려고 테스트 데이터를 만드는 과정을 해결하여 정리해 봅니다. 사용하는 데이터셋은 비슷합니다만 GDAL만으로 처리하기에는 실력 부족으로 막혔던 부분을 데이터베이

t2ols.tistory.com

 

Comments