Example #1
0
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()
Example #2
0
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()
Example #3
0
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