Skip to content

Commit 8c09e4b

Browse files
committed
Update to UFG
1 parent d083af8 commit 8c09e4b

9 files changed

Lines changed: 1307 additions & 1 deletion

openudm/RasterToolkit.cpp

Lines changed: 1102 additions & 0 deletions
Large diffs are not rendered by default.

openudm/RasterToolkit.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ struct RTTile {
3737
}
3838
};
3939

40+
//simple tile structure
41+
struct UFTile {
42+
int dph;
43+
int build_cov;
44+
int roads_cov;
45+
int green_cov;
46+
std::string str;
47+
std::string str90;
48+
IRaster ras;
49+
IRaster ras90;
50+
51+
UFTile() {
52+
dph = 0;
53+
build_cov = 0;
54+
roads_cov = 0;
55+
green_cov = 0;
56+
str = "";
57+
str90 = "";
58+
}
59+
};
60+
4061
bool DevCompare(const std::string& iRas1, const std::string& iRas2, const std::string& result);
4162
bool IRasterCompare(const std::string& iRas1, const std::string& iRas2, const std::string& result);
4263
bool DRasterCompare(const std::string& dRas1, const std::string& dRas2, const std::string& result);
@@ -79,4 +100,7 @@ void IRasterToHeader(const std::string& inputRaster, const std::string& outputHe
79100

80101
int ParameterFromHeader(const std::string& header, const std::string& parameter);
81102

82-
void IRasterSetToValue(const std::string& rasterHeader, int value, const std::string& outputRaster);
103+
void IRasterSetToValue(const std::string& rasterHeader, int value, const std::string& outputRaster);
104+
105+
void UFGCoverageFromDensity(const std::string& densityFolder, const std::string& tilesFolder);
106+
void UFGFabricFomCoverage(const std::string& densityFolder, const std::string& tilesFolder);

openudm/Tiles/tiles-detached.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tile_dph,tile_str,tile90_str,pc_build,pc_roads,pc_green
2+
7,D1.asc,D1R.asc,8,14,78
3+
12,D2.asc,D2R.asc,13,14,73
4+
23,D3.asc,D3R.asc,18,22,60
5+
30,D4.asc,D4R.asc,20,24,56

openudm/Tiles/tiles-flats.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tile_dph,tile_str,tile90_str,pc_build,pc_roads,pc_green
2+
77,F1.asc,F1R.asc,20,32,48
3+
101,F2.asc,F2R.asc,21,38,41
4+
164,F3.asc,F3R.asc,27,54,19
5+
216,F4.asc,F4R.asc,27,46,27
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tile_dph,tile_str,tile90_str,pc_build,pc_roads,pc_green
2+
13,S1.asc,S1R.asc,8,16,76
3+
23,S2.asc,S2R.asc,13,19,68
4+
31,S3.asc,S3R.asc,17,22,61
5+
42,S4.asc,S4R.asc,20,30,50

openudm/Tiles/tiles-terraced.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tile_dph,tile_str,tile90_str,pc_build,pc_roads,pc_green
2+
22,T1.asc,T1R.asc,12,25,63
3+
68,T2.asc,T2R.asc,29,32,39
4+
90,T3.asc,T3R.asc,34,43,23
5+
109,T4.asc,T4R.asc,34,51,15

openudm/Tiles/types-vs-density.csv

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
density,detached,semi-detached,terraced,flats
2+
5,77,15,4,4
3+
10,63,24,8,5
4+
15,55,27,13,5
5+
20,48,31,13,8
6+
25,40,34,16,10
7+
30,32,38,19,11
8+
35,23,43,22,12
9+
40,18,41,27,14
10+
45,12,39,31,18
11+
50,10,33,37,20
12+
55,8,29,38,25
13+
60,6,26,43,25
14+
65,5,22,43,30
15+
70,4,20,46,30
16+
75,4,17,44,35
17+
80,3,15,43,39
18+
85,3,14,42,41
19+
90,3,12,42,43
20+
95,2,9,39,50
21+
100,2,9,45,44
22+
100,1,5,23,71

openudm/UFGCoverageFromDensity.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import sys
3+
import csv
4+
import getopt
5+
6+
# import swig-wrapped RasterToolkit as rt
7+
from openudm import (RasterToolkit as rt)
8+
9+
10+
#def urban_fabric_generator_entrypoint():
11+
def ufg_coverage_from_density_entrypoint():
12+
"""
13+
Commandline entrypoint
14+
"""
15+
# default values for required input variables
16+
data_path_tiles = ''
17+
18+
# get args list
19+
args = sys.argv[1:]
20+
21+
# parse passed command line arguments
22+
try:
23+
# e.g. i = input file (colon indicates input expected)
24+
opts, args = getopt.getopt(args, "i:t:", ["input_data_path=", 'tile_data_path='])
25+
except getopt.GetoptError as err:
26+
print(err)
27+
sys.exit(2)
28+
29+
input_data_path = None
30+
tile_data_path = None
31+
32+
# check each passed argument and assign values to variables
33+
for opt, arg in opts:
34+
print(opt)
35+
if opt in ("-i", "input_data_path="):
36+
input_data_path = arg
37+
elif opt in ("-t", 'tile_data_path='):
38+
tile_data_path = arg
39+
else:
40+
print('Un-recognised argument %s' %opt)
41+
sys.exit(2)
42+
43+
if input_data_path is None:
44+
print('Input data path is required')
45+
sys.exit(2)
46+
47+
ufg_coverage_from_density(dph_path=input_data_path, tiles_path=tile_data_path)
48+
49+
50+
#def urban_fabric_generator(dph_path, out_path=None, tiles_path=None):
51+
def ufg_coverage_from_density(dph_path, tiles_path=None):
52+
"""
53+
Runs a function to generate raster files containing urban coverage.
54+
Input data to be in the UDM data dir and output written to same directory.
55+
56+
Inputs:
57+
- dph_path: the path to the folder containing the dph raster
58+
- tiles_path : accepts a file path to a folder which contains the tiles to generate urban coverage.
59+
"""
60+
61+
if tiles_path is None:
62+
tiles_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'Tiles'))
63+
64+
print(tiles_path)
65+
66+
# call wrapped C++ UFG function
67+
rt.UFGCoverageFromDensity(dph_path, tiles_path)
68+
69+
return

