Skip to content

Commit

Permalink
nå tror jeg alt funker?
Browse files Browse the repository at this point in the history
  • Loading branch information
springvalley committed Feb 19, 2024
1 parent 64b68b4 commit adb66c9
Show file tree
Hide file tree
Showing 45 changed files with 22 additions and 28 deletions.
16 changes: 7 additions & 9 deletions WMS/Ortofoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from dotenv import load_dotenv
import json

def generate_orto():
def generate_orto_picture():
# Finner path til .env filen som ligger i ngisopenapi mappen
current_script_directory = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(current_script_directory, '..', 'ngisopenapi'))
env_file_path = os.path.join(project_root, '.env')

coordinates_file_path = os.path.join(current_script_directory, 'resources', 'coordinates.json')
# Laster .env fra riktig path
load_dotenv(env_file_path)

Expand All @@ -34,13 +34,13 @@ def generate_orto():
bbox = f'{min_x},{min_y},{max_x},{max_y}'

# Setter directory for lagring av bilde
images_directory = "ortofoto_images"
images_directory = "rawphotos"

# Lager hele pathen i samme mappe
images_directory_path = os.path.join(current_script_directory, images_directory)

# Sjekker om filen eksisterer
os.makedirs(images_directory_path, exist_ok=True)
#os.makedirs(images_directory_path, exist_ok=True)

