def getGeoTiffBoundingBox(geoTiffPath): """Returns (minLon, maxLon, minLat, maxLat) for a geotiff image""" if not os.path.exists(geoTiffPath): raise Exception('Input file does not exist: ' + geoTiffPath) # Call command line tool silently cmd = ['geoRefTool', '--printBounds', geoTiffPath] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) textOutput, err = p.communicate() # Check that the call did not fail if (textOutput.find('Failed') >= 0): raise Exception( 'Error: getGeoTiffBoundingBox failed on input image: ' + geoTiffPath) # Parse the output try: minLat = float( IrgStringFunctions.getLineAfterText(textOutput, 'Min latitude =')) maxLat = float( IrgStringFunctions.getLineAfterText(textOutput, 'Max latitude =')) minLon = float( IrgStringFunctions.getLineAfterText(textOutput, 'Min longitude =')) maxLon = float( IrgStringFunctions.getLineAfterText(textOutput, 'Max longitude =')) except Exception, e: print 'In file: ' + geoTiffPath print 'In text:' print textOutput raise e
def getGeoTiffBoundingBox(geoTiffPath): """Returns (minLon, maxLon, minLat, maxLat) for a geotiff image""" if not os.path.exists(geoTiffPath): raise Exception('Input file does not exist: ' + geoTiffPath) # Call command line tool silently cmd = ['geoRefTool', '--printBounds', geoTiffPath] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) textOutput, err = p.communicate() # Check that the call did not fail if (textOutput.find('Failed') >= 0): raise Exception('Error: getGeoTiffBoundingBox failed on input image: ' + geoTiffPath) # Parse the output try: minLat = float( IrgStringFunctions.getLineAfterText(textOutput, 'Min latitude =') ) maxLat = float( IrgStringFunctions.getLineAfterText(textOutput, 'Max latitude =') ) minLon = float( IrgStringFunctions.getLineAfterText(textOutput, 'Min longitude =') ) maxLon = float( IrgStringFunctions.getLineAfterText(textOutput, 'Max longitude =') ) except Exception,e: print 'In file: ' + geoTiffPath print 'In text:' print textOutput raise e
def getAspVersionStrings(): """Returns version strings for ASP""" # Get the version text cmd = ['stereo_pprc', '-v'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) textOut, err = p.communicate() # Parse the version text # Get the ASP stuff aspFirstLine = IrgStringFunctions.getLineAfterText(textOut, 'NASA Ames Stereo Pipeline', 0, True) aspSecondLine = IrgStringFunctions.getLineAfterText(textOut, 'Build ID:', 0, True) aspLine = aspFirstLine + ', ' + aspSecondLine secondaryStart = textOut.find('Built against:') # Get the vision workbench stuff vwFirstLine = IrgStringFunctions.getLineAfterText(textOut, 'NASA Vision Workbench', secondaryStart, True) vwSecondLine = IrgStringFunctions.getLineAfterText(textOut, 'Build ID:', secondaryStart, True) # Make sure we don't find the ASP line vwLine = vwFirstLine + ', ' + vwSecondLine # Get the ISIS stuff isisLine = IrgStringFunctions.getLineAfterText(textOut, 'USGS ISIS', secondaryStart, True) isisLine = isisLine.split('#')[0] # Restrict to first part of the line return (aspLine, vwLine, isisLine)
def getProjectedBoundsFromIsisLabel(filePath): '''Function to read the projected coordinates bounding box from an ISIS label file''' if not os.path.exists(filePath): raise Exception('Error, missing label file path!') # Read all the values! minX = None maxY = None pixRes = None numRows = None numCols = None f = open(filePath, 'r') for line in f: if ('UpperLeftCornerX' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): minX = float(s[:endPos - 1]) else: minX = float(s) continue if ('UpperLeftCornerY' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): maxY = float(s[:endPos - 1]) else: maxY = float(s) continue if ('PixelResolution' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): pixRes = float(s[:endPos - 1]) else: pixRes = float(s) continue if (' Samples =' in line): s = IrgStringFunctions.getLineAfterText(line, '=') numCols = float(s) continue if (' Lines =' in line): s = IrgStringFunctions.getLineAfterText(line, '=') numRows = float(s) continue f.close() if (not minX) or (not maxY) or (not pixRes) or (not numRows) or ( not numCols): raise Exception('Failed to find projected bounds in file ' + filePath) # Compute the other bounds maxX = minX + pixRes * numCols minY = maxY - pixRes * numRows return (minX, maxX, minY, maxY)
def getBoundingBoxFromIsisLabel(filePath): '''Function to read the bounding box from an ISIS label file''' if not os.path.exists(filePath): raise Exception('Error, missing label file path!') numFound = 0 f = open(filePath, 'r') for line in f: if ('MINIMUM_LATITUDE' in line) or ('MinimumLatitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): minLat = float(s[:endPos - 1]) else: minLat = float(s) numFound = numFound + 1 continue if ('MAXIMUM_LATITUDE' in line) or ('MaximumLatitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): maxLat = float(s[:endPos - 1]) else: maxLat = float(s) numFound = numFound + 1 continue if ('EASTERNMOST_LONGITUDE' in line) or ('MAXIMUM_LONGITUDE' in line) or ('MaximumLongitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') # Check for unit name if (endPos >= 0): maxLon = float(s[:endPos - 1]) else: maxLon = float(s) numFound = numFound + 1 continue if ('WESTERNMOST_LONGITUDE' in line) or ('MINIMUM_LONGITUDE' in line) or ('MinimumLongitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') # Check for unit name if (endPos >= 0): minLon = float(s[:endPos - 1]) else: minLon = float(s) numFound = numFound + 1 continue if numFound == 4: break f.close() if numFound < 4: raise Exception('Failed to find lat/lon bounds in file ' + filePath) return (minLon, maxLon, minLat, maxLat)
def getProjectedBoundsFromIsisLabel(filePath): '''Function to read the projected coordinates bounding box from an ISIS label file''' if not os.path.exists(filePath): raise Exception('Error, missing label file path!') # Read all the values! minX = None maxY = None pixRes = None numRows = None numCols = None f = open(filePath, 'r') for line in f: if ('UpperLeftCornerX' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): minX = float(s[:endPos-1]) else: minX = float(s) continue if ('UpperLeftCornerY' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): maxY = float(s[:endPos-1]) else: maxY = float(s) continue if ('PixelResolution' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): pixRes = float(s[:endPos-1]) else: pixRes = float(s) continue if (' Samples =' in line): s = IrgStringFunctions.getLineAfterText(line, '=') numCols = float(s) continue if (' Lines =' in line): s = IrgStringFunctions.getLineAfterText(line, '=') numRows = float(s) continue f.close() if (not minX) or (not maxY) or (not pixRes) or (not numRows) or (not numCols): raise Exception('Failed to find projected bounds in file ' + filePath) # Compute the other bounds maxX = minX + pixRes*numCols minY = maxY - pixRes*numRows return (minX, maxX, minY, maxY)
def getBoundingBoxFromIsisLabel(filePath): '''Function to read the bounding box from an ISIS label file''' if not os.path.exists(filePath): raise Exception('Error, missing label file path!') numFound = 0 f = open(filePath, 'r') for line in f: if ('MINIMUM_LATITUDE' in line) or ('MinimumLatitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): minLat = float(s[:endPos-1]) else: minLat = float(s) numFound = numFound + 1 continue if ('MAXIMUM_LATITUDE' in line) or ('MaximumLatitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') if (endPos >= 0): maxLat = float(s[:endPos-1]) else: maxLat = float(s) numFound = numFound + 1 continue if ('EASTERNMOST_LONGITUDE' in line) or ('MAXIMUM_LONGITUDE' in line) or ('MaximumLongitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') # Check for unit name if (endPos >= 0): maxLon = float(s[:endPos-1]) else: maxLon = float(s) numFound = numFound + 1 continue if ('WESTERNMOST_LONGITUDE' in line) or ('MINIMUM_LONGITUDE' in line) or ('MinimumLongitude' in line): s = IrgStringFunctions.getLineAfterText(line, '=') endPos = s.find('<') # Check for unit name if (endPos >= 0): minLon = float(s[:endPos-1]) else: minLon = float(s) numFound = numFound + 1 continue if numFound == 4: break f.close() if numFound < 4: raise Exception('Failed to find lat/lon bounds in file ' + filePath) return (minLon, maxLon, minLat, maxLat)
def getGdalInfoTagValue(text, tag): """Gets the value of a gdal parameter in a [""] tag or None if it is absent.""" try: lineAfterTag = IrgStringFunctions.getLineAfterText(text, tag) # The remaining line should look like this: ",25], commaPos = lineAfterTag.find(',') bracketPos = lineAfterTag.find(']') # The value is always returned as a string return IrgStringFunctions.convertToFloatIfNumber(lineAfterTag[commaPos+1:bracketPos]) except Exception: # Requested tag was not found return None
def loadKeys(): '''Load the authorization keys''' keyPath = os.path.join(sys.path[0], 'keys.txt') f = open(keyPath, 'r') lines = f.readlines() f.close() # Authorization codes API_KEY = IrgStringFunctions.getLineAfterText(lines[0], '=').strip() CLIENT_ID = IrgStringFunctions.getLineAfterText(lines[1], '=').strip() CLIENT_SECRET = IrgStringFunctions.getLineAfterText(lines[2], '=').strip() PROJECT_ID = IrgStringFunctions.getLineAfterText(lines[3], '=').strip() return (API_KEY, CLIENT_ID, CLIENT_SECRET, PROJECT_ID)
def getGdalInfoTagValue(text, tag): """Gets the value of a gdal parameter in a [""] tag or None if it is absent.""" try: lineAfterTag = IrgStringFunctions.getLineAfterText(text, tag) # The remaining line should look like this: ",25], commaPos = lineAfterTag.find(',') bracketPos = lineAfterTag.find(']') # The value is always returned as a string return IrgStringFunctions.convertToFloatIfNumber( lineAfterTag[commaPos + 1:bracketPos]) except Exception: # Requested tag was not found return None
def getCubeCenterLatitude(cubePath, workDir='tmp'): """Calls caminfo on a cube and returns the CenterLatitude value""" # Make sure the requested file is present if not os.path.exists(cubePath): raise Exception('File ' + cubePath + ' does not exist!') # Call caminfo (from ISIS) on the input cube to find out the CenterLatitude value camInfoOuputPath = workDir + "/camInfoOutput.txt" cmd = 'caminfo from=' + cubePath + ' to=' + camInfoOuputPath print cmd os.system(cmd) if not os.path.exists(camInfoOuputPath): raise Exception('Call to caminfo failed on file ' + cubePath) # Read in the output file to extract the CenterLatitude value centerLatitude = -9999 infoFile = open(camInfoOuputPath, 'r') for line in infoFile: if (line.find('CenterLatitude') >= 0): centerLatitude = IrgStringFunctions.getNumberAfterEqualSign(line, ) break # Make sure we found the desired value if (centerLatitude == -9999) or (isinstance(centerLatitude, basestring)): raise Exception("Unable to find CenterLatitude from file " + cubePath) # Clean up temporary file os.remove(camInfoOuputPath) return centerLatitude
def getImageStats(imagePath): """Obtains some image statistics from gdalinfo""" if not os.path.exists(imagePath): raise Exception('Image file ' + imagePath + ' not found!') # Call command line tool silently cmd = ['gdalinfo', imagePath, '-stats'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) textOutput, err = p.communicate() # Statistics are computed seperately for each band bandStats = [] band = 0 while (True): # Loop until we run out of bands # Look for the stats line for this band bandString = 'Band ' + str(band + 1) + ' Block=' bandLoc = textOutput.find(bandString) if bandLoc < 0: return bandStats # Quit if we did not find it # Now parse out the statistics for this band bandMaxStart = textOutput.find('STATISTICS_MAXIMUM=', bandLoc) bandMeanStart = textOutput.find('STATISTICS_MEAN=', bandLoc) bandMinStart = textOutput.find('STATISTICS_MINIMUM=', bandLoc) bandStdStart = textOutput.find('STATISTICS_STDDEV=', bandLoc) bandMax = IrgStringFunctions.getNumberAfterEqualSign( textOutput, bandMaxStart) bandMean = IrgStringFunctions.getNumberAfterEqualSign( textOutput, bandMeanStart) bandMin = IrgStringFunctions.getNumberAfterEqualSign( textOutput, bandMinStart) bandStd = IrgStringFunctions.getNumberAfterEqualSign( textOutput, bandStdStart) # Add results to the output list bandStats.append((bandMin, bandMax, bandMean, bandStd)) band = band + 1 # Move to the next band
def getProjectionFromIsisLabel(filePath): '''Function to read the projection type from an ISIS label file''' if not os.path.exists(filePath): raise Exception('Error, missing label file path!') f = open(filePath, 'r') for line in f: if ('MAP_PROJECTION_TYPE =' in line) or ('ProjectionName =' in line): line = line.replace('"','') # Strip quotes projType = IrgStringFunctions.getLineAfterText(line, '=').strip() f.close() return projType f.close() raise Exception('Unable to find projection type in file ' + filePath)
def getImageStats(imagePath): """Obtains some image statistics from gdalinfo""" if not os.path.exists(imagePath): raise Exception('Image file ' + imagePath + ' not found!') # Call command line tool silently cmd = ['gdalinfo', imagePath, '-stats'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) textOutput, err = p.communicate() # Statistics are computed seperately for each band bandStats = [] band = 0 while (True): # Loop until we run out of bands # Look for the stats line for this band bandString = 'Band ' + str(band+1) + ' Block=' bandLoc = textOutput.find(bandString) if bandLoc < 0: return bandStats # Quit if we did not find it # Now parse out the statistics for this band bandMaxStart = textOutput.find('STATISTICS_MAXIMUM=', bandLoc) bandMeanStart = textOutput.find('STATISTICS_MEAN=', bandLoc) bandMinStart = textOutput.find('STATISTICS_MINIMUM=', bandLoc) bandStdStart = textOutput.find('STATISTICS_STDDEV=', bandLoc) bandMax = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandMaxStart) bandMean = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandMeanStart) bandMin = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandMinStart) bandStd = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandStdStart) # Add results to the output list bandStats.append( (bandMin, bandMax, bandMean, bandStd) ) band = band + 1 # Move to the next band
def getProjectionFromIsisLabel(filePath): '''Function to read the projection type from an ISIS label file''' if not os.path.exists(filePath): raise Exception('Error, missing label file path!') f = open(filePath, 'r') for line in f: if ('MAP_PROJECTION_TYPE =' in line) or ('ProjectionName =' in line): line = line.replace('"', '') # Strip quotes projType = IrgStringFunctions.getLineAfterText(line, '=').strip() f.close() return projType f.close() raise Exception('Unable to find projection type in file ' + filePath)
def getCreationTime(fileList): """Extract the file creation time and return in YYYY-MM-DDTHH:MM:SSZ format""" # We get this from the original non-tif file if len(fileList) < 2: raise Exception('Error, missing original file path!') filePath = fileList[1] # Use subprocess to parse the command output cmd = ['gdalinfo', filePath] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) cmdOut, err = p.communicate() # Find the time string in the text timeString = IrgStringFunctions.getLineAfterText(cmdOut, 'PRODUCT_CREATION_TIME=') # Get to the correct format timeString = timeString.strip() timeString = timeString[:-5] + 'Z' return timeString
def getCreationTimeHelper(filePath): '''Extracts the file creation time from the EDR .IMG image, then saves in to a file''' # Call gdalinfo on the file and grab the output cmd = ['gdalinfo', filePath] p = subprocess.Popen(cmd, stdout=subprocess.PIPE) outputText, err = p.communicate() outputTextLines = outputText.split('\n') timeString = '' for line in outputTextLines: if 'PRODUCT_CREATION_TIME' in line: timeString = IrgStringFunctions.getLineAfterText(line, '=') break if not timeString: raise Exception('Unable to find time string in file ' + filePath) # Get to the correct format timeString = timeString.strip() timeString = timeString + 'Z' return timeString
def getCreationTime(fileList): """Extract the file creation time and return in YYYY-MM-DDTHH:MM:SSZ format""" if 'DTE' in fileList[0]: # DEM files do not have a creation time! #raise Exception('Error, missing label file path!') return '1900-01-01T00:00:00Z' # Return a flag date filePath = fileList[1] timeString = '' f = open(filePath, 'r') for line in f: if 'STOP_TIME' in line: timeString = IrgStringFunctions.getLineAfterText(line, '=') break f.close() if not timeString: raise Exception('Unable to find time string in file ' + filePath) # Get to the correct format timeString = timeString.strip() timeString = timeString[:-4] + 'Z' return timeString
def getImageGeoInfo(imagePath, getStats=True): """Obtains some image geo information from gdalinfo in dictionary format""" outputDict = {} # Call command line tool silently cmd = ['gdalinfo', imagePath, '-proj4'] if getStats: cmd.append('-stats') p = subprocess.Popen(cmd, stdout=subprocess.PIPE) textOutput, err = p.communicate() # Get the size in pixels imageSizeLine = IrgStringFunctions.getLineAfterText(textOutput, 'Size is ') sizeVals = imageSizeLine.split(',') outputDict['image_size'] = (int(sizeVals[0]), int(sizeVals[1])) # Get origin location and pixel size originLine = IrgStringFunctions.getLineAfterText(textOutput, 'Origin = ') pixelSizeLine = IrgStringFunctions.getLineAfterText( textOutput, 'Pixel Size = ') originVals = IrgStringFunctions.getNumbersInParentheses(originLine) pixelSizeVals = IrgStringFunctions.getNumbersInParentheses(pixelSizeLine) outputDict['origin'] = originVals outputDict['pixel_size'] = pixelSizeVals # Get bounding box in projected coordinates and possibly lonlat coordinates upperLeftLine = IrgStringFunctions.getLineAfterText( textOutput, 'Upper Left') lowerRightLine = IrgStringFunctions.getLineAfterText( textOutput, 'Lower Right') ulCoords = parseGdalLonLatBounds(upperLeftLine) brCoords = parseGdalLonLatBounds(lowerRightLine) (minX, maxY) = ulCoords[0] (maxX, minY) = brCoords[0] outputDict['projection_bounds'] = (minX, maxX, minY, maxY) if (len(ulCoords) == 2): (minLon, maxLat) = ulCoords[1] (maxLon, minLat) = brCoords[1] while (maxLon < minLon): # Get lon values in the same degree range maxLon += 360.0 outputDict['lonlat_bounds'] = (minLon, maxLon, minLat, maxLat) # Try to read in a set of ground control points # - TODO: Read in the GCP projection info! if 'GCP[' in textOutput: # Split the text into lines, then look for that symbol at each line lines = textOutput.split('\n') gcpList = [] foundGcp = False for line in lines: if foundGcp: # Parse the lines following the GCP tag to get the coordinates numSets = IrgStringFunctions.getNumbersInParentheses( line, brackets=False) gcpList.append(numSets) # This should be in the correct format foundGcp = False if 'GCP[' in line: foundGcp = True # Do we need the GCP ID number? #index = IrgStringFunctions.getNumbersInParentheses(line, brackets=True)[0] outputDict['GCPs'] = gcpList # Get some proj4 values outputDict['standard_parallel_1'] = getGdalInfoTagValue( textOutput, 'standard_parallel_1') outputDict['central_meridian'] = getGdalInfoTagValue( textOutput, 'central_meridian') # TODO: Get the projection type! if '+proj=eqc' in textOutput: outputDict['projection'] = 'EQUIRECTANGULAR' elif '+proj=ster' in textOutput: outputDict['projection'] = 'POLAR STEREOGRAPHIC' else: outputDict['projection'] = 'UNKNOWN' # Extract this variable which ASP inserts into its point cloud files try: pointOffsetLine = IrgStringFunctions.getLineAfterText( textOutput, 'POINT_OFFSET=') # Tag name must be synced with C++ code offsetValues = pointOffsetLine.split(' ') outputDict['point_offset'] = (float(offsetValues[0]), float(offsetValues[1]), float(offsetValues[2])) except: pass # In most cases this line will not be present if getStats: # TODO: Which fields are set by this? # List of dictionaries per band outputDict['band_info'] = [] # Populate band information band = 1 while (True): # Loop until we run out of bands bandString = 'Band ' + str(band) + ' Block=' bandLoc = textOutput.find(bandString) if bandLoc < 0: # Ran out of bands break # Found the band, read pertinent information bandInfo = {} # Get the type string bandLine = IrgStringFunctions.getLineAfterText( textOutput, bandString) typePos = bandLine.find('Type=') commaPos = bandLine.find(',') typeName = bandLine[typePos + 5:commaPos - 1] bandInfo['type'] = typeName outputDict['band_info'] = bandInfo band = band + 1 # Move on to the next band return outputDict
def getImageGeoInfo(imagePath, getStats=True): """Obtains some image geo information from gdalinfo in dictionary format""" outputDict = {} # Call command line tool silently cmd = ['gdalinfo', imagePath, '-proj4'] if getStats: cmd.append('-stats') p = subprocess.Popen(cmd, stdout=subprocess.PIPE) textOutput, err = p.communicate() # Get the size in pixels imageSizeLine = IrgStringFunctions.getLineAfterText(textOutput, 'Size is ') sizeVals = imageSizeLine.split(',') outputDict['image_size'] = (int(sizeVals[0]), int(sizeVals[1])) # Get origin location and pixel size originLine = IrgStringFunctions.getLineAfterText(textOutput, 'Origin = ') pixelSizeLine = IrgStringFunctions.getLineAfterText(textOutput, 'Pixel Size = ') originVals = IrgStringFunctions.getNumbersInParentheses(originLine) pixelSizeVals = IrgStringFunctions.getNumbersInParentheses(pixelSizeLine) outputDict['origin'] = originVals outputDict['pixel_size'] = pixelSizeVals # Get bounding box in projected coordinates and possibly lonlat coordinates upperLeftLine = IrgStringFunctions.getLineAfterText(textOutput, 'Upper Left') lowerRightLine = IrgStringFunctions.getLineAfterText(textOutput, 'Lower Right') ulCoords = parseGdalLonLatBounds(upperLeftLine) brCoords = parseGdalLonLatBounds(lowerRightLine) (minX, maxY) = ulCoords[0] (maxX, minY) = brCoords[0] outputDict['projection_bounds'] = (minX, maxX, minY, maxY) if (len(ulCoords) == 2): (minLon, maxLat) = ulCoords[1] (maxLon, minLat) = brCoords[1] while (maxLon < minLon): # Get lon values in the same degree range maxLon += 360.0 outputDict['lonlat_bounds'] = (minLon, maxLon, minLat, maxLat) # Try to read in a set of ground control points # - TODO: Read in the GCP projection info! if 'GCP[' in textOutput: # Split the text into lines, then look for that symbol at each line lines = textOutput.split('\n') gcpList = [] foundGcp = False for line in lines: if foundGcp: # Parse the lines following the GCP tag to get the coordinates numSets = IrgStringFunctions.getNumbersInParentheses(line, brackets=False) gcpList.append(numSets) # This should be in the correct format foundGcp = False if 'GCP[' in line: foundGcp = True # Do we need the GCP ID number? #index = IrgStringFunctions.getNumbersInParentheses(line, brackets=True)[0] outputDict['GCPs'] = gcpList # Get some proj4 values outputDict['standard_parallel_1'] = getGdalInfoTagValue(textOutput, 'standard_parallel_1') outputDict['central_meridian'] = getGdalInfoTagValue(textOutput, 'central_meridian') # TODO: Get the projection type! if '+proj=eqc' in textOutput: outputDict['projection'] = 'EQUIRECTANGULAR' elif '+proj=ster' in textOutput: outputDict['projection'] = 'POLAR STEREOGRAPHIC' else: outputDict['projection'] = 'UNKNOWN' # Extract this variable which ASP inserts into its point cloud files try: pointOffsetLine = IrgStringFunctions.getLineAfterText(textOutput, 'POINT_OFFSET=') # Tag name must be synced with C++ code offsetValues = pointOffsetLine.split(' ') outputDict['point_offset'] = (float(offsetValues[0]), float(offsetValues[1]), float(offsetValues[2])) except: pass # In most cases this line will not be present if getStats: # TODO: Which fields are set by this? # List of dictionaries per band outputDict['band_info'] = [] # Populate band information band = 1 while (True): # Loop until we run out of bands bandString = 'Band ' + str(band) + ' Block=' bandLoc = textOutput.find(bandString) if bandLoc < 0: # Ran out of bands break # Found the band, read pertinent information bandInfo = {} # Get the type string bandLine = IrgStringFunctions.getLineAfterText(textOutput, bandString) typePos = bandLine.find('Type=') commaPos = bandLine.find(',') typeName = bandLine[typePos+5:commaPos-1] bandInfo['type'] = typeName outputDict['band_info'] = bandInfo band = band + 1 # Move on to the next band return outputDict