コード例 #1
0
ファイル: t.info.py プロジェクト: AsherBond/MondocosmOS
def main():

    # Get the options
    name = options["dataset"]
    type = options["type"]
    shellstyle = flags['g']
    tmatrix = flags['t']

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

    #Get the current mapset to create the id of the space time dataset

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

    if type == "strds":
        sp = tgis.space_time_raster_dataset(id)
    if type == "str3ds":
        sp = tgis.space_time_raster3d_dataset(id)
    if type == "stvds":
        sp = tgis.space_time_vector_dataset(id)
    if type == "raster":
        sp = tgis.raster_dataset(id)
        tmatrix = False
    if type == "raster3d":
        sp = tgis.raster3d_dataset(id)
        tmatrix = False
    if type == "vector":
        sp = tgis.vector_dataset(id)
        tmatrix = False

    if sp.is_in_db() == False:
        grass.fatal("Dataset <" + name + "> not found in temporal database")
        
    # Insert content from db
    sp.select()

    if tmatrix:
        matrix = sp.get_temporal_relation_matrix()

        for row in matrix:
            for col in row:
                print col,
            print " "
        print " "

    if shellstyle == True:
        sp.print_shell_info()
    else:
        sp.print_info()
コード例 #2
0
ファイル: tr.series.py プロジェクト: AsherBond/MondocosmOS
def main():

    # Get the options
    input = options["input"]
    output = options["output"]
    method = options["method"]
    sort = options["sort"]
    where = options["where"]

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

    if input.find("@") >= 0:
        id = input
    else:
        mapset =  grass.gisenv()["MAPSET"]
        id = input + "@" + mapset

    sp = tgis.space_time_raster_dataset(id)

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

    sp.select()

    rows = sp.get_registered_maps(None, where, sort)

    if rows:
        inputs = ""

        count = 0
        for row in rows:
            if count == 0:
                inputs += row["id"]
            else:
                inputs += "," + row["id"]
            count += 1

        print inputs

        if grass.overwrite() == True:
            grass.run_command("r.series", input=inputs, output=output, overwrite=True, method=method)
        else:
            grass.run_command("r.series", input=inputs, output=output, overwrite=False, method=method)
コード例 #3
0
ファイル: t.remove.py プロジェクト: AsherBond/MondocosmOS
def main():
    
    # Get the options
    names = options["dataset"]
    type = options["type"]

    # Make sure the temporal database exists
    tgis.create_temporal_database()
    
    mapset =  grass.gisenv()["MAPSET"]

    dbif = tgis.sql_database_interface()
    dbif.connect()

    for name in names.split(","):
        name = name.strip()
        # Check for the mapset in name
        if name.find("@") < 0:
            id = name + "@" + mapset
        else:
            id = name

        if type == "strds":
            ds = tgis.space_time_raster_dataset(id)
        if type == "str3ds":
            ds = tgis.space_time_raster3d_dataset(id)
        if type == "stvds":
            ds = tgis.space_time_vector_dataset(id)
        if type == "raster":
            ds = tgis.raster_dataset(id)
        if type == "raster3d":
            ds = tgis.raster3d_dataset(id)
        if type == "vector":
            ds = tgis.vector_dataset(id)

        if ds.is_in_db(dbif) == False:
            grass.fatal(ds.get_type() + " dataset <" + name + "> not found in temporal database")

        # We need to read some data from the temporal database
        ds.select(dbif)
        ds.delete(dbif)

    dbif.close()
コード例 #4
0
ファイル: t.create.py プロジェクト: AsherBond/MondocosmOS
def main():

    # Get the options
    name = options["dataset"]
    type = options["type"]
    temporaltype = options["temporaltype"]
    title = options["title"]
    descr = options["description"]
    semantic = options["semantictype"]
    gran = options["granularity"]

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

    #Get the current mapset to create the id of the space time dataset

    mapset =  grass.gisenv()["MAPSET"]
    id = name + "@" + mapset

    if type == "strds":
        sp = tgis.space_time_raster_dataset(id)
    if type == "str3ds":
        sp = tgis.space_time_raster3d_dataset(id)
    if type == "stvds":
        sp = tgis.space_time_vector_dataset(id)

    dbif = tgis.sql_database_interface()
    dbif.connect()

    if sp.is_in_db(dbif) and grass.overwrite() == False:
        grass.fatal("Space time " + sp.get_new_map_instance(None).get_type() + " dataset <" + name + "> is already in the database. Use the overwrite flag.")

    if sp.is_in_db(dbif) and grass.overwrite() == True:
        grass.info("Overwrite space time " + sp.get_new_map_instance(None).get_type() + " dataset <" + name + "> and unregister all maps.")
        sp.delete(dbif)
        sp = sp.get_new_instance(id)

    grass.info("Create space time " + sp.get_new_map_instance(None).get_type() + " dataset.")

    sp.set_initial_values(granularity=gran, temporal_type=temporaltype, semantic_type=semantic, title=title, description=descr)
    sp.insert(dbif)

    dbif.close()
コード例 #5
0
ファイル: t.list.py プロジェクト: AsherBond/MondocosmOS
def main():

    # Get the options
    type = options["type"]
    temporaltype = options["temporaltype"]
    columns = options["columns"]
    sort = options["sort"]
    where = options["where"]
    separator = options["fs"]
    colhead = flags['c']

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

    id = None

    if type == "strds":
        sp = tgis.space_time_raster_dataset(id)
    if type == "str3ds":
        sp = tgis.space_time_raster3d_dataset(id)
    if type == "stvds":
        sp = tgis.space_time_vector_dataset(id)
    if type == "raster":
        sp = tgis.raster_dataset(id)
    if type == "raster3d":
        sp = tgis.raster3d_dataset(id)
    if type == "vector":
        sp = tgis.vector_dataset(id)

    dbif = tgis.sql_database_interface()
    dbif.connect()

    # Insert content from db
    sp.select(dbif)

    # Create the sql selection statement
    # Table name
    if temporaltype == "absolute":
        table = sp.get_type() + "_view_abs_time"
    else:
        table = sp.get_type() + "_view_rel_time"

    if columns.find("all") == -1:
        sql = "SELECT " + str(columns) + " FROM " + table
    else:
        sql = "SELECT * FROM " + table

    if sort:
        sql += " ORDER BY " + sort

    if where:
        sql += " WHERE " + where

    dbif.cursor.execute(sql)
    rows = dbif.cursor.fetchall()
    dbif.close()

    # Print the query result to stout
    if rows:
        if separator == None or separator == "":
            separator = "\t"

        # Print the column names if requested
        if colhead == True:
            output = ""
            count = 0
            for key in rows[0].keys():
                if count > 0:
                    output += separator + str(key)
                else:
                    output += str(key)
                count += 1
            print output

        for row in rows:
            output = ""
            count = 0
            for col in row:
                if count > 0:
                    output += separator + str(col)
                else:
                    output += str(col)
                count += 1
                
            print output