# Angi hvilke layers, bbox og hva enn du er interessert i
params = {
Expand All @@ -58,8 +58,6 @@ def generate_orto():

# Build and print the full URL
full_url = f"{wms_url}?{encoded_params}"
print("Generated URL:")
print(full_url)

# Headers som legger en browser request
headers = {
Expand All @@ -68,11 +66,11 @@ def generate_orto():

# Oppretter en get request til WMS serveren gjennom url og api nøkkel
response = requests.get(full_url, headers=headers) # Ensure the request is made to `full_url`

print("HELLO");
if response.status_code == 200:
# Genererer et filnavn basert på dato og tid bildet ble hentet på
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
file_name = f"output_{timestamp}.png"
#timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
file_name = f"orto.png"

# Hele fil pathen
image_path = os.path.join(images_directory_path, file_name)
Expand Down
19 changes: 7 additions & 12 deletions WMS/Sanderscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def generate_wms_picture():
bbox = f'{min_x},{min_y},{max_x},{max_y}'

# Velger et sted å lagre bildene
images_directory = "Fasitfoto"
images_directory = "rawphotos"

# Lagrer alt i mappen definert
images_directory_path = os.path.join(images_directory)
images_directory_path = os.path.join(current_script_directory, images_directory)

# Sjekker om filen eksisterer
os.makedirs(images_directory_path, exist_ok=True)
#os.makedirs(images_directory_path, exist_ok=True)

# WMS parametere, de tomme feltene blir definert videre i koden
wms_params = {
Expand All @@ -54,8 +54,7 @@ def generate_wms_picture():
'sld_body': ''
}

# Spør som en input hvilket "Layers brukeren vil se"
layer_names = input("Enter LAYERS (layer names, comma-separated if multiple, Current layers are: veg,bru,bygning): ")
layer_names = "bygning"
wms_params['LAYERS'] = layer_names

# Starter SLD body
Expand Down Expand Up @@ -95,20 +94,17 @@ def generate_wms_picture():

# Bygger og printer URLen med de riktige definerte WMS parameterene
full_url = f"{base_url}?{encoded_params}"
print("Generated URL:")
print(full_url)

# Headers som lager en browser request
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}

response = requests.get(full_url, headers=headers)

if response.status_code == 200:
# Genererer et filnavn basert på dato og tid bildet ble hentet på
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
file_name = f"output_{timestamp}.png"
#timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
file_name = f"fasit.png"

# Hele fil pathen
image_path = os.path.join(images_directory_path, file_name)
Expand All @@ -118,5 +114,4 @@ def generate_wms_picture():
print(f"Bildet ble lagret i {image_path}.")
else:
print(f"Kunne ikke lagre bilde, statuskode: {response.status_code}")

generate_wms_picture()

2 changes: 1 addition & 1 deletion WMS/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def split_image(image_path, output_folder, tile_size):
tile.save(f"{output_folder}/tile_{i}_{i}.png")

#Return the amount of tiles created
return horizontal_tiles + vertical_tiles
return horizontal_tiles


def split_files(image_path, output_folder, tiles, training_fraction, validation_fraction):
Expand Down
Binary file added WMS/__pycache__/ortofoto.cpython-311.pyc
Binary file not shown.
Binary file added WMS/__pycache__/sanderscript.cpython-311.pyc
Binary file not shown.
Binary file modified WMS/__pycache__/util.cpython-311.pyc
Binary file not shown.
Binary file added WMS/email/train/images/tile_0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WMS/email/train/images/tile_10_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WMS/email/train/images/tile_11_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_1_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_2_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_3_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_4_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_5_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_6_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_7_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/images/tile_8_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WMS/email/train/images/tile_9_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WMS/email/train/masks/tile_0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WMS/email/train/masks/tile_10_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WMS/email/train/masks/tile_11_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_1_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_2_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_3_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_4_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_5_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_6_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_7_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified WMS/email/train/masks/tile_8_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WMS/email/train/masks/tile_9_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed WMS/email/val/images/tile_0_0.png
Binary file not shown.
Binary file added WMS/email/val/images/tile_12_12.png
Binary file added WMS/email/val/images/tile_13_13.png
Binary file added WMS/email/val/images/tile_14_14.png
Binary file added WMS/email/val/images/tile_15_15.png
Binary file removed WMS/email/val/masks/tile_0_0.png
Diff not rendered.
Binary file added WMS/email/val/masks/tile_12_12.png
Binary file added WMS/email/val/masks/tile_13_13.png
Binary file added WMS/email/val/masks/tile_14_14.png
Binary file added WMS/email/val/masks/tile_15_15.png
Binary file modified WMS/rawphotos/fasit.png
Binary file modified WMS/rawphotos/orto.png
2 changes: 1 addition & 1 deletion WMS/resources/config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Config": {"data_parameters": ["90", "10", "10"], "layers": ["Bygning", "Veg", "Bru"], "colors": ["#000000", "#ffff00", "#00ff00"]}}
{"Config": {"data_parameters": ["70", "30", "10"], "layers": ["Bygning", "Veg", "Bru"], "colors": ["#000000", "#ffff00", "#00ff00"]}}
Binary file modified __pycache__/main.cpython-311.pyc
Binary file not shown.
11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from pydantic import BaseModel
from deleteFolder import delete_all_folders
from WMS import util
from WMS import Orotfoto
from WMS import ortofoto
from WMS import sanderscript


# Class for the FastAPI. Will contain all our methods for updating values and starting scripts
Expand Down Expand Up @@ -321,13 +322,13 @@ async def generatePhotos():
config = data["Config"];


#Her må de forskjellige WMSene plugges inn
#generate_wms_picture(coordinates[0], coordinates[1], coordinates[2], coordinates[3])
#generate_wms_photo(coordinates, config)
#Genererer bilder fra de forskjellige WMSene
fasit_path = sanderscript.generate_wms_picture()
orto_path = ortofoto.generate_orto_picture()

#Også må de riktige urlene plugges inn som image_path
util.split_image("WMS/rawphotos/fasit.png", "WMS/tiles/fasit", 100)
tiles = util.split_image("WMS/rawphotos/orto.png", "WMS/tiles/orto", 100)
print("TILES:" + str(tiles));
util.split_files("WMS/tiles", "WMS/email", tiles, config["data_parameters"][0], config["data_parameters"][1])


0 comments on commit adb66c9

Please sign in to comment.