openudm/UFGFabricFromCoverage.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import sys
3+
import csv
4+
import getopt
5+
6+
# import swig-wrapped RasterToolkit as rt
7+
from openudm import (RasterToolkit as rt)
8+
9+
10+
#def urban_fabric_generator_entrypoint():
11+
def ufg_fabric_from_coverage_entrypoint():
12+
"""
13+
Commandline entrypoint
14+
"""
15+
# default values for required input variables
16+
data_path_tiles = ''
17+
18+
# get args list
19+
args = sys.argv[1:]
20+
21+
# parse passed command line arguments
22+
try:
23+
# e.g. i = input file (colon indicates input expected)
24+
opts, args = getopt.getopt(args, "i:t:", ["input_data_path=", 'tile_data_path='])
25+
except getopt.GetoptError as err:
26+
print(err)
27+
sys.exit(2)
28+
29+
input_data_path = None
30+
tile_data_path = None
31+
32+
# check each passed argument and assign values to variables
33+
for opt, arg in opts:
34+
print(opt)
35+
if opt in ("-i", "input_data_path="):
36+
input_data_path = arg
37+
elif opt in ("-t", 'tile_data_path='):
38+
tile_data_path = arg
39+
else:
40+
print('Un-recognised argument %s' %opt)
41+
sys.exit(2)
42+
43+
if input_data_path is None:
44+
print('Input data path is required')
45+
sys.exit(2)
46+
47+
ufg_fabric_from_coverage(dph_path=input_data_path, tiles_path=tile_data_path)
48+
49+
50+
#def urban_fabric_generator(dph_path, out_path=None, tiles_path=None):
51+
def ufg_fabric_from_coverage(dph_path, tiles_path=None):
52+
"""
53+
Runs a function to generate a raster file containing urban fabric.
54+
Input data to be in the UDM data dir and output written to same directory.
55+
56+
Inputs:
57+
- dph_path: the path to the folder containing the dph raster
58+
- tiles_path : accepts a file path to a folder which contains the tiles to generate urban coverage.
59+
"""
60+
61+
if tiles_path is None:
62+
tiles_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'Tiles'))
63+
64+
print(tiles_path)
65+
66+
# call wrapped C++ UFG function
67+
rt.UFGFabricFromCoverage(dph_path, tiles_path)
68+
69+
return

0 commit comments

Comments
 (0)