hoony's web study

728x90
반응형

이전 자료하고는 조금 버전업된 코드 공유해드려요.

python에서 tiff metadata 추출 source 공유해드려요.

import os
from osgeo import gdal
filename = "C:\\temo\\"
# raster = gdal.Open(filename)

for x in os.listdir(filename):
      if '.tif' in x:
        print('-----input : ' + (x) + '-----')
        raster = gdal.Open(filename + (x))
        
        # Projection
        # print(raster.GetProjection())
        Projection = "Projection : EPSG5179"

        # Dimensions
        RasterColumCount = raster.RasterXSize
        XCol = "XColumCount : " + str(RasterColumCount)
        RasterRowCount = raster.RasterYSize
        YRow = "YRowCount : " + str(RasterRowCount)

        # Number of bands
        Band = "Bands : " + str(raster.RasterCount)

        # Cell Information
        CellI = raster.GetGeoTransform()
        # print(CellI) 
        pixelSizeX = CellI[1]
        pixelSizeY = -CellI[5]
        pixelX = "pixelSizeX : " + str(pixelSizeX*100)
        pixelY = "pixelSizeY : " + str(pixelSizeY*100)

        # Extent
        ExtentTOP = CellI[3]
        ExtentLeft = CellI[0]
        TOP = "TOP : " + str(ExtentTOP)
        LEFT = "Left : " + str(ExtentLeft)
        ExtentRight = ExtentLeft + (RasterColumCount * pixelSizeY)
        RIGHT = "Right : " + str(ExtentRight)
        ExtentBottom = ExtentTOP - (RasterRowCount * pixelSizeX)
        BOTTOM = "Bottom : " + str(ExtentBottom)
        with open(filename + 'OrthoMeta.txt', "a") as f:
         f.write( Projection+" "+XCol+" "+YRow+" "+Band+" "+pixelX+" "+pixelY+" "+TOP+" "+LEFT + RIGHT + BOTTOM + '\n' )

tiff metadata 추출

728x90

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading