def read_color_table(image, sigevent_url): """ Read color table from an input image and returns list of colors Argument: image -- Image to read color table """ log_info_mssg("Checking for color table in " + image) colortable = [] idx = 0 has_color_table = False gdalinfo_command_list = ['gdalinfo', image] gdalinfo = subprocess.Popen(gdalinfo_command_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE) for line in gdalinfo.stdout.readlines(): if has_color_table == True and (" " + str(idx) + ":") in line: rgb = line.replace(str(idx) + ":", "").strip().split(",") if len(rgb) < 4: rgb[3] = "255" # default if alpha not define colorEntry = ColorEntry(idx, rgb[0], rgb[1], rgb[2], rgb[3]) colortable.append(colorEntry) idx += 1 if "Color Table" in line: has_color_table = True if has_color_table == False: log_sig_exit("Error", "No color table found in " + image, sigevent_url) return colortable
def read_color_table(image, sigevent_url): """ Read color table from an input image and returns list of colors Argument: image -- Image to read color table """ log_info_mssg("Checking for color table in " + image) colortable = [] idx = 0 has_color_table = False gdalinfo_command_list=['gdalinfo', image] gdalinfo = subprocess.Popen(gdalinfo_command_list,stdout=subprocess.PIPE,stderr=subprocess.PIPE) for line in gdalinfo.stdout.readlines(): if has_color_table == True and (" " + str(idx) + ":") in line: rgb = line.replace(str(idx) + ":", "").strip().split(",") if len(rgb) < 4: rgb[3] = "255" # default if alpha not define colorEntry = ColorEntry(idx, rgb[0], rgb[1], rgb[2], rgb[3]) colortable.append(colorEntry) idx+=1 if "Color Table" in line: has_color_table = True if has_color_table == False: log_sig_exit("Error", "No color table found in " + image, sigevent_url) return colortable
def read_colormap(colormap_filename, sigevent_url): """ Read color tables from GIBS color map and returns a list of colors Argument: colormap_filename -- GIBS color map file to read color tables """ colortable = [] try: # Open colormap file. colormap_file=open(colormap_filename, 'r') dom = xml.dom.minidom.parse(colormap_file) log_info_mssg("Opening file " + colormap_filename) colormap_file.close() except IOError: # try http URL log_info_mssg("Unable to find file, trying as URL: " + colormap_filename) try: dom = xml.dom.minidom.parse(urllib.urlopen(colormap_filename)) except IOError, e: log_sig_exit("ERROR", str(e), sigevent_url)
def read_colormap(colormap_filename, sigevent_url): """ Read color tables from GIBS color map and returns a list of colors Argument: colormap_filename -- GIBS color map file to read color tables """ colortable = [] try: # Open colormap file. colormap_file = open(colormap_filename, 'r') dom = xml.dom.minidom.parse(colormap_file) log_info_mssg("Opening file " + colormap_filename) colormap_file.close() except IOError: # try http URL log_info_mssg("Unable to find file, trying as URL: " + colormap_filename) try: dom = xml.dom.minidom.parse(urllib.urlopen(colormap_filename)) except IOError, e: log_sig_exit("ERROR", str(e), sigevent_url)
alpha = 0 # Send email. send_email = options.send_email # Email server. email_server = options.email_server # Email recipient email_recipient = options.email_recipient # Email sender email_sender = options.email_sender # Email metadata replaces sigevent_url if send_email == True and email_recipient != '': sigevent_url = (email_server, email_recipient, email_sender) else: sigevent_url = '' log_info_mssg('colormap: ' + colormap_filename) log_info_mssg('output VRT: ' + output_vrt) log_info_mssg('merge VRT: ' + merge_vrt) try: # Open colormap file. colormap_file = open(colormap_filename, 'r') dom = xml.dom.minidom.parse(colormap_file) log_info_mssg("Opening file " + colormap_filename) colormap_file.close() except IOError: # try http URL log_info_mssg("Accessing URL " + colormap_filename) dom = xml.dom.minidom.parse(urllib.urlopen(colormap_filename)) # ColorMap parameters colorMaps = dom.getElementsByTagName('ColorMap')
alpha = 0 # Send email. send_email=options.send_email # Email server. email_server=options.email_server # Email recipient email_recipient=options.email_recipient # Email sender email_sender=options.email_sender # Email metadata replaces sigevent_url if send_email == True and email_recipient != '': sigevent_url = (email_server, email_recipient, email_sender) else: sigevent_url = '' log_info_mssg('colormap: ' + colormap_filename) log_info_mssg('output VRT: ' + output_vrt) log_info_mssg('merge VRT: ' + merge_vrt) try: # Open colormap file. colormap_file=open(colormap_filename, 'r') dom = xml.dom.minidom.parse(colormap_file) log_info_mssg("Opening file " + colormap_filename) colormap_file.close() except IOError: # try http URL log_info_mssg("Accessing URL " + colormap_filename) dom = xml.dom.minidom.parse(urllib.urlopen(colormap_filename)) # ColorMap parameters colorMaps = dom.getElementsByTagName('ColorMap')
# Colors to ignore if not options.ignore_colors: ignore_colors = [] else: ignore_colors = options.ignore_colors.strip().split("|") for ignore_color in ignore_colors: if r_color.match(ignore_color) is None: log_sig_exit( "Error", ignore_color + " ignore_color format must be %d,%d,%d,%d", sigevent_url) # verbose logging if verbose: log_info_mssg('Colormap: ' + colormap_filename) log_info_mssg('Input Image: ' + input_filename) log_info_mssg('Fill Value: ' + fill_value) log_info_mssg('Ignore Colors: ' + str(ignore_colors)) # Read palette from colormap try: colortable = read_colormap(colormap_filename, sigevent_url) except: log_sig_exit("Error", "Unable to read colormap " + colormap_filename, sigevent_url) # Read palette from image img_colortable = read_color_table(input_filename, sigevent_url) # Lists to track matching colors
# No XML configurations (getCapabilities, getTileService) xml = not options.no_xml # No Tiled-WMS configuration. twms = not options.no_twms # No WMTS configuration. wmts = not options.no_wmts # TileMatrixSet configurations if options.tilematrixsets_config_path: tilematrixsets_config_path = options.tilematrixsets_config_path else: tilematrixsets_config_path = lcdir + '/conf/tilematrixsets.xml' layer_config_path = options.layer_config_path if not layer_config_path: print 'No layer config XML specified' sys.exit() # Sigevent URL. sigevent_url = options.sigevent_url base_twms_gc = os.path.join(lcdir, '/conf/getcapabilities_base_twms.xml') base_twms_get_tile_service = os.path.join(lcdir, '/conf/gettileservice_base.xml') base_wmts_gc = os.path.join(lcdir, '/conf/getcapabilities_base_wmts.xml') print 'Using ' + lcdir + ' as $LCDIR.' if not xml: log_info_mssg("no_xml specified, getCapabilities and getTileService files will be staged only") build_reproject_configs(layer_config_path, tilematrixsets_config_path, base_wmts_gc=base_wmts_gc, base_twms_gc=base_twms_gc, base_twms_get_tile_service=base_twms_get_tile_service, wmts=wmts, twms=twms, xml=xml, sigevent_url=sigevent_url, stage_only=options.stage_only, debug=options.debug)
r_color = re.compile(r'\d+,\d+,\d+,\d+') if r_color.match(fill_value) is None: log_sig_exit("Error", "fill_value format must be %d,%d,%d,%d", sigevent_url) # Colors to ignore if not options.ignore_colors: ignore_colors = [] else: ignore_colors = options.ignore_colors.strip().split("|") for ignore_color in ignore_colors: if r_color.match(ignore_color) is None: log_sig_exit("Error", ignore_color + " ignore_color format must be %d,%d,%d,%d", sigevent_url) # verbose logging if verbose: log_info_mssg('Colormap: ' + colormap_filename) log_info_mssg('Input Image: ' + input_filename) log_info_mssg('Fill Value: ' + fill_value) log_info_mssg('Ignore Colors: ' + str(ignore_colors)) # Read palette from colormap try: colortable = read_colormap(colormap_filename, sigevent_url) except: log_sig_exit("Error", "Unable to read colormap " + colormap_filename, sigevent_url) # Read palette from image img_colortable = read_color_table(input_filename, sigevent_url) # Lists to track matching colors match_colors = []