-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeeMyHouse-CLI.py
121 lines (100 loc) · 3.92 KB
/
SeeMyHouse-CLI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# SeeMyHouse script app
# 1: import statements
# 1.5: global variables
# 2: locally defined functions
# 3: program implementation
import plotly.graph_objects as go
import pandas as pd
import rasterio
import rasterio.windows as rw
import pyproj
# Global variables
path = f""
# Self-defined functions
# Convert degrees, minutes, seconds format coordinates to float
def coordinate_to_float(dms_string):
# split input string
dms_list = dms_string.split(" ")
# assign elements
degrees = float(dms_list[0])
minutes = float(dms_list[1])
seconds = float(dms_list[2])
# conversion calculation
float_coordinate = degrees + (minutes / 60) + (seconds / 3600)
return float_coordinate
# A filepath needs to be provided
# The user can then input a set
# of coordinates provided in WGS84,
# the generally known standard coordinate system
# Welcome statement
print("Welcome to SeeMyHouse")
# Compatibility checks
tiff_available = input("Can you provide your own GeoTIFF file for 3D plotting? (y/n) ")
tiff_crs_compatible = input("Please note that only files"
" using Belgian Lambert crs are \n"
"compatible. That includes the files \n"
"you can download on the geopunt.be website, \n"
"given you use the .tif file found in the \n"
"\"GeoTIFF\" folder of the zip-file.\n"
"Is your file compatible? (y/n) ")
if tiff_available == ("y" or "Y") and tiff_crs_compatible == ("y" or "Y"):
path = input("Please provide the filepath of your GeoTIFF: ")
print(f"Your filepath: {path}")
else:
print("I'm afraid I can't help you yet.")
quit()
# Reading the file into a rasterio object
print("Examining file")
image = rasterio.open(path)
print("File received")
# Coordinate input by user
# Todo delete test values
print("At what coordinates do you want me to look?")
print("Please provide latitude and longitude \n"
"in the following format: degrees minutes seconds \n"
"(separated by spaces, no unit symbols or names)")
latitude = input("Latitude: ")
longitude = input("Longitude: ")
name = input("Give your plot a name: ")
# Conversion to floats
latitude = coordinate_to_float(latitude)
longitude = coordinate_to_float(longitude)
# Convert from WGS84 to Belgian Lambert
converter = pyproj.Transformer.from_crs('epsg:4326', 'epsg:31370')
x, y = converter.transform(latitude, longitude)
# Construct window
# Define borders of window
window_margin = int(input("To zoom in to your house, we would like you \n"
"to estimate how wide or deep it is in metres. \n"
"Use whichever value is the largest, so your whole \n"
"house can fit on the 3D model: "))/2 + 10
left = x - window_margin
right = x + window_margin
bottom = y - window_margin
top = y + window_margin
# Create window object
area_of_interest = image.read(1, window=rw.from_bounds(
left, bottom, right, top,
image.transform))
# Convert to pandas dataframe
heightmap = pd.DataFrame(data=area_of_interest)
# Creating the plotly figure (3D model)
fig = go.Figure(data=[go.Surface(z=heightmap.values,
colorscale="Picnic")])
# Set name and properties for good visual
# The 'aspectmode' in the scene argument makes
# sure the model scales correctly and realistically,
# while 'autosize' is needed to make the plot large enough
# and responsive to browser window size
fig.update_layout(title=name, autosize=True,
scene=dict(aspectmode="data",
xaxis_autorange="reversed"),
)
# Ready prompt
print(f"3D plot ready. Saved as {name}.html.")
# This will save the plot
# to an interactive html file
# and open it in the standard browser
fig.write_html(f'testplots/{name}.html', auto_open=True)
# Always exit with a smile
print("Thank you for using SeeMyHouse!")