-
Notifications
You must be signed in to change notification settings - Fork 3
/
OssimPython.py
161 lines (143 loc) · 6.56 KB
/
OssimPython.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python
import platform
import os
import subprocess
from osgeo import gdal
home = os.environ.get('HOME')
PathToOssimPreference = home+str('/ossim_preferences')
#PathToGdalGrass = str('/Users/Shared/source/grass7/distLEO/')
def WhichPlatform():
global platform
platforms = platform.system()
return platforms
def OssimImg2rr(img1,output):
myenv = os.environ.copy()
systemplatform = WhichPlatform()
if systemplatform == 'Darwin':
PathToExecutable = str('/var/tmp/XcodeBuilds/Release/')
myenv['DYLD_FRAMEWORK_PATH'] = PathToExecutable
#myenv['GDAL_DRIVER_PATH'] = PathToGdalGrass
else :
PathToExecutable = str('/usr/local/bin/')
myenv['OSSIM_PREFS_FILE'] = PathToOssimPreference
output = subprocess.Popen([PathToExecutable+'ossim-img2rr' ,str(img1), '-o', str(output)], stdout=subprocess.PIPE, env = myenv).communicate()[0]
def OssimCreateHisto(img1,output):
myenv = os.environ.copy()
systemplatform = WhichPlatform()
if systemplatform == 'Darwin':
PathToExecutable = str('/var/tmp/XcodeBuilds/Release/')
myenv['DYLD_FRAMEWORK_PATH'] = PathToExecutable
#myenv['GDAL_DRIVER_PATH'] = PathToGdalGrass
else :
PathToExecutable = str('/usr/local/bin/')
myenv['OSSIM_PREFS_FILE'] = PathToOssimPreference
output = subprocess.Popen([PathToExecutable+'ossim-create-histo' ,str(img1), '-o', str(output)], stdout=subprocess.PIPE, env = myenv).communicate()[0]
def OssimImageInfo(band1):
myenv = os.environ.copy()
systemplatform = WhichPlatform()
if systemplatform == 'Darwin':
PathToExecutable = str('/var/tmp/XcodeBuilds/Release/')
myenv['DYLD_FRAMEWORK_PATH'] = PathToExecutable
#myenv['GDAL_DRIVER_PATH'] = PathToGdalGrass
else :
PathToExecutable = str('/usr/local/bin/')
myenv['OSSIM_PREFS_FILE'] = PathToOssimPreference
output = subprocess.Popen([PathToExecutable+'ossim-info' ,str(band1)], stdout=subprocess.PIPE, env = myenv).communicate()[0]
return output
def OssimBandMerge(band1,band2,band3,output):
myenv = os.environ.copy()
systemplatform = WhichPlatform()
if systemplatform == 'Darwin':
PathToExecutable = str('/var/tmp/XcodeBuilds/Release/')
myenv['DYLD_FRAMEWORK_PATH'] = PathToExecutable
#myenv['GDAL_DRIVER_PATH'] = PathToGdalGrass
else :
PathToExecutable = str('/usr/local/bin/')
myenv['OSSIM_PREFS_FILE'] = PathToOssimPreference
output = subprocess.Popen([PathToExecutable+'ossim-band-merge' , 'tiff_strip' ,str(band1) , str(band2) , str(band3) , str(output)],stdout=subprocess.PIPE, env = myenv).communicate()[0]
def OssimCmm(band1):
myenv = os.environ.copy()
systemplatform = WhichPlatform()
if systemplatform == 'Darwin':
PathToExecutable = str('/var/tmp/XcodeBuilds/Release/')
myenv['DYLD_FRAMEWORK_PATH'] = PathToExecutable
#myenv['GDAL_DRIVER_PATH'] = PathToGdalGrass
else :
PathToExecutable = str('/usr/local/bin/')
myenv['OSSIM_PREFS_FILE'] = PathToOssimPreference
output = subprocess.Popen([PathToExecutable+'ossim-cmm' ,str(band1)],stdout=subprocess.PIPE, env = myenv).communicate()[0]
def OssimHeight(x,y):
myenv = os.environ.copy()
systemplatform = WhichPlatform()
if systemplatform == 'Darwin':
PathToExecutable = str('/var/tmp/XcodeBuilds/Release/')
myenv['DYLD_FRAMEWORK_PATH'] = PathToExecutable
#myenv['GDAL_DRIVER_PATH'] = PathToGdalGrass
else :
PathToExecutable = str('/usr/local/bin/')
myenv['OSSIM_PREFS_FILE'] = PathToOssimPreference
output = subprocess.Popen([PathToExecutable+'ossim-height', str(x) , str(y)],stdout=subprocess.PIPE, env = myenv).communicate()[0]
for line in output.splitlines():
if line.startswith('Height above MSL:'):
data = line[17:].strip()
return data
msl = repr(float(data))
msl = float(msl)
print msl
return msl
def OssimMosaic(img1,img2,output):
myenv = os.environ.copy()
systemplatform = WhichPlatform()
if systemplatform == 'Darwin':
PathToExecutable = str('/var/tmp/XcodeBuilds/Release/')
myenv['DYLD_FRAMEWORK_PATH'] = PathToExecutable
#myenv['GDAL_DRIVER_PATH'] = PathToGdalGrass
else :
PathToExecutable = str('/usr/local/bin/')
myenv['OSSIM_PREFS_FILE'] = PathToOssimPreference
output = subprocess.Popen([PathToExecutable+'ossim-mosaic' ,str(img1), str(img2), str(output)],stdout=subprocess.PIPE, env = myenv).communicate()[0]
def GdalInfo(input):
myenv = os.environ.copy()
output = subprocess.Popen(['gdalinfo' ,str(input)], stdout=subprocess.PIPE, env = myenv).communicate()[0]
return output
def Gdal_TranslateVrt(input,output):
instr = 'gdal_translate -of VRT %s %s' % (input,output)
os.system(instr)
#### functions not yet finished #####
def makeTemplateSRTM(tile):
template = 'igen.slave_tile_buffers: 10 \n'
template += 'igen.tiling.type: ossimTiling \n'
template += 'igen.tiling.tiling_distance: 1 1 \n'
template += 'igen.tiling.tiling_distance_type: degrees \n'
template += 'igen.tiling.delta: %s %s \n' % (tile,tile)
template += 'igen.tiling.delta_type: total_pixels \n'
template += 'igen.tiling.tile_name_mask: %SRTM% \n'
template += 'igen.tiling.padding_size_in_pixels: 0 0 \n'
template += 'object1.description: \n'
template += 'object1.enabled: 1 \n'
template += 'object1.id: 1 \n'
template += 'object1.object1.description: \n'
template += 'object1.object1.enabled: 1 \n'
template += 'object1.object1.id: 2 \n'
template += 'object1.object1.resampler.magnify_type: bilinear \n'
template += 'object1.object1.resampler.minify_type: bilinear \n'
template += 'object1.object1.type: ossimImageRenderer \n'
template += 'object1.object2.type: ossimCastTileSourceFilter \n'
template += 'object1.object2.scalar_type: ossim_sint16 \n'
template += 'object1.type: ossimImageChain \n'
template += 'object2.type: ossimGeneralRasterWriter \n'
template += 'object2.byte_order: big_endian \n'
template += 'product.projection.type: ossimEquDistCylProjection \n'
return template
def orthoigen(input,outputdir,outputname,tile):
#apppath = os.path.abspath(os.path.dirname(sys.argv[0]))
#workdir = os.chdir()
#ds = gdal.Open(input)
#geotransform = ds.GetGeoTransform()
#xpixelsize=geotransform[1]
#ypixelsize=geotransform[5]
#const = 108000
#xtile = (cont+xpixelsize)/xpixelsize
#ytile = (cont+ypixelsize)/ypixelsize
template = makeTemplateSRTM(tile)
return template