"name": "geom",
    "type": "geometry"
}, {
    "name": "data",
    "type": "json"
}, {
    "name": "raster_maps",
    "type": "raster"
}]
osm_africa_metadata = MetaData(
    'OSM database for Africa', {
        "url": "http://download.geofabrik.de/africa-latest.osm.pbf",
        "format": "pbf",
        "downloadable": "free"
    }, 'data')
osm_africa__ds = ds_from_metadata(osm_africa_metadata)
osm_africa = GeoConcept('OSM database for Africa',
                        'OSM database for Africa.',
                        'Feature',
                        json_feature_structure,
                        subgeoconcepts=[],
                        data_source=osm_africa__ds)
osm_africa_metadata.set_metatable(metadata_table)
osm_africa_metadata.set_validitydates(['2021-01-01', '2121-01-01'])
metadata_fid_sequence = sequence_generator(
    dbs.get_last_value_of_seq(
        osm_africa_metadata.get_metatable().get_self_sequence_name('fid'),
        set_last_value=True,
        data_table=osm_africa_metadata.get_metatable().get_scheme() + '.' +
        osm_africa_metadata.get_metatable().get_name(),
        id_attribute='fid'))
        ds = gdal.Open('%s/twi.tif' % tempdir)
        metadata_dict = im_object.get_metadata()
        twi = Imagee(np.array(ds.GetRasterBand(1).ReadAsArray()),
                     metadata_dict)
        return twi


# %%
fields_metadata = MetaData(
    'Pessl fields database', {
        "local":
        "/home/jovyan/public/shared/Scenario5/Field_borders/Field035.geojson",
        "format": "GeoJSON"
    }, 'data')

fields_ds = ds_from_metadata(fields_metadata)

fields = GeoConcept('Pessl fields',
                    'Fields of farmers that are using Pessl instruments',
                    'Feature',
                    json_feature_structure,
                    data_source=fields_ds,
                    subgeoconcepts=[])

# %%
fields.get_data_source().set_data_file(
    '/home/jovyan/public/shared/Scenario5/Field_borders/Field035.geojson')

# %%
features = fields.get_data_source().read_features('feature', number=1)
feature = next(features)[0]
dbs_olu_connection = {**{'dbname': 'oluv20'}, **connectionstring_localhost}
dbs_olu = DBStorage(dbs_olu_connection)
dbs_olu.connect()
dbs_olu.disconnect()
dbs_olu.connect()

admunit_cz__metadata = MetaData(
    'Administrative units in Czech Republic', {
        "url":
        "https://vdp.cuzk.cz/vymenny_format/soucasna/[posledni_den_mesice]_ST_UKSG.xml.zip",
        "format": "GML",
        "compression": "zip"
    }, 'data')

admunit_cz__ds = ds_from_metadata(admunit_cz__metadata)

admunit_cz = GeoConcept('Administrative units in Czech Republic',
                        'Administrative units in Czech Republic. All levels.',
                        'AdmUnitFeature',
                        json_admin_unit_structure,
                        data_source=admunit_cz__ds,
                        subgeoconcepts=[])

url_adresa = admunit_cz.get_data_source().get_attributes()['url']
for i in re.findall('\[.*?\]', url_adresa):
    if i in list(replacement_dictionary.keys()):
        url_adresa = url_adresa.replace(i, replacement_dictionary[i])
admunit_cz.get_data_source().set_attribute({'url': url_adresa})
del (url_adresa)
Exemple #4
0
}, {
    "name": "raster_maps",
    "type": "raster"
}]

# %%
admunit_cz__metadata = MetaData(
    'Administrative units in Czech Republic', {
        "url":
        "https://vdp.cuzk.cz/vymenny_format/soucasna/[posledni_den_mesice]_ST_UKSG.xml.zip",
        "format": "GML",
        "compression": "zip"
    }, 'data')

# %%
admunit_cz__ds = ds_from_metadata(admunit_cz__metadata)
admunit_cz = GeoConcept('Administrative units in Czech Republic',
                        'Administrative units in Czech Republic. All levels.',
                        'AdmUnitFeature',
                        json_admin_unit_structure,
                        data_source=admunit_cz__ds,
                        subgeoconcepts=[])

# %%
url_adresa = admunit_cz.get_data_source().get_attributes()['url']
for i in re.findall('\[.*?\]', url_adresa):
    if i in list(replacement_dictionary.keys()):
        url_adresa = url_adresa.replace(i, replacement_dictionary[i])

