Exemplo n.º 1
0
def main():
    # Load metadata library
    from mdlib.mdgrass import GrassMD

    if not options['output']:
        destination = None
        output_name = None
    else:
        destination, output_name = os.path.split(options['output'])

    name = options["input"]
    type_ = options["type"]

    # Make sure the temporal database exists
    tgis.init()

    dbif, connected = tgis.init_dbif(None)

    if name.find("@") >= 0:
        id_ = name
    else:
        id_ = "{}@{}".format(name, grass.gisenv()["MAPSET"])

    dataset = tgis.dataset_factory(type_, id_)

    if not dataset.is_in_db(dbif):
        grass.fatal(_("Dataset <%s> not found in temporal database") % (id_), )

    md = GrassMD(id_, type=type_)
    md.createTemporalISO()
    md.saveXML(
        path=destination,
        xml_out_name=output_name,
        overwrite=os.getenv('GRASS_OVERWRITE', False),
    )
Exemplo n.º 2
0
def main():

    name = options["input"]
    type_ = options["type"]
    shellstyle = flags['g']
    system = flags['d']
    history = flags['h']

    # Make sure the temporal database exists
    tgis.init()

    dbif, connected = tgis.init_dbif(None)

    rows = tgis.get_tgis_metadata(dbif)

    if system and not shellstyle:
        #      0123456789012345678901234567890
        print(" +------------------- Temporal DBMI backend information ----------------------+")
        print(" | DBMI Python interface:...... " + str(dbif.get_dbmi().__name__))
        print(" | Temporal database string:... " + str(
            tgis.get_tgis_database_string()))
        print(" | SQL template path:.......... " + str(
            tgis.get_sql_template_path()))
        if rows:
            for row in rows:
                print(" | %s .......... %s"%(row[0], row[1]))
        print(" +----------------------------------------------------------------------------+")
        return
    elif system:
        print("dbmi_python_interface=\'" + str(dbif.get_dbmi().__name__) + "\'")
        print("dbmi_string=\'" + str(tgis.get_tgis_database_string()) + "\'")
        print("sql_template_path=\'" + str(tgis.get_sql_template_path()) + "\'")
        if rows:
            for row in rows:
                print("%s=\'%s\'"%(row[0], row[1]))
        return

    if not system and not name:
        grass.fatal(_("Please specify %s=") % ("name"))

    if name.find("@") >= 0:
        id_ = name
    else:
        id_ = name + "@" + grass.gisenv()["MAPSET"]

    dataset = tgis.dataset_factory(type_, id_)

    if dataset.is_in_db(dbif) == False:
        grass.fatal(_("Dataset <%s> not found in temporal database") % (id_))

    dataset.select(dbif)

    if history == True and type in ["strds", "stvds", "str3ds"]:
        dataset.print_history()
        return

    if shellstyle == True:
        dataset.print_shell_info()
    else:
        dataset.print_info()
Exemplo n.º 3
0
def main():
    # lazy imports
    import grass.temporal as tgis

    name = options["input"]
    type_ = options["type"]
    shellstyle = flags["g"]
    system = flags["d"]
    history = flags["h"]

    # Make sure the temporal database exists
    tgis.init()

    dbif, connection_state_changed = tgis.init_dbif(None)

    rows = tgis.get_tgis_metadata(dbif)

    if system and not shellstyle and not history:
        #      0123456789012345678901234567890
        print(
            " +------------------- Temporal DBMI backend information ----------------------+"
        )
        print(" | DBMI Python interface:...... " + str(dbif.get_dbmi().__name__))
        print(" | Temporal database string:... " + str(tgis.get_tgis_database_string()))
        print(" | SQL template path:.......... " + str(tgis.get_sql_template_path()))
        if rows:
            for row in rows:
                print(" | %s .......... %s" % (row[0], row[1]))
        print(
            " +----------------------------------------------------------------------------+"
        )
        return
    elif system and not history:
        print("dbmi_python_interface='" + str(dbif.get_dbmi().__name__) + "'")
        print("dbmi_string='" + str(tgis.get_tgis_database_string()) + "'")
        print("sql_template_path='" + str(tgis.get_sql_template_path()) + "'")
        if rows:
            for row in rows:
                print("%s='%s'" % (row[0], row[1]))
        return

    if not system and not name:
        grass.fatal(_("Please specify %s=") % ("name"))

    if name.find("@") >= 0:
        id_ = name
    else:
        id_ = name + "@" + grass.gisenv()["MAPSET"]

    dataset = tgis.dataset_factory(type_, id_)

    if not dataset.is_in_db(dbif):
        grass.fatal(
            _("Dataset <{n}> of type <{t}> not found in temporal database").format(
                n=id_, t=type_
            )
        )

    dataset.select(dbif)

    if history and type_ in ["strds", "stvds", "str3ds"]:
        dataset.print_history()
        return

    if shellstyle:
        dataset.print_shell_info()
    else:
        dataset.print_info()
