Professional Documents
Culture Documents
บทนํา
ขอมูลแบบจําลองภูมิประเทศ เปนอีกสิ่งทีม่ ีความสําคัญ ในการนํามาใชในการดัดแกภาพ
ออรโท และสามารถนํามาใชประมวลผลดานตางๆในระบบภูมิสารสนเทศ โดยขอมูลจะถูกจัดเก็บ
ในรูปแบบราสเตอรไฟล คลายกับภาพถายดาวเทียมแตมีแค Band เดียวโดยเก็บในรูปแบบ Floating
ที่มีขนาดใหญครอบคลุมกับระดับคาความสูงที่บรรจุใน Digital Number
วัตถุประสงค
1. เรียนรูการเขาถึงคา Digital Value จาก THEOS ดวย Python
2. ศึกษาการจัดการขอมูลเชิงคลื่น ในภาพถายดาวเทียม
วิธีการ
ทดลองเขียนโปรแกรมดังตอไปนี้
# เรียกโมดูลทีต่ องการเพื่อใชงาน
import os
import sys
from osgeo import gdal
import string
import math
# ทดลองใช Alias name
import numpy as Numeric
dataset = gdal.Open("C:\data\image\ASTGTM_N15E099_dem.tif")
R=1
print "Python Code for SRTM DEM Acessing"
#เขาถึงขอมูลไฟล GDEM
# ตรวสอบ Band และชั้นขอมูลราสเตอร
image_count=dataset.RasterCount
# ตรวจสอบขนาด Pixelsize
image_x_size=dataset.RasterXSize
image_y_size=dataset.RasterYSize
#เขาถึงระบบพิกัดอางอิง
image_CRS=dataset.GetGeoTransform()
image_proj=dataset.GetGCPProjection()
print "image size is ",image_x_size,'*',image_y_size
# เขาถึงขอมูล Digital Value
array = dataset.ReadAsArray()
band = dataset.GetRasterBand(1)
print 'Band Type=',gdal.GetDataTypeName(band.DataType)
min = band.GetMinimum()
max = band.GetMaximum()
#คํานวณคาสถิติของ GDEM
if min is None or max is None:(min,max) = band.ComputeRasterMinMax(1)
print 'Min=%.3f, Max=%.3f' % (min,max)
# Loop เขาหาคา DN
for iBand in range(1, dataset.RasterCount + 1):
inband = dataset.GetRasterBand(iBand)
#print inband.YSize
for i in range(inband.YSize - 1, -1, -1):
scanline = inband.ReadAsArray(0, i, inband.XSize, 1, inband.XSize, 1)
scanline = Numeric.choose(Numeric.equal( scanline, 999),(scanline, 000) )
#print 'line ',scanline, 0, i
#ทําการจัดตัวคาพิกัดอางอิง
geoTrans = dataset.GetGeoTransform()
cellSizeX = geoTrans[1]
cellSizeY = geoTrans[5]
nXSize = dataset.RasterXSize
nYSize = dataset.RasterYSize
print 'Cell Size',cellSizeX,cellSizeY
cx=1
cy=1
dem=band.ReadAsArray(0, cx , cy, 1) # Acess Dem Value
arr=len(dem) # check number of rows
arc=len(dem[0]) # check number of columns
print 'cx,cy,value :',cx,cy,dem[0,0]
inGridBand=dataset.GetRasterBand(1)
buff = inGridBand.ReadAsArray(xoff=0, yoff=0, win_xsize=nXSize,win_ysize=1)
# create distance array
dist=Numeric.zeros((winSize,winSize),float)
#print dist.size
for i in range(winSize):
for j in range(winSize):
dist[i][j]=Numeric.sqrt((cellSizeX*(i-R))**2 +
(cellSizeY*(j-R))**2)
#print dist