admunit_cz.get_data_source().set_attribute({'url': url_adresa})
del (url_adresa)
# %%
replacement_dictionary = {"[posledni_den_mesice]":(datetime.datetime.today().replace(day=1)-datetime.timedelta(days=1)).strftime('%Y%m%d'),"[lpis_cz__posledni_aktualizace]":lpis_cz__posledni_aktualizace().strftime('%Y%m%d'), "[vcera]":(datetime.datetime.today().replace(day=1)-datetime.timedelta(days=1)).strftime('%Y%m%d')} 
json_feature_structure=[{"name":"id","type":"serial primary key"},{"name":"geom","type":"geometry"},{"name":"data","type":"json"}]
json_feature_with_bigid_structure=[{"name":"id","type":"bigint primary key"},{"name":"geom","type":"geometry"},{"name":"data","type":"json"}]
json_admin_unit_structure=[{"name":"id","type":"integer primary key"},{"name":"geom","type":"geometry"},{"name":"data","type":"json"},{"name":"level","type":"integer"},{"name":"parent_id","type":"text"}]
json_admin_unit_structure_at=[{"name":"id","type":"text primary key"},{"name":"geom","type":"geometry"},{"name":"data","type":"json"},{"name":"level","type":"integer"},{"name":"parent_id","type":"text"}]
json_feature_with_raster_structure=[{"name":"id","type":"serial primary key"},{"name":"geom","type":"geometry"},{"name":"data","type":"json"},{"name":"raster_maps","type":"raster"}]

# %%
admunit_cz__metadata=MetaData('Administrative units in Czech Republic',
                              {"url":"https://vdp.cuzk.cz/vymenny_format/soucasna/[posledni_den_mesice]_ST_UKSG.xml.zip",
                               "format":"GML", "compression":"zip"},'data')

# %%
admunit_cz__ds=ds_from_metadata(admunit_cz__metadata)
admunit_cz=GeoConcept('Administrative units in Czech Republic','Administrative units in Czech Republic. All levels.',
                      'AdmUnitFeature',json_admin_unit_structure, data_source=admunit_cz__ds, subgeoconcepts=[] )

# %%
url_adresa=admunit_cz.get_data_source().get_attributes()['url']
for i in re.findall('\[.*?\]',url_adresa):
    if i in list(replacement_dictionary.keys()):
        url_adresa=url_adresa.replace(i,replacement_dictionary[i])
        
admunit_cz.get_data_source().set_attribute({'url':url_adresa})
del(url_adresa)

# %%
#admunit_cz.get_data_source().download_data('archive.zip',s,'all',os.getcwd())
admunit_cz.get_data_source().set_data_file('20201031_ST_UKSG.xml')
Exemple #6
0
}, {
    "name": "raster_maps",
    "type": "raster"
}]

# %%
admunit_cz__metadata = MetaData(
    'Administrative units in Czech Republic', {
        "url":
        "https://vdp.cuzk.cz/vymenny_format/soucasna/[posledni_den_mesice]_ST_UKSG.xml.zip",
        "format": "GML",
        "compression": "zip"
    }, 'data')

# %%
admunit_cz__ds = ds_from_metadata(admunit_cz__metadata)
admunit_cz = GeoConcept('Administrative units in Czech Republic',
                        'Administrative units in Czech Republic. All levels.',
                        'AdmUnitFeature',
                        json_admin_unit_structure,
                        data_source=admunit_cz__ds,
                        subgeoconcepts=[])

# %%
url_adresa = admunit_cz.get_data_source().get_attributes()['url']
for i in re.findall('\[.*?\]', url_adresa):
    if i in list(replacement_dictionary.keys()):
        url_adresa = url_adresa.replace(i, replacement_dictionary[i])

admunit_cz.get_data_source().set_attribute({'url': url_adresa})
del (url_adresa)
    delete from tanzania_lc.unit_%s where id in \
    (select a.id from tanzania_lc.unit_%s a, admunits b where st_area(st_intersection(a.geom, b.geom))<1 and b.id=%s);\
    " % (adm_unit_id, adm_unit_id, adm_unit_id))
    olu_conn.commit()

olu_cur.execute(
    "SELECT table_name FROM information_schema.tables WHERE table_schema = 'tanzania_lc'"
)

tables = [str(i[0]) for i in olu_cur.fetchall()]

cci20__metadata = MetaData('CCI 20 meter African Land Cover map', {
    "local": "osm_africa/cci_tanzania_3857_2020.tif",
    "format": "GTiff"
}, 'raster')
cci20__ds = ds_from_metadata(cci20__metadata)
cci20 = GeoConcept('CCI 20 meter African Land Cover map',
                   'CCI 20 meter African Land Cover map by ESA. ',
                   'Feature',
                   json_feature_with_raster_structure,
                   data_source=cci20__ds,
                   subgeoconcepts=[])
cci20.set_raster_output_backend(
    '',
    cci20.get_data_source().get_attributes()['local'])

olu_cur.execute(
    'create table tanzania_lc_atts (id integer, lc_class integer, frequency numeric(5,2))'
)

olu_conn.commit()