Exemplo n.º 4
0
def main():

    name = options["input"]
    type_ = options["type"]
    shellstyle = flags['g']
    system = flags['s']
    history = flags['h']

    # Make sure the temporal database exists
    tgis.init()

    dbif, connected = tgis.init_dbif(None)

    rows = tgis.get_tgis_metadata(dbif)

    if system and not shellstyle:
        #      0123456789012345678901234567890
        print " +------------------- Temporal DBMI backend information ----------------------+"
        print " | DBMI Python interface:...... " + str(
            dbif.get_dbmi().__name__)
        print " | Temporal database string:... " + str(
            tgis.get_tgis_database_string())
        print " | SQL template path:.......... " + str(
            tgis.get_sql_template_path())
        if rows:
            for row in rows:
                print " | %s .......... %s" % (row[0], row[1])
        print " +----------------------------------------------------------------------------+"
        return
    elif system:
        print "dbmi_python_interface=\'" + str(dbif.get_dbmi().__name__) + "\'"
        print "dbmi_string=\'" + str(tgis.get_tgis_database_string()) + "\'"
        print "sql_template_path=\'" + str(tgis.get_sql_template_path()) + "\'"
        if rows:
            for row in rows:
                print "%s=\'%s\'" % (row[0], row[1])
        return

    if not system and not name:
        grass.fatal(_("Please specify %s=") % ("name"))

    if name.find("@") >= 0:
        id_ = name
    else:
        id_ = name + "@" + grass.gisenv()["MAPSET"]

    dataset = tgis.dataset_factory(type_, id_)

    if dataset.is_in_db(dbif) == False:
        grass.fatal(_("Dataset <%s> not found in temporal database") % (id_))

    dataset.select(dbif)

    if history == True and type in ["strds", "stvds", "str3ds"]:
        dataset.print_history()
        return

    if shellstyle == True:
        dataset.print_shell_info()
    else:
        dataset.print_info()
Exemplo n.º 5
0
def main():
    # lazy imports
    import grass.temporal as tgis

    strdsin = options["strds"]
    rasterin = options["raster"]
    strdsout = options["output"]
    bandname = options["bandname"]

    type_ = "strds"

    # make sure the temporal database exists
    tgis.init()

    dbif, connection_state_changed = tgis.init_dbif(None)

    rows = tgis.get_tgis_metadata(dbif)

    if strdsin.find("@") >= 0:
        strdsid_ = strdsin
    else:
        strdsid_ = strdsin + "@" + grass.gisenv()["MAPSET"]

    if rasterin.find("@") >= 0:
        rasterid_ = rasterin
    else:
        rasterid_ = rasterin + "@" + grass.gisenv()["MAPSET"]

    datasetin = tgis.dataset_factory(type_, strdsid_)

    if not datasetin.is_in_db(dbif):
        grass.fatal(
            _("Dataset <{n}> of type <{t}> not found in temporal database").
            format(n=strdsid_, t=type_))

    datasetin.select(dbif)

    start_time = datasetin.temporal_extent.get_start_time()
    end_time = datasetin.temporal_extent.get_end_time()

    # create a new strds using the old strds as template

    # specs of input strds
    sp = tgis.open_old_stds(strdsid_, "strds", dbif)
    ttype, stype, title, descr = sp.get_initial_values()
    dbif.close()

    # t.create, use specs of input strds
    grass.run_command('t.create',
                      type='strds',
                      output=strdsout,
                      temporaltype=ttype,
                      semantictype=stype,
                      title=title,
                      description=descr)

    # register the raster map in the new strds
    rlistfile = grass.tempfile(create=False)
    fd = open(rlistfile, "w")
    if bandname is not None:
        fd.write("%s|%s|%s|%s\n" %
                 (rasterid_, str(start_time), str(end_time), bandname))
    else:
        fd.write("%s|%s|%s\n" % (rasterid_, str(start_time), str(end_time)))
    fd.close()
    # t.register to create new strds
    grass.run_command('t.register', input=strdsout, file=rlistfile)
    grass.try_remove(rlistfile)