123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- import os
- from grass.script.tgis_core import *
- from grass.script.tgis_base import *
- from grass.script.tgis_temporal_extent import *
- from grass.script.tgis_spatial_extent import *
- from grass.script.tgis_metadata import *
- from grass.script.tgis_abstract_datasets import *
- from grass.script.tgis_space_time_datasets import *
- import grass.script as grass
- ###############################################################################
- def test_dict_sql_serializer():
- t = dict_sql_serializer()
- t.test()
- def test_dataset_identifer():
- for i in range(2):
- base = raster_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", creator="soeren", temporal_type="absolute", revision=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_creator("rene")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = raster3d_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", creator="soeren")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_creator("rene")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = vector_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", creator="soeren")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_creator("rene")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = strds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", creator="soeren", semantic_type="event", temporal_type="absolute", revision=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_creator("rene")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = str3ds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", semantic_type="event", creator="soeren")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_creator("rene")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = stvds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", semantic_type="event", creator="soeren")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_creator("rene")
- base.update()
- base.select()
- base.print_self()
-
- def test_absolute_timestamp():
- for i in range(2):
- base = raster_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), timezone=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_start_time(datetime(2010,01,01))
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = raster3d_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), timezone=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_start_time(datetime(2010,01,01))
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = vector_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), timezone=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_start_time(datetime(2010,01,01))
- base.update()
- base.select()
- base.print_self()
-
- for i in range(2):
- base = strds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_start_time(datetime(2010,01,01))
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = str3ds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_start_time(datetime(2010,01,01))
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = stvds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_start_time(datetime(2010,01,01))
- base.update()
- base.select()
- base.print_self()
-
- def test_spatial_extent():
- for i in range(2):
- base = raster_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_north(120+i)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = raster3d_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_north(120+i)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = vector_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_north(120+i)
- base.update()
- base.select()
- base.print_self()
-
- for i in range(2):
- base = strds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_north(120+i)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = str3ds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_north(120+i)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = stvds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_north(120+i)
- base.update()
- base.select()
- base.print_self()
- def test_relative_timestamp():
- for i in range(2):
- base = raster_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_interval(i+1)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = raster3d_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_interval(i+1)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = vector_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_interval(i+1)
- base.update()
- base.select()
- base.print_self()
-
- for i in range(2):
- base = strds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_interval(i+1)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = str3ds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_interval(i+1)
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = stvds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_interval(i+1)
- base.update()
- base.select()
- base.print_self()
-
- def test_map_metadata():
- for i in range(2):
- base = raster_metadata(ident="soil" + str(i) + "@PERMANENT", strds_register="PERMANENT_soil_strds_register", datatype="CELL", \
- cols=500, rows=400, number_of_cells=200000,nsres=1, ewres=1, min=0, max=33)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_datatype("FCELL")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = raster3d_metadata(ident="soil" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_soil_str3ds_register", datatype="FCELL", \
- cols=500, rows=400, depths=20, number_of_cells=200000,nsres=1, ewres=1, tbres=10, min=0, max=33)
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_datatype("DCELL")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = vector_metadata(ident="soil" + str(i) + "@PERMANENT", stvds_register="PERMANENT_soil_stvds_register")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_stvds_register("PERMANENT_soil_stvds_register")
- base.update()
- base.select()
- base.print_self()
-
- for i in range(2):
- base = strds_metadata(ident="soil" + str(i) + "@PERMANENT", raster_register="PERMANENT_soil_raster_register", \
- title="Test", description="Test description")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_title("More tests")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = str3ds_metadata(ident="soil" + str(i) + "@PERMANENT", raster3d_register="PERMANENT_soil_raster3d_register", \
- title="Test", description="Test description")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_title("More tests")
- base.update()
- base.select()
- base.print_self()
- for i in range(2):
- base = stvds_metadata(ident="soil" + str(i) + "@PERMANENT", vector_register="PERMANENT_soil_vector_register", \
- title="Test", description="Test description")
- base.insert()
- base.select()
- base.print_self()
- base.clear()
- base.set_title("More tests")
- base.update()
- base.select()
- base.print_self()
-
- def test_base_absolute_time_extent_metadata():
- for i in range(10):
- base = vector_base(ident="water" + str(i) + "@PERMANENT", name="water" + str(i), mapset="PERMANENT", creator="soeren")
- base.insert()
- base = raster_base(ident="water" + str(i) + "@PERMANENT", name="water" + str(i), mapset="PERMANENT", creator="soeren")
- base.insert()
- base = raster3d_base(ident="water" + str(i) + "@PERMANENT", name="water" + str(i), mapset="PERMANENT", creator="soeren")
- base.insert()
- for i in range(10):
- base = vector_base(ident="water" + str(i) + "@PERMANENT")
- base.set_creator("rene")
- base.update()
- base = raster_base(ident="water" + str(i) + "@PERMANENT")
- base.set_creator("rene")
- base.update()
- base = raster3d_base(ident="water" + str(i) + "@PERMANENT")
- base.set_creator("rene")
- base.update()
- for i in range(10):
- base = vector_absolute_time(ident="water" + str(i) + "@PERMANENT", start_time=datetime.now(), end_time=datetime.now(), timezone=1)
- base.insert()
- base = raster_absolute_time(ident="water" + str(i) + "@PERMANENT", start_time=datetime.now(), end_time=datetime.now(), timezone=1)
- base.insert()
- base = raster3d_absolute_time(ident="water" + str(i) + "@PERMANENT", start_time=datetime.now(), end_time=datetime.now(), timezone=1)
- base.insert()
- for i in range(10):
- base = vector_absolute_time(ident="water" + str(i) + "@PERMANENT")
- base.set_start_time(datetime(2010, 6, 1))
- base.update()
- base = raster_absolute_time(ident="water" + str(i) + "@PERMANENT")
- base.set_start_time(datetime(2010, 6, 1))
- base.update()
- base = raster3d_absolute_time(ident="water" + str(i) + "@PERMANENT")
- base.set_start_time(datetime(2010, 6, 1))
- base.update()
- for i in range(10):
- base = vector_spatial_extent(ident="water" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- base = raster_spatial_extent(ident="water" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=0, bottom=0)
- base.insert()
- base = raster3d_spatial_extent(ident="water" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
- base.insert()
- for i in range(10):
- base = vector_spatial_extent(ident="water" + str(i) + "@PERMANENT")
- base.set_north(120 + i)
- base.set_south(20 + i)
- base.update()
- base = raster_spatial_extent(ident="water" + str(i) + "@PERMANENT")
- base.set_north(120 + i)
- base.set_south(20 + i)
- base.update()
- base = raster3d_spatial_extent(ident="water" + str(i) + "@PERMANENT")
- base.set_north(120 + i)
- base.set_south(20 + i)
- base.update()
- for i in range(10):
- base = vector_metadata(ident="water" + str(i) + "@PERMANENT", stvds_register="PERMANENT_water_stvds_register")
- base.insert()
- base = raster_metadata(ident="water" + str(i) + "@PERMANENT", strds_register="PERMANENT_water_strds-register", datatype="CELL", \
- cols=500, rows=400, number_of_cells=200000,nsres=1, ewres=1, min=0, max=33)
- base.insert()
- base = raster3d_metadata(ident="water" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_water_str3ds-register", datatype="FCELL", \
- cols=500, rows=400, depths=20, number_of_cells=200000,nsres=1, ewres=1, tbres=10, min=0, max=33)
- base.insert()
- for i in range(10):
- base = vector_metadata(ident="water" + str(i) + "@PERMANENT")
- base.set_stvds_register("PERMANENT_water_stvds_register")
- base.update()
- base = raster_metadata(ident="water" + str(i) + "@PERMANENT")
- base.set_datatype("DCELL")
- base.update()
- base = raster3d_metadata(ident="water" + str(i) + "@PERMANENT")
- base.set_datatype("DCELL")
- base.update()
- for i in range(10):
- base = vector_base(ident="water" + str(i) + "@PERMANENT")
- base.select()
- base.print_self()
- base = raster_base(ident="water" + str(i) + "@PERMANENT")
- base.select()
- base.print_self()
- base = raster3d_base(ident="water" + str(i) + "@PERMANENT")
- base.select()
- base.print_self()
- print "Create a raster object"
- rds = raster_dataset("water0@PERMANENT")
- rds.select()
- rds.print_self()
- print rds.temporal_relation(rds)
- def test_absolut_time_temporal_relations():
- A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2001, month=1, day=1), timezone=1)
- B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2001, month=1, day=1), \
- end_time=datetime(year=2002, month=1, day=1), timezone=1)
- print "Precedes: ", A.temporal_relation(B)
- print "Follows: ", B.temporal_relation(A)
- A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2001, month=1, day=1), timezone=1)
- B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2001, month=1, day=2), \
- end_time=datetime(year=2002, month=1, day=1), timezone=1)
- print "Before: ", A.temporal_relation(B)
- print "After: ", B.temporal_relation(A)
- A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2001, month=1, day=1), timezone=1)
- B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2002, month=1, day=1), timezone=1)
- print "Starts: ", A.temporal_relation(B)
- print "Started: ", B.temporal_relation(A)
- A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2001, month=1, day=1), timezone=1)
- B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=1, day=2), \
- end_time=datetime(year=2001, month=1, day=1), timezone=1)
- print "Finished: ", A.temporal_relation(B)
- print "Finishes: ", B.temporal_relation(A)
- A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2001, month=1, day=1), timezone=1)
- B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=3, day=1), \
- end_time=datetime(year=2000, month=9, day=1), timezone=1)
- print "Contains: ", A.temporal_relation(B)
- print "During: ", B.temporal_relation(A)
- A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2000, month=6, day=1), timezone=1)
- B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=3, day=1), \
- end_time=datetime(year=2000, month=9, day=1), timezone=1)
- print "Overlap: ", A.temporal_relation(B)
- print "Overlapped:", B.temporal_relation(A)
- A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2000, month=1, day=1), timezone=1)
- B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
- end_time=datetime(year=2000, month=1, day=1), timezone=1)
- print "Equivalent:", A.temporal_relation(B)
- print "Equivalent:", B.temporal_relation(A)
- def test_raster_dataset():
-
- # Create a test map
- grass.raster.mapcalc("test = sin(x()) + cos(y())", overwrite = True)
-
- name = "test"
- mapset = grass.gisenv()["MAPSET"]
-
- print "Create a raster object"
- # We need to specify the name and the mapset as identifier
- rds = raster_dataset(name + "@" + mapset)
-
- # Load data from the raster map in the mapset
- rds.load()
-
- print "Is in db: ", rds.is_in_db()
-
- if rds.is_in_db():
- # Remove the entry if it is in the db
- rds.delete()
-
- # Set the absolute valid time
- rds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
- end_time= datetime(year=2010, month=1, day=1))
- # Insert the map data into the SQL database
- rds.insert()
- # Print self info
- rds.print_self()
- # The temporal relation must be equal
- print rds.temporal_relation(rds)
- def test_raster3d_dataset():
-
- # Create a test map
- grass.raster3d.mapcalc3d("test = sin(x()) + cos(y()) + sin(z())", overwrite = True)
-
- name = "test"
- mapset = grass.gisenv()["MAPSET"]
-
- print "Create a raster object"
- # We need to specify the name and the mapset as identifier
- r3ds = raster3d_dataset(name + "@" + mapset)
-
- # Load data from the raster map in the mapset
- r3ds.load()
-
- print "Is in db: ", r3ds.is_in_db()
-
- if r3ds.is_in_db():
- # Remove the entry if it is in the db
- r3ds.delete()
-
- # Set the absolute valid time
- r3ds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
- end_time= datetime(year=2010, month=1, day=1))
-
- # Insert the map data into the SQL database
- r3ds.insert()
- # Print self info
- r3ds.print_self()
- # The temporal relation must be equal
- print r3ds.temporal_relation(r3ds)
- def test_vector_dataset():
-
- # Create a test map
- grass.run_command("v.random", output="test", n=20, column="height", zmin=0, \
- zmax=100, flags="z", overwrite = True)
-
- name = "test"
- mapset = grass.gisenv()["MAPSET"]
-
- print "Create a vector object"
- # We need to specify the name and the mapset as identifier
- vds = vector_dataset(name + "@" + mapset)
-
- # Load data from the raster map in the mapset
- vds.load()
-
- print "Is in db: ", vds.is_in_db()
-
- if vds.is_in_db():
- # Remove the entry if it is in the db
- vds.delete()
-
- # Set the absolute valid time
- vds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
- end_time= datetime(year=2010, month=1, day=1))
- # Insert the map data into the SQL database
- vds.insert()
- # Print self info
- vds.print_self()
- # The temporal relation must be equal
- print vds.temporal_relation(vds)
- def test_strds_dataset():
-
- name = "strds_test_1"
- mapset = grass.gisenv()["MAPSET"]
- print "Create a strds object"
- # We need to specify the name and the mapset as identifier
- strds = space_time_raster_dataset(ident = name + "@" + mapset)
- # Check if in db
- print "Is strds in db: ", strds.is_in_db()
- # Create a new entry if not in db
- if strds.is_in_db() == False:
- strds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
- semantic_type="event", title="This is a test space time raster dataset", description="A space time raster dataset for testing")
- strds.insert()
-
- # Reread the data from the db
- strds.select()
- # Print self info
- #strds.print_self()
- # Create a test maps
- for i in range(11):
- i = i + 1
- grass.raster.mapcalc("test" + str(i) + " = sin(x()) + cos(y())", overwrite = True)
-
- name = "test" + str(i)
- mapset = grass.gisenv()["MAPSET"]
- ident = name + "@" + mapset
- print "Create a raster object"
- # We need to specify the name and the mapset as identifier
- rds = raster_dataset(ident)
- # Load data from the raster map in the mapset
- rds.load()
- print "Is raster in db: ", rds.is_in_db()
- if rds.is_in_db():
- rds.select()
- rds.print_self()
- # Remove the entry if it is in the db
- rds.delete()
- rds.reset(ident)
- rds.load()
- # Set the absolute valid time
- rds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
- end_time= datetime(year=2000, month=i + 1, day=1))
- # Insert the map data into the SQL database
- rds.insert()
- # Register the map in the space time raster dataset
- strds.register_map(rds)
- # Print self info
- #rds.print_self()
- strds.update_from_registered_maps()
- strds.select()
- # Print self info
- strds.print_self()
- # Delete the dataset
- strds.delete()
- def test_str3ds_dataset():
-
- name = "str3ds_test_1"
- mapset = grass.gisenv()["MAPSET"]
- print "Create a str3ds object"
- # We need to specify the name and the mapset as identifier
- str3ds = space_time_raster3d_dataset(ident = name + "@" + mapset)
- # Check if in db
- print "Is str3ds in db: ", str3ds.is_in_db()
- # Create a new entry if not in db
- if str3ds.is_in_db() == False:
- str3ds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
- semantic_type="event", title="This is a test space time raster3d dataset", description="A space time raster3d dataset for testing")
- str3ds.insert()
-
- # Reread the data from the db
- str3ds.select()
- # Print self info
- #str3ds.print_self()
- # Create a test maps
- for i in range(11):
- i = i + 1
- grass.raster3d.mapcalc3d("test" + str(i) + " = sin(x()) + cos(y()) + z()", overwrite = True)
-
- name = "test" + str(i)
- mapset = grass.gisenv()["MAPSET"]
- ident = name + "@" + mapset
- print "Create a raster3d object"
- # We need to specify the name and the mapset as identifier
- r3ds = raster3d_dataset(ident)
- # Load data from the raster3d map in the mapset
- r3ds.load()
- print "Is raster3d in db: ", r3ds.is_in_db()
- if r3ds.is_in_db():
- r3ds.select()
- r3ds.print_self()
- # Remove the entry if it is in the db
- r3ds.delete()
- r3ds.reset(ident)
- r3ds.load()
- # Set the absolute valid time
- r3ds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
- end_time= datetime(year=2000, month=i + 1, day=1))
- # Insert the map data into the SQL database
- r3ds.insert()
- # Register the map in the space time raster3d dataset
- str3ds.register_map(r3ds)
- # Print self info
- #r3ds.print_self()
- str3ds.update_from_registered_maps()
- str3ds.select()
- # Print self info
- str3ds.print_self()
- # Delete the dataset
- str3ds.delete()
- def test_stvds_dataset():
- name = "stvds_test_1"
- mapset = grass.gisenv()["MAPSET"]
- print "Create a stvds object"
- # We need to specify the name and the mapset as identifier
- stvds = space_time_vector_dataset(ident = name + "@" + mapset)
- # Check if in db
- print "Is stvds in db: ", stvds.is_in_db()
- # Create a new entry if not in db
- if stvds.is_in_db() == False:
- stvds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
- semantic_type="event", title="This is a test space time vector dataset", description="A space time vector dataset for testing")
- stvds.insert()
- # Reread the data from the db
- stvds.select()
- # Print self info
- #stvds.print_self()
- # Create a test maps
- for i in range(11):
- name = "test" + str(i)
- mapset = grass.gisenv()["MAPSET"]
- ident = name + "@" + mapset
- i = i + 1
- grass.run_command("v.random", output=name, n=100, zmin=0, zmax=100, column="height" ,flags="z" , overwrite = True)
- print "Create a vector object"
- # We need to specify the name and the mapset as identifier
- vds = vector_dataset(ident)
- # Load data from the raster map in the mapset
- vds.load()
- print "Is vector in db: ", vds.is_in_db()
- if vds.is_in_db():
- vds.select()
- vds.print_self()
- # Remove the entry if it is in the db
- vds.delete()
- vds.reset(ident)
- vds.load()
- # Set the absolute valid time
- vds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
- end_time= datetime(year=2000, month=i + 1, day=1))
- # Insert the map data into the SQL database
- vds.insert()
- # Register the map in the space time raster dataset
- stvds.register_map(vds)
- # Print self info
- #vds.print_self()
- stvds.update_from_registered_maps()
- stvds.select()
- # Print self info
- stvds.print_self()
- # Delete the dataset
- stvds.delete()
- test_dict_sql_serializer()
- create_temporal_database()
- #test_dataset_identifer()
- #test_absolute_timestamp()
- #test_relative_timestamp()
- #test_spatial_extent()
- #test_map_metadata()
- #test_base_absolute_time_extent_metadata()
- #test_absolut_time_temporal_relations()
- test_raster_dataset()
- test_raster3d_dataset()
- test_vector_dataset()
- test_strds_dataset()
- test_str3ds_dataset()
- test_stvds_dataset()
- test_increment_datetime_by_string()
|