Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions download_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"MV": None,
"NI": None,
"NW": "https://www.opengeodata.nrw.de/produkte/geobasis"
"/lk/akt/hu_shp/hu_EPSG4647_Shape.zip",
"/lk/akt/gru_vereinfacht_gpkg/gru_vereinf_05314000_Bonn_EPSG25832_GeoPackage.zip",
"RP": None,
"SL": None,
"SN": "https://geocloud.landesvermessung.sachsen.de/index.php/s"
Expand All @@ -54,7 +54,7 @@
"HE": "gebaeude-he.shp",
"MV": None,
"NI": None,
"NW": "hu_shp.shp",
"NW": "202601_gru_vereinf_05314000_Bonn_EPSG25832.gpkg",
"RP": None,
"SL": None,
"SN": "hu_sn_gebaeude_20240118.shp",
Expand All @@ -63,6 +63,10 @@
"TH": "gebaeude-th.shp",
}

BUILDINGS_LAYERS = {
"NW": "GebauedeBauwerk",
}

BB_districts = {
"BAR": "Barnim",
"BRB": "Brandenburg an der Havel",
Expand Down
2 changes: 1 addition & 1 deletion testsuite/data/test_aoi_NW.geojson
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[6.955032348632812,50.94544969875718],[6.933231353759766,50.935714552368594],[6.957607269287109,50.92998067919713],[6.961212158203125,50.937445394034576],[6.955032348632812,50.94544969875718]]]}}]}
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[7.090,50.750],[7.090,50.710],[7.155,50.710],[7.155,50.750],[7.090,50.750]]]}}]}
28 changes: 18 additions & 10 deletions testsuite/v_alkis_buildings_import_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ def setUpClass(cls):
# set region
grass.run_command("g.region", vector=cls.aoi_map, flags="a")
if cls.east == "" and cls.west == "":
grass.run_command("g.region", n="n+200", s="n-100", w="e-100")
grass.run_command(
"g.region", n="n+200", s="s-100", w="w-100", e="e+100"
)
else:
grass.run_command(
"g.region", n="n+200", s="n-100", w=cls.west, e=cls.east
"g.region", n="n+200", s="s-100", w=cls.west, e=cls.east
)

def option_aoi_map(self):
Expand Down Expand Up @@ -161,20 +163,26 @@ def flag(self):
self.assertTrue(
"AGS" in atr[1], "Module failed, because of missins key 'AGS'"
)
# check extend of output (data should overlap with 50 percent of the
# region)
# check that output extent overlaps with at least 50% of the region
out_data_reg = grass.parse_command(
"v.info", map=self.test_output, flags="g"
)
g_reg = grass.region()
overlap_e = min(float(out_data_reg["east"]), g_reg["e"])
overlap_w = max(float(out_data_reg["west"]), g_reg["w"])
overlap_n = min(float(out_data_reg["north"]), g_reg["n"])
overlap_s = max(float(out_data_reg["south"]), g_reg["s"])
if overlap_e > overlap_w and overlap_n > overlap_s:
overlap_area = (overlap_e - overlap_w) * (overlap_n - overlap_s)
region_area = (g_reg["e"] - g_reg["w"]) * (g_reg["n"] - g_reg["s"])
overlap_pct = overlap_area / region_area * 100
else:
overlap_pct = 0
self.assertTrue(
(
abs(float(out_data_reg["north"]) - g_reg["n"]) < 25
and abs(float(out_data_reg["south"]) - g_reg["s"]) < 25
and abs(float(out_data_reg["east"]) - g_reg["e"]) < 25
and abs(float(out_data_reg["west"]) - g_reg["w"]) < 25
overlap_pct > 50,
"Output data overlaps only {:.0f}% of the region".format(
overlap_pct
),
"Output data extend is wrong.",
)

print(f"Running test for {self.fs} region flag done.")
Expand Down
31 changes: 15 additions & 16 deletions v.alkis.buildings.import.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
from download_urls import (
URLS,
BUILDINGS_FILENAMES,
BUILDINGS_LAYERS,
BB_districts,
download_dict,
)
Expand Down Expand Up @@ -332,7 +333,7 @@ def download_alkis_buildings(fs, url):


def import_single_alkis_source(
alkis_source, aoi_map, load_region, output_alkis, f_state
alkis_source, aoi_map, load_region, output_alkis, f_state, layer=None
):
"""Importing single ALKIS source"""
alkis_source_fixed = alkis_source
Expand Down Expand Up @@ -362,23 +363,23 @@ def import_single_alkis_source(
if f_state == "Thüringen":
snap = 0.1

vimport_opts = dict(
input=alkis_source_fixed,
snap=snap,
quiet=True,
)
if layer:
vimport_opts["layer"] = layer

if aoi_map:
# set region to aoi_map
grass.run_command("g.region", vector=aoi_map, quiet=True)
# if grass.find_file(
# name=OUTPUT_ALKIS_TEMP, element="vector"
# )["file"] != "":
# import pdb; pdb.set_trace()
# OUTPUT_ALKIS_TEMP += "_2"
# rm_vectors.append(OUTPUT_ALKIS_TEMP)
grass.run_command(
"v.import",
input=alkis_source_fixed,
output=OUTPUT_ALKIS_TEMP,
snap=snap,
extent="region",
quiet=True,
overwrite=True,
**vimport_opts,
)
grass.run_command(
"v.clip",
Expand All @@ -391,19 +392,15 @@ def import_single_alkis_source(
elif load_region:
grass.run_command(
"v.import",
input=alkis_source_fixed,
output=output_alkis,
snap=snap,
extent="region",
quiet=True,
**vimport_opts,
)
else:
grass.run_command(
"v.import",
input=alkis_source_fixed,
output=output_alkis,
snap=snap,
quiet=True,
**vimport_opts,
)


Expand Down Expand Up @@ -701,13 +698,15 @@ def main():

# import to GRASS DB
grass.message(_(f"Importing ALKIS buildings data ({fs})..."))
layer_name = BUILDINGS_LAYERS.get(fs)
if isinstance(alkis_source, str):
import_single_alkis_source(
alkis_source,
aoi_map,
load_region,
output_alkis_fs,
federal_state,
layer=layer_name,
)
else:
import_shapefiles(alkis_source, output_alkis_fs, aoi_map)
Expand Down
Loading