'feature_geomorpho':{'object': feature_geomorpho_var}, \ 'feature_dem':{'function':(lambda y, z: Imagee(*y.get_raster_map()['dem'].clip_by_shape(z)) ),'parameters':['feature_geomorpho','feature_geometry']},\ 'feature_slope':{'function':(lambda y, z: Imagee(*y.get_raster_map()['slope'].clip_by_shape(z)) ),'parameters':['feature_geomorpho','feature_geometry']},\ 'feature_orientation':{'function':(lambda y, z: Imagee(*y.get_raster_map()['orientation'].clip_by_shape(z)) ),'parameters':['feature_geomorpho','feature_geometry']},\ 'feature_twi':{'function':(lambda y, z: Imagee(*y.get_raster_map()['twi'].clip_by_shape(z)) ),'parameters':['feature_geomorpho','feature_geometry']},\ 'feature_soils':{'object': feature_soils}, \ 'feature_aglim1':{'function':(lambda y, z: Imagee(*y.get_raster_map()['aglim1'].clip_by_shape(z)) ),'parameters':['feature_soils','feature_geometry']},\ 'feature_aglim2':{'function':(lambda y, z: Imagee(*y.get_raster_map()['aglim2'].clip_by_shape(z)) ),'parameters':['feature_soils','feature_geometry']},\ 'result_feature':{'function':(lambda r, s, t, u, v, w, x, y, z: FeatureWithRasterMap(data=r, geom=s,id=t,raster_map={'dem':u,'slope':v,'orientation':w,'twi':x,'aglim1':y,'aglim2':z}) ),'parameters':['feature_data','feature_geometry','feature_id','feature_dem', 'feature_slope', 'feature_orientation', 'feature_twi', 'feature_aglim1', 'feature_aglim2']},\ } return t_dict # %% plt.imshow(apply_function( compilable_transformation_dictionary(feature, feature_geomorpho, feature_eu_soils), 'result_feature').get_raster_map()['dem'].get_data(), origin="upper", cmap='gray', interpolation='nearest') plt.colorbar() plt.show() # %% plt.imshow(apply_function( compilable_transformation_dictionary(feature, feature_geomorpho, feature_eu_soils), 'result_feature').get_raster_map()['twi'].get_data(), origin="upper", cmap='gray', interpolation='nearest')
ogr.CreateGeometryFromWkb(geom).ExportToWkt())) parts = corine_layer.GetFeatureCount() number = 100 i = 1 count = 0 j = math.ceil(parts / number) while i < j: for k in range(number): olu_id = next(olu_id_gen) atts_id = next(olu_atts_id_gen) f = corine_layer.GetNextFeature() #[print(i) for i in apply_function(corine_transformations(f,olu_id,atts_id,nuts_id,olu_object_table,olu_attribute_set_table,olu_atts_to_object_table,olu_object_to_admin_unit_table),'four_insert_statements')] [ olu_cur.execute(i) for i in apply_function( corine_transformations( f, olu_id, atts_id, nuts_id, olu_object_table, olu_attribute_set_table, olu_atts_to_object_table, olu_object_to_admin_unit_table), 'four_insert_statements') ] count += 1 olu_conn.commit() i += 1 for k in range(parts - count): olu_id = next(olu_id_gen) atts_id = next(olu_atts_id_gen) f = corine_layer.GetNextFeature() [ olu_cur.execute(i) for i in apply_function( corine_transformations( f, olu_id, atts_id, nuts_id, olu_object_table,
admunit_cz.get_attributes(), data_source=DataSource( admunit_cz.get_data_source().get_type(), admunit_cz.get_data_source().get_name(), ({ **admunit_cz.get_data_source().get_attributes(), **{ 'layer': l } }), None, admunit_cz.get_data_source().get_data_file()), supergeoconcept=admunit_cz, table_inheritance=False, type='semantic', subgeoconcepts=[])) G = apply_function(compilable_node_dictionary(admunit_cz), 'admunit__tree') eudem_cz__metadata = MetaData('EU DEM in Czech Republic', { "local": "/home/jupyter-dima/eu_dem_czat3035.tif", "format": "GTiff" }, 'raster data') eudem_cz_ds = ds_from_metadata(eudem_cz__metadata) eudem_cz = GeoConcept('EU DEM in Czech Republic', 'EU DEM in Czech Republic.', 'Feature', json_feature_with_raster_structure, data_source=eudem_cz_ds, subgeoconcepts=[]) eudem_cz.set_raster_output_backend( '', eudem_cz.get_data_source().get_attributes()['local'])
return t_dict # %% sentinel_im=FeatureWithRasterMap(data={},geom=('POLYGON ((%d %d, %d %d, %d %d, %d %d, %d %d))' % (geom_utm_envelope[0],geom_utm_envelope[2],geom_utm_envelope[0],geom_utm_envelope[3],geom_utm_envelope[1],geom_utm_envelope[3],geom_utm_envelope[1],geom_utm_envelope[2],geom_utm_envelope[0],geom_utm_envelope[2])),id=1,raster_map={'im_band2':im,'im_band4':im_b4,'im_band8':im_b8}) # %% features=fields.read_features_from_geojson_output_backend('feature',number=10) # %% with open('testovaci.geojson', 'w', encoding='utf-8') as file: geojson={"type": "FeatureCollection", "features": [] } for f in features: for ff in f: if len(ff)>0: for fff in ff: geojson["features"].append(apply_function(compilable_transformation_dictionary(fff,sentinel_im,utm32635_to_wgs84),'result_feature').export_to_geojson()) json.dump(geojson, file, ensure_ascii=False, indent=4) # %% from ipyleaflet import Map, GeoJSON m = Map(center=(ogr.CreateGeometryFromWkt(transform_wkt_geometry(sentinel_im.get_geometry(),utm32635_to_wgs84)).Centroid().GetY(),ogr.CreateGeometryFromWkt(transform_wkt_geometry(sentinel_im.get_geometry(),utm32635_to_wgs84)).Centroid().GetX()), zoom=14) # %% geo_json = GeoJSON(data=geojson, style = {'color': 'green'}) m.add_layer(geo_json) # %% m # %% for feature in geojson['features']:
scheme='public', conflict='append') # %% url_adresa = lpis_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]) lpis_cz.get_data_source().set_attribute({'url': url_adresa}) del (url_adresa) # %% for i in re.findall('\{.*?\}', lpis_cz.get_data_source().get_attributes()['url']): if i[1:-1] in list(compilable_tree_dictionary(admunit_cz).keys()): for j in apply_function(compilable_tree_dictionary(admunit_cz), i[1:-1]): lpis_cz.append_subgeoconcept( SubGeoConcept( str(j), 'LPIS in Czech administrative territorial unit %s ' % str(j), 'Feature', lpis_cz.get_attributes(), data_source=DataSource( lpis_cz.get_data_source().get_type(), lpis_cz.get_data_source().get_name(), (dict( lpis_cz.get_data_source().get_attributes(), **{ 'url': lpis_cz.get_data_source().get_attributes() ['url'].replace(i, str(j)) })), None, None),
def transform(self, dictionary_key): concept = apply_function(self._dictionary, dictionary_key) return concept
def generate_olu_reference_geometries(kod_obce, theme, generate_inherited_tables=False): if generate_inherited_tables==True: dbs_olu.execute('create table if not exists olu_object.%s () inherits (olu2.olu_object)' % transform_name_to_postgresql_format(kod_obce)) dbs_olu.execute('create table if not exists olu_attribute_set.%s () inherits (olu2.olu_attribute_set)' % transform_name_to_postgresql_format(kod_obce)) dbs_olu.execute('create table if not exists atts_to_object.%s () inherits (olu2.atts_to_object)' % transform_name_to_postgresql_format(kod_obce)) olu_object_table='olu_object.%s' % transform_name_to_postgresql_format(kod_obce) olu_attribute_set_table='olu_attribute_set.%s' % transform_name_to_postgresql_format(kod_obce) olu_atts_to_object_table='atts_to_object.%s' % transform_name_to_postgresql_format(kod_obce) olu_objects_union_cascaded=ogr.CreateGeometryFromWkt('MULTIPOLYGON EMPTY') ku=find_neighbors_level(G.reverse(),kod_obce,4) while True: try: cislo_ku=next(ku) print(cislo_ku) sub=lpis_cz.get_subgeoconcept_by_adm_node(cislo_ku) print(sub.get_name()) lpis_feature_gen=sub.read_features_from_table(100) for feature_batch in lpis_feature_gen: if len(feature_batch)>0: print(len(feature_batch)) for feature in feature_batch: feature.transform_geometry(sjtsk5514_to_wgs84) olu_id=next(olu_id_gen) atts_id=next(olu_atts_id_gen) [dbs_olu.execute(i) for i in apply_function(lpis_transformations(feature,olu_id,atts_id,kod_obce,olu_object_table,olu_attribute_set_table,olu_atts_to_object_table),'three_insert_statements')] else: break except: print('no next feature') break obec_gen=admunit_cz.read_features_from_table_by_sqlcondition('id=%s' %kod_obce,1) obec=next(obec_gen)[0] obec_area=ogr.CreateGeometryFromWkb(obec.get_geometry()).Area() try: olu_objects_union=ogr.CreateGeometryFromWkb(dbs_olu.execute("select st_asbinary(st_union(geom)) from %s where admunit_id='%s'" % ('olu2.olu_object',kod_obce))[0][0]) olu_objects_union.Transform(wgs84_to_sjtsk5514) if abs(obec_area-olu_objects_union.Area())<100: return None olu_objects_union_cascaded=olu_objects_union#olu_objects_union.UnionCascaded() del(olu_objects_union) print(olu_objects_union_cascaded.Area()) print(ogr.CreateGeometryFromWkb(obec.get_geometry()).Area()) except: dbs_olu.disconnect() dbs_olu.connect() ruian_features_gen=ruian_parcely_cz.get_subgeoconcept_by_name(kod_obce).read_features_from_table_by_sqlcondition("st_intersects(geom,st_setsrid(st_geomfromtext('%s'),5514))" % (ogr.CreateGeometryFromWkb(obec.get_geometry()).Difference(olu_objects_union_cascaded).ExportToWkt()) ,1000) for feature_batch in ruian_features_gen: print(len(feature_batch)) if len(feature_batch)>0: for feature in feature_batch: feature.transform_geometry(sjtsk5514_to_wgs84) olu_id=next(olu_id_gen) atts_id=next(olu_atts_id_gen) [dbs_olu.execute(i) for i in apply_function(ruian_transformations(feature,olu_id,atts_id,kod_obce,olu_object_table,olu_attribute_set_table,olu_atts_to_object_table),'three_insert_statements')] else: break try: olu_objects_union=ogr.CreateGeometryFromWkb(dbs_olu.execute("select st_asbinary(st_union(geom)) from %s where admunit_id='%s'" % ('olu2.olu_object',kod_obce))[0][0]) olu_objects_union.Transform(wgs84_to_sjtsk5514) if abs(obec_area-olu_objects_union.Area())<100: return None olu_objects_union_cascaded=olu_objects_union#olu_objects_union.UnionCascaded() del(olu_objects_union) print(olu_objects_union_cascaded.Area()) except: dbs_olu.disconnect() dbs_olu.connect() if ogr.CreateGeometryFromWkb(obec.get_geometry()).Difference(olu_objects_union_cascaded) is None: return None ua_features_gen=ua_cz.read_features_from_table_by_sqlcondition("st_intersects(geom,st_transform(st_setsrid(st_geomfromtext('%s'),5514),3035)) and data->>'CODE2012' not in ('12210','12220','12230')" % (ogr.CreateGeometryFromWkb(obec.get_geometry()).Difference(olu_objects_union_cascaded).ExportToWkt()) ,100) for feature_batch in ua_features_gen: print(len(feature_batch)) if len(feature_batch)>0: for feature in feature_batch: feature.transform_geometry(etrs3035_to_wgs84) olu_id=next(olu_id_gen) atts_id=next(olu_atts_id_gen) [dbs_olu.execute(i) for i in apply_function(ua_transformations(feature,olu_id,atts_id,kod_obce,olu_object_table,olu_attribute_set_table,olu_atts_to_object_table),'three_insert_statements')] else: break try: olu_objects_union=ogr.CreateGeometryFromWkb(dbs_olu.execute("select st_asbinary(st_union(geom)) from %s where admunit_id='%s'" % ('olu2.olu_object',kod_obce))[0][0]) olu_objects_union.Transform(wgs84_to_sjtsk5514) if abs(obec_area-olu_objects_union.Area())<100: return None olu_objects_union_cascaded=olu_objects_union#olu_objects_union.UnionCascaded() del(olu_objects_union) print(olu_objects_union_cascaded.Area()) except: dbs_olu.disconnect() dbs_olu.connect() if ogr.CreateGeometryFromWkb(obec.get_geometry()).Difference(olu_objects_union_cascaded) is None: return None corine_features_gen=corine_cz.get_subgeoconcept_by_name('2018').read_features_from_table_by_sqlcondition("st_intersects(geom,st_transform(st_setsrid(st_geomfromtext('%s'),5514),4326))" % (ogr.CreateGeometryFromWkb(obec.get_geometry()).Difference(olu_objects_union_cascaded).ExportToWkt()) ,10) for feature_batch in corine_features_gen: print(len(feature_batch)) if len(feature_batch)>0: for feature in feature_batch: feature.transform_geometry(wgs84_to_wgs84) olu_id=next(olu_id_gen) atts_id=next(olu_atts_id_gen) [dbs_olu.execute(i) for i in apply_function(corine_transformations(feature,olu_id,atts_id,kod_obce,olu_object_table,olu_attribute_set_table,olu_atts_to_object_table),'three_insert_statements')] else: break
'Vusc':{'level_value':1,'parent_value':'1','id_attribute':'Kod'}, 'Okresy':{'level_value':2,'parent_attribute':'VuscKod','id_attribute':'Kod'}, 'Obce':{'level_value':3,'parent_attribute':'OkresKod','id_attribute':'Kod'}, 'KatastralniUzemi':{'level_value':4,'parent_attribute':'ObecKod','id_attribute':'Kod'}} for l in list(set(concept_list).intersection(set(admunit_cz.get_data_source().list_layers()))): admunit_cz.append_subgeoconcept(SubGeoConcept(l,l,'AdmUnitFeature',admunit_cz.get_attributes(),data_source=DataSource(admunit_cz.get_data_source().get_type(),admunit_cz.get_data_source().get_name(),({**admunit_cz.get_data_source().get_attributes(),**{'layer':l}}),None,admunit_cz.get_data_source().get_data_file()),supergeoconcept=admunit_cz,table_inheritance=False,type='semantic',subgeoconcepts=[])) # %% concept_list=['Parcely'] concept_additional_attributes={'Parcely':{'id_attribute':'Id'}} for i in re.findall('\{.*?\}',ruian_parcely_cz.get_data_source().get_attributes()['url']): if i[1:-1] in list(compilable_tree_dictionary(admunit_cz).keys()): for j in apply_function(compilable_tree_dictionary(admunit_cz),i[1:-1]): ruian_parcely_cz.append_subgeoconcept(SubGeoConcept(str(j),'RUIAN land parcels in Czech administrative territorial unit %s ' % str(j),'FeatureWithID',ruian_parcely_cz.get_attributes(),data_source=DataSource(ruian_parcely_cz.get_data_source().get_type(),ruian_parcely_cz.get_data_source().get_name(),(dict(ruian_parcely_cz.get_data_source().get_attributes(),**{'url':ruian_parcely_cz.get_data_source().get_attributes()['url'].replace(i,str(j))})),None,None),supergeoconcept=ruian_parcely_cz,table_inheritance=True,subgeoconcepts=[])) # %% for i in re.findall('\{.*?\}',lpis_cz.get_data_source().get_attributes()['url']): if i[1:-1] in list(compilable_tree_dictionary(admunit_cz).keys()): for j in apply_function(compilable_tree_dictionary(admunit_cz),i[1:-1]): lpis_cz.append_subgeoconcept(SubGeoConcept(str(j),'LPIS in Czech administrative territorial unit %s ' % str(j),'FeatureWithID',lpis_cz.get_attributes(),data_source=DataSource(lpis_cz.get_data_source().get_type(),lpis_cz.get_data_source().get_name(),(dict(lpis_cz.get_data_source().get_attributes(),**{'url':lpis_cz.get_data_source().get_attributes()['url'].replace(i,str(j))})),None,None),supergeoconcept=lpis_cz,table_inheritance=True,subgeoconcepts=[],type='spatial:admin',adm_graph_node=str(j))) # %% concept_list=[re.search('_.*_',file)[0][1:-1] for file in os.listdir('.') if file.endswith('.zip') and file.startswith('CZ')] for concept in concept_list: for i in re.findall('\{.*?\}',ua_cz.get_data_source().get_attributes()['layer']): if i.split(':')[1][:-1] in list((compilable_ua_dictionary('')).keys()): geoconcept=SubGeoConcept('%s' % concept,'Urban Atlas in agglomeration %s ' % str(concept),'FeatureWithID',ua_cz.get_attributes(),data_source=DataSource(ua_cz.get_data_source().get_type(), ua_cz.get_data_source().get_name(),(ua_cz.get_data_source().get_attributes()),None,None),supergeoconcept=ua_cz,table_inheritance=True,subgeoconcepts=[])