-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,184 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
MAP | ||
# background color of image if transparency | ||
# is not requested | ||
IMAGECOLOR 255 255 255 | ||
|
||
# default output image dimensions | ||
SIZE 600 400 | ||
MAXSIZE 4000 | ||
# always returns a map | ||
STATUS ON | ||
|
||
# set top level projection | ||
PROJECTION | ||
"init=epsg:3857" | ||
END | ||
|
||
# image format options | ||
OUTPUTFORMAT | ||
NAME png | ||
DRIVER "GD/PNG" | ||
MIMETYPE "image/png" | ||
IMAGEMODE RGB | ||
EXTENSION "png" | ||
END | ||
|
||
OUTPUTFORMAT | ||
NAME "GEOTIFF" | ||
DRIVER "GDAL/GTiff" | ||
MIMETYPE "image/tiff" | ||
IMAGEMODE "BYTE" | ||
EXTENSION "tif" | ||
END | ||
|
||
# minx miny maxx maxy | ||
# sets: | ||
# /WMT_MS_Capabilities/Capability/Layer/LatLonBoundingBox(@minx @miny @maxx @maxx) | ||
EXTENT -180 -90 180 90 # World | ||
|
||
# add def pointers for symbols | ||
SYMBOLSET "./symbols/symbols35.sym" | ||
FONTSET "./fonts/fonts.list" | ||
|
||
# Start of web interface definition | ||
WEB | ||
# this is the real filepath to the temp dir for intermediate file creation | ||
IMAGEPATH "./tmp" | ||
# this is the web-accessible path to IMAGEPATH | ||
IMAGEURL "/tmp/" | ||
HEADER "./templates/query_header.html" | ||
FOOTER "./templates/query_footer.html" | ||
METADATA | ||
"ows_enable_request" "*" | ||
"wms_title" "NEMAC WMS" | ||
"wms_abstract" "NEMAC WMS" | ||
"wms_contactperson" "[email protected]" | ||
"wms_rootlayer_name" "" # this sets queryable=0 for root layer | ||
"wms_onlineresource" "https://mapserver.nemac.org/?map=/etc/mapserver/ecs_test_map_files/forwarn3_products_1yr.map" | ||
"wms_keywordlist" "2024-05-09_2024-06-01.napolygon.1yrdeparture.LAEA.img, | ||
2024-05-17_2024-06-09.napolygon.1yrdeparture.LAEA.img, | ||
2024-05-25_2024-06-17.napolygon.1yrdeparture.LAEA.img, | ||
2024-06-02_2024-06-25.napolygon.1yrdeparture.LAEA.img, | ||
2024-06-10_2024-07-03.napolygon.1yrdeparture.LAEA.img, | ||
2024-06-18_2024-07-11.napolygon.1yrdeparture.LAEA.img, | ||
2024-06-26_2024-07-19.napolygon.1yrdeparture.LAEA.img, | ||
2024-07-04_2024-07-27.napolygon.1yrdeparture.LAEA.img" | ||
"wms_srs" "EPSG:4326 EPSG:2163 EPSG:3857 EPSG:900913" | ||
"wcs_label" "forwarn3_products_1yr.map" | ||
"wcs_srs" "EPSG:2163" | ||
"ows_contactorganization" "UNCA's NEMAC" | ||
END # end METADATA | ||
END # end WEB | ||
|
||
QUERYMAP | ||
STATUS OFF | ||
END # end QUERYMAP | ||
|
||
LEGEND | ||
STATUS ON | ||
LABEL | ||
COLOR 0 0 0 | ||
FONT "vera_serif" | ||
TYPE truetype | ||
SIZE 9 | ||
POSITION cl | ||
END # end LABEL | ||
END # end LEGEND | ||
|
||
LAYER | ||
NAME "forwarn3_products_1yr" | ||
PROJECTION | ||
"+proj=laea" | ||
"+lat_0=45" | ||
"+lon_0=-100" | ||
"+x_0=0" | ||
"+y_0=0" | ||
"+a=6370997" | ||
"+b=6370997" | ||
"+units=m" | ||
"+no_defs" | ||
END # END PROJECTION | ||
TYPE RASTER | ||
STATUS OFF | ||
VALIDATION | ||
"mask" "^[a-zA-Z0-9_]+$" | ||
"default_mask" "empty_mask" | ||
END # END VALIDATION | ||
DATA /etc/mapserver/forwarn3_products/1yr/%data% | ||
TEMPLATE layer_query_body.html # THIS DOES NOT EXIST AT THE MOMENT BUT IT IS NEEDED TO HAVE queryable=1 | ||
#GROUP "forwarn3_products_1yr" | ||
INCLUDE "new-forwarn2-standard-2.cmap" | ||
METADATA | ||
"wms_title" "forwarn3_products_1yr" | ||
#"wms_group_title" "forwarn3_products_1yr" | ||
"wms_extent" "-2401951.937575, -2238222.70389, 2345858.525679, 967021.455769" | ||
"wms_abstract" "forwarn3_products_1yr" | ||
"wcs_label" "forwarn3_products_1yr" | ||
"wcs_rangeset_name" "forwarn3_products_1yr" | ||
"wcs_rangeset_label" "forwarn3_products_1yr" | ||
"wcs_bandcount" "1" | ||
"wcs_formats" "GEOTIFF" | ||
"wcs_nativeformat" "8-bit GeoTIF" | ||
"gml_include_items" "value_0" | ||
END # end METADATA | ||
MASK '%mask%' | ||
END # end LAYER | ||
|
||
INCLUDE "masks.map" | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import os | ||
import glob | ||
import re | ||
|
||
DATA_DIR = "forwarn" | ||
EXCLUDE_DIRS = ["archive", "bill_c", "forwarn2_build_prod", "forwarn2_products", | ||
"forwarn3_test", "graph_data", "jspruce", "masks", "precursors", | ||
"rescaled_precursors", "scripts"] | ||
DATA_LOCATION_DIRECTORY = "/etc/mapserver" # where ECS container expects data to be | ||
|
||
def extract_date_range(filename): | ||
# Use a regular expression to find the date range | ||
match = re.search(r'(\d{4}-\d{2}-\d{2})_(\d{4}-\d{2}-\d{2})', filename) | ||
if match: | ||
return match.group(2) | ||
return None | ||
|
||
def extract_subdirs(file_path, base_dir): | ||
# Get the relative path | ||
rel_path = os.path.relpath(file_path, base_dir) | ||
# Split the path into parts | ||
parts = rel_path.split(os.sep) | ||
# Return all parts except the last one (filename) | ||
return os.sep.join(parts[:-1]) | ||
|
||
def create_layers_from_template(map_template_file, raster_template_file, data_dir): | ||
with open(map_template_file, 'r', encoding='utf-8') as f: | ||
map_template = f.read() | ||
|
||
with open(raster_template_file, 'r', encoding='utf-8') as f: | ||
raster_template = f.read() | ||
|
||
# Get list of .img files | ||
img_files = [ | ||
f for f in glob.glob(os.path.join(data_dir, '**/*.img'), recursive=True) | ||
if not any(exclude_dir in f.split(os.sep) for exclude_dir in EXCLUDE_DIRS) | ||
if "muted" not in os.path.basename(f).lower() | ||
] | ||
# img_files = glob.glob(os.path.join(data_dir, '**/*.img'), recursive=True) | ||
img_files.sort() | ||
|
||
# Group files by subdirectory | ||
subdirectory_files = {} | ||
for absolute_path in img_files: | ||
subdirs = extract_subdirs(absolute_path, data_dir) | ||
if subdirs not in subdirectory_files: | ||
subdirectory_files[subdirs] = [] | ||
subdirectory_files[subdirs].append(absolute_path) | ||
|
||
# Process each subdirectory | ||
for subdirs, files in subdirectory_files.items(): | ||
layers = [] | ||
layer_filenames = [] | ||
layer_content = raster_template.format( | ||
layer_name = subdirs.replace(os.sep, '_'), | ||
group_name = subdirs.replace(os.sep, '_'), | ||
metadata_name = subdirs.replace(os.sep, '_'), | ||
data_location = os.path.join(DATA_LOCATION_DIRECTORY, subdirs, "%data%") | ||
) | ||
layers.append(layer_content) | ||
for absolute_path in files: | ||
filename = os.path.basename(absolute_path) | ||
layer_filenames.append(filename) | ||
grouped = [layer_filenames[i:i+1] for i in range(0, len(layer_filenames), 1)] | ||
final_string = ',\n '.join(','.join(group) for group in grouped) | ||
# date_range = extract_date_range(filename) | ||
# if date_range: | ||
# layer_content = raster_template.format( | ||
# layer_name = f"{subdirs.replace(os.sep, '_')}_{date_range.replace('-', '')}", | ||
# group_name = subdirs.replace(os.sep, '_'), | ||
# metadata_name = f"{subdirs.replace(os.sep, '_')}_{date_range}", | ||
# metadata_date = date_range.replace('-', ''), | ||
# data_location = os.path.join(DATA_LOCATION_DIRECTORY, absolute_path) | ||
# ) | ||
# layers.append(layer_content) | ||
# layer_filenames.append(filename) | ||
# else: | ||
# print(f"Warning: Could not extract date range from {filename}") | ||
|
||
layers_str = "\n".join(layers) | ||
output_filename = f"{subdirs.replace(os.sep, '_')}.map" | ||
map_content = map_template.format(layers=layers_str, layer_filenames=final_string, map_file_name=output_filename) | ||
with open(output_filename, 'w', encoding='utf-8') as f: | ||
f.write(map_content) | ||
|
||
print(f"Created map file: {output_filename}") | ||
|
||
MAP_TEMPLATE = "map_template.map" | ||
RASTER_TEMPLATE = "raster_layers_template.map" | ||
create_layers_from_template(MAP_TEMPLATE, RASTER_TEMPLATE, DATA_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
MAP | ||
# background color of image if transparency | ||
# is not requested | ||
IMAGECOLOR 255 255 255 | ||
|
||
# default output image dimensions | ||
SIZE 600 400 | ||
MAXSIZE 4000 | ||
# always returns a map | ||
STATUS ON | ||
|
||
# set top level projection | ||
PROJECTION | ||
"init=epsg:3857" | ||
END | ||
|
||
# image format options | ||
OUTPUTFORMAT | ||
NAME png | ||
DRIVER "GD/PNG" | ||
MIMETYPE "image/png" | ||
IMAGEMODE RGB | ||
EXTENSION "png" | ||
END | ||
|
||
OUTPUTFORMAT | ||
NAME "GEOTIFF" | ||
DRIVER "GDAL/GTiff" | ||
MIMETYPE "image/tiff" | ||
IMAGEMODE "BYTE" | ||
EXTENSION "tif" | ||
END | ||
|
||
# minx miny maxx maxy | ||
# sets: | ||
# /WMT_MS_Capabilities/Capability/Layer/LatLonBoundingBox(@minx @miny @maxx @maxx) | ||
EXTENT -180 -90 180 90 # World | ||
|
||
# add def pointers for symbols | ||
SYMBOLSET "./symbols/symbols35.sym" | ||
FONTSET "./fonts/fonts.list" | ||
|
||
# Start of web interface definition | ||
WEB | ||
# this is the real filepath to the temp dir for intermediate file creation | ||
IMAGEPATH "./tmp" | ||
# this is the web-accessible path to IMAGEPATH | ||
IMAGEURL "/tmp/" | ||
HEADER "./templates/query_header.html" | ||
FOOTER "./templates/query_footer.html" | ||
METADATA | ||
"ows_enable_request" "*" | ||
"wms_title" "NEMAC WMS" | ||
"wms_abstract" "NEMAC WMS" | ||
"wms_contactperson" "[email protected]" | ||
"wms_rootlayer_name" "" # this sets queryable=0 for root layer | ||
"wms_onlineresource" "https://mapserver.nemac.org/?map=/etc/mapserver/ecs_test_map_files/{map_file_name}" | ||
"wms_keywordlist" "{layer_filenames}" | ||
"wms_srs" "EPSG:4326 EPSG:2163 EPSG:3857 EPSG:900913" | ||
"wcs_label" "{map_file_name}" | ||
"wcs_srs" "EPSG:2163" | ||
"ows_contactorganization" "UNCA's NEMAC" | ||
END # end METADATA | ||
END # end WEB | ||
|
||
QUERYMAP | ||
STATUS OFF | ||
END # end QUERYMAP | ||
|
||
LEGEND | ||
STATUS ON | ||
LABEL | ||
COLOR 0 0 0 | ||
FONT "vera_serif" | ||
TYPE truetype | ||
SIZE 9 | ||
POSITION cl | ||
END # end LABEL | ||
END # end LEGEND | ||
|
||
{layers} | ||
INCLUDE "masks.map" | ||
END |
Oops, something went wrong.