Пример #1
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()
Пример #2
0
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()
Пример #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