def _uncertainty_export(self, fmt='geotiff'): """ Helper function to be re-used for different output formats """ bag_file = self._ask_bag_input() fmt_name = self._uncertainty_formats[fmt][1] fmt_ext = self._uncertainty_formats[fmt][0] out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext) try: bag = BAGFile(bag_file) bag_meta = bag.populate_metadata() bag_unc = bag.uncertainty(mask_nan=False) Uncertainty2Gdal(bag_uncertainty=bag_unc, bag_meta=bag_meta, fmt=fmt, out_file=out_file) except Exception as e: dlg = wx.MessageDialog(parent=None, message="%s" % e, caption="Error", style=wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self._check_file_creation(out_file)
def _bbox_export(self, fmt='kml'): """ Helper function to be re-used for different output formats """ bag_file = self._ask_bag_input() fmt_name = self.bbox_formats[fmt][1] fmt_ext = self.bbox_formats[fmt][0] out_file = self._ask_file_output(fmt_name=fmt_name, fmt_ext=fmt_ext) try: bag = BAGFile(bag_file) bag_meta = bag.populate_metadata() Bbox2Gdal(bag_meta, fmt=fmt, title=os.path.basename(bag_file), out_file=out_file) except Exception as e: dlg = wx.MessageDialog(parent=None, message="%s" % e, caption="Error", style=wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return self._check_file_creation(out_file)
def main(): logger = logging.getLogger() logger.setLevel(logging.NOTSET) import argparse from hyo.bag import BAGFile, is_bag, __version__ app_name = "bag_bbox" app_info = "Extraction of bounding box from an OpenNS BAG file, using hyo.bag r%s" % __version__ formats = ['gjs', 'gml', 'kml', 'shp'] parser = argparse.ArgumentParser(prog=app_name, description=app_info) parser.add_argument("bag_file", type=str, help="a valid BAG file from which to extract metadata") parser.add_argument("-f", "--format", help="one of the available file format: " + ", ".join(formats), choices=formats, default="kml", metavar='') parser.add_argument("-o", "--output", help="the output file", type=str) parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") args = parser.parse_args() if args.verbose: print("> verbosity: ON") ch = logging.StreamHandler() ch.setLevel( logging.DEBUG ) # change to WARNING to reduce verbosity, DEBUG for high verbosity ch_formatter = logging.Formatter( '%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s') ch.setFormatter(ch_formatter) logger.addHandler(ch) if args.verbose: print("> input: %s" % args.bag_file) if args.output: args.output = os.path.abspath(args.output) print("> output: %s" % args.output) else: args.output = None print("> output: [default]") print("> format: %s" % args.format) if not os.path.exists(args.bag_file): parser.exit( 1, "ERROR: the input valid does not exist: %s" % args.bag_file) if not is_bag(args.bag_file): parser.exit( 1, "ERROR: the input valid does not seem a BAG file: %s" % args.bag_file) bf = BAGFile(args.bag_file) try: bag_meta = bf.populate_metadata() except Exception as e: parser.exit(1, "ERROR: issue in metadata population: %s" % e) try: from hyo.bag.bbox import Bbox2Gdal Bbox2Gdal(bag_meta, fmt=args.format, title=os.path.basename(args.bag_file), out_file=args.output) except Exception as e: parser.exit(1, "ERROR: issue in output creation: %s" % e) if args.verbose: print("> DONE")
def main(): logger = logging.getLogger() logger.setLevel(logging.NOTSET) import argparse from hyo.bag import BAGFile, is_bag, __version__ app_name = "bag_uncertainty" app_info = "Extraction of uncertainty layer from an OpenNS BAG file, using hyo.bag r%s" % __version__ formats = ['ascii', 'geotiff', 'xyz'] parser = argparse.ArgumentParser(prog=app_name, description=app_info) parser.add_argument("bag_file", type=str, help="a valid BAG file from which to extract metadata") parser.add_argument("-f", "--format", help="one of the available file format: " + ", ".join(formats), choices=formats, default="geotiff", metavar='') parser.add_argument("-o", "--output", help="the output file", type=str) parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") args = parser.parse_args() if args.verbose: print("> verbosity: ON") ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) # change to WARNING to reduce verbosity, DEBUG for high verbosity ch_formatter = logging.Formatter('%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s') ch.setFormatter(ch_formatter) logger.addHandler(ch) if args.verbose: print("> input: %s" % args.bag_file) if args.output: args.output = os.path.abspath(args.output) print("> output: %s" % args.output) else: args.output = None print("> output: [default]") print("> format: %s" % args.format) if not os.path.exists(args.bag_file): parser.exit(1, "ERROR: the input valid does not exist: %s" % args.bag_file) if not is_bag(args.bag_file): parser.exit(1, "ERROR: the input valid does not seem a BAG file: %s" % args.bag_file) bf = BAGFile(args.bag_file) bag_meta = None try: bag_meta = bf.populate_metadata() except Exception as e: parser.exit(1, "ERROR: issue in metadata population: %s" % e) bag_uncertainty = None try: bag_uncertainty = bf.uncertainty(mask_nan=False) except Exception as e: parser.exit(1, "ERROR: issue in uncertainty population: %s" % e) try: from hyo.bag.uncertainty import Uncertainty2Gdal Uncertainty2Gdal(bag_uncertainty=bag_uncertainty, bag_meta=bag_meta, fmt=args.format, out_file=args.output) except Exception as e: parser.exit(1, "ERROR: issue in output creation: %s" % e) if args.verbose: print("> DONE")
'%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s') ch.setFormatter(ch_formatter) logger.addHandler(ch) from hyo.bag import BAGFile from hyo.bag import BAGError from hyo.bag.helper import Helper file_bag_0 = os.path.join(Helper.samples_folder(), "bdb_01.bag") if os.path.exists(file_bag_0): print("- file_bag_0: %s" % file_bag_0) bag_0 = BAGFile(file_bag_0) print(bag_0) print(type(bag_0.elevation(mask_nan=True)), bag_0.elevation(mask_nan=True).shape, bag_0.elevation(mask_nan=True).dtype) # ax =plt.contourf(bag_0.elevation(mask_nan=True)) # plt.colorbar(ax) # plt.show() bag_meta = bag_0.populate_metadata() print(bag_meta) from hyo.bag.bbox import Bbox2Gdal Bbox2Gdal(bag_meta, fmt="gjs", title=os.path.basename(file_bag_0)) Bbox2Gdal(bag_meta, fmt="gml", title=os.path.basename(file_bag_0)) Bbox2Gdal(bag_meta, fmt="kml", title=os.path.basename(file_bag_0)) Bbox2Gdal(bag_meta, fmt="shp", title=os.path.basename(file_bag_0))
ch.setLevel(logging.DEBUG) # change to WARNING to reduce verbosity, DEBUG for high verbosity ch_formatter = logging.Formatter('%(levelname)-9s %(name)s.%(funcName)s:%(lineno)d > %(message)s') ch.setFormatter(ch_formatter) logger.addHandler(ch) from hyo.bag import BAGFile from hyo.bag import BAGError from hyo.bag.helper import Helper bag_file = os.path.join(Helper.samples_folder(), "bdb_01.bag") if os.path.exists(bag_file): print("- file_bag_0: %s" % bag_file) bag = BAGFile(bag_file) bag_meta = bag.populate_metadata() print(bag_meta) print("has density? %s" % bag.has_density()) if not bag.has_density(): exit() bag_density = bag.density(mask_nan=True) print(type(bag.density(mask_nan=True)), bag.density(mask_nan=True).shape, bag.density(mask_nan=True).dtype) print("min: %s" % np.nanmin(bag_density)) print("max: %s" % np.nanmax(bag_density)) # from hyo.bag.density import Density2Gdal
ax = plt.contourf(sliced_uncertainty) plt.colorbar(ax) plt.show() # - tracking list logger.debug("\ntracking list:\n type: %s\n shape: %s\n dtype: %s" % (type(bag_0.tracking_list()), bag_0.tracking_list().shape, bag_0.tracking_list().dtype)) # - metadata logger.debug("\nmetadata: %s %s\n" % (type(bag_0.metadata()), len(bag_0.metadata()))) file_bag_0_xml = os.path.join("bdb_00.bag.xml") bag_0.extract_metadata(name=file_bag_0_xml) bag_0.populate_metadata() logger.debug("rows, cols: %d, %d" % (bag_0.meta.rows, bag_0.meta.cols)) logger.debug("res x, y: %f, %f" % (bag_0.meta.res_x, bag_0.meta.res_y)) logger.debug("corner SW, NE: %s, %s" % (bag_0.meta.sw, bag_0.meta.ne)) logger.debug("coord sys: %s" % bag_0.meta.wkt_srs) logger.debug(bag_0) file_bag_1 = os.path.join(Helper.samples_folder(), "bdb_01.bag") if os.path.exists(file_bag_1): logger.debug("file_bag_1: %s" % file_bag_1) file_bag_2 = os.path.abspath(os.path.join("test_00.bag")) logger.debug("file_bag_2: %s" % file_bag_2) bag_2 = BAGFile.create_template(file_bag_2)