示例#1
0
    def can_handle(url):
        if not url.startswith('file://'):
            log.debug("able to handle %s? no, invalid url" % url)
            return False

        path = url2path(url)
        if not is_bag(path):
            log.debug("able to handle %s? no, not a BAG" % url)
            return False

        log.debug("able to handle %s? yes" % url)
        return True
示例#2
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


    import argparse
    from hydroffice.bag import BAGFile, is_bag, __version__

    app_name = "bag_metadata"
    app_info = "Extraction of XML metadata from an OpenNS BAG file, using hydroffice.bag r%s" % __version__

    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("-x", "--xml_file", help="the output XML metadata 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.xml_file:
            args.xml_file = os.path.abspath(args.xml_file)
            print("> output: %s" % args.xml_file)
        else:
            args.xml_file = os.path.abspath(BAGFile.default_metadata_file)
            print("> output: %s [default]" % args.xml_file)

    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:
        bf.extract_metadata(args.xml_file)
    except Exception as e:
        parser.exit(1, "ERROR: %s" % e)

    if args.verbose:
        print("> DONE")
示例#3
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


    import argparse
    from hydroffice.bag import BAGFile, is_bag, __version__

    app_name = "bag_bbox"
    app_info = "Extraction of bounding box from an OpenNS BAG file, using hydroffice.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 hydroffice.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")
示例#4
0
def main():
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)


    import argparse
    from hydroffice.bag import BAGFile, is_bag, __version__

    app_name = "bag_tracklist"
    app_info = "Extraction the tracklist from an OpenNS BAG file, using hydroffice.bag r%s" % __version__

    formats = ['csv']

    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="csv", metavar='')
    parser.add_argument("-o", "--output", help="the output file", type=str)
    parser.add_argument("-hd", "--header", help="add an header", action="store_true")
    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)
        print("> header: %s" % args.header)

    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)
    tl = None
    try:
        tl = bf.tracking_list()
    except Exception as e:
        parser.exit(1, "ERROR: issue in tracking-list recovery: %s" % e)

    tlf = ""
    if args.header:
        try:
            tlf = bf.tracking_list_fields()
        except Exception as e:
            parser.exit(1, "ERROR: issue in tracking-list fields recovery: %s" % e)

    try:
        from hydroffice.bag.tracklist import TrackList2Csv
        TrackList2Csv(track_list=tl, csv_file=args.output, header=tlf)
    except Exception as e:
        parser.exit(1, "ERROR: issue in output creation: %s" % e)

    if args.verbose:
        print("> DONE")