Skip to content

Commit

Permalink
Merge pull request #66 from natcap/task/62-protected-layer
Browse files Browse the repository at this point in the history
Add protected layers
  • Loading branch information
dcdenu4 authored Sep 22, 2021
2 parents 603a083 + de0bad1 commit eef998b
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 33 deletions.
74 changes: 72 additions & 2 deletions data/merge_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def build_vector_path_list(vector_directory):

return vector_list

def build_vector_recursive_path_list(vector_directory):
vector_list = []
for root, dirs, files in os.walk(vector_directory):
for file in files:
if file.endswith(".shp") and "protected_points" not in file:
vector_list.append(os.path.join(root, file))
if file.endswith(".gpkg"):
vector_list.append(os.path.join(root, file))
#LOGGER.info(vector_list)
return vector_list
#return []

if __name__ == "__main__":

LOGGER.debug("Starting Merge Processing")
Expand All @@ -39,20 +51,47 @@ def build_vector_path_list(vector_directory):
'C:', os.sep, 'Users', 'ddenu', 'Workspace', 'NatCap', 'Repositories',
'global-web-viewer', 'processed-data', 'gadm_stats_vectors')

protected_root_dir = os.path.join(
'C:', os.sep, 'Users', 'ddenu', 'Workspace', 'NatCap', 'Repositories',
'global-web-viewer', 'data', 'boundaries', 'Global-Protected-Areas')
protected_sub_dir = "all"

#protected_sub_dir = "Africa"
#protected_sub_dir = "Asia_and_Pacific"
#protected_sub_dir = "Europe"
#protected_sub_dir = "LatinAmerica_Caribbean"
#protected_sub_dir = "NorthAmerica"
#protected_sub_dir = "Polar"
protected_sub_dir = "WestAsia"
protected_root_dir = os.path.join(
'C:', os.sep, 'Users', 'ddenu', 'Workspace', 'NatCap', 'Repositories',
'global-web-viewer', 'data', 'boundaries', 'Global-Protected-Areas',
f'WDPA_WDOECM_Mar2021_Public_{protected_sub_dir}_shp')

gadm0_process_dir = os.path.join(
gadm0_root_dir, 'gadm36_0_clipped_stats')

protected_process_dir = os.path.join(
protected_root_dir, f'protected_polys_merged_{protected_sub_dir}')
#protected_process_dir = os.path.join(
# protected_root_dir, f'protected_points_merged_{protected_sub_dir}')

gadm0_path_list = build_vector_path_list(gadm0_process_dir)
protected_path_list = build_vector_recursive_path_list(protected_root_dir)

merge_hybas = True
merge_hybas = False
merge_gadm0 = False
merge_protected = True
geom_type = "polygons"
#geom_type = "points"


if merge_hybas:
hybas_id = 'acc'
hybas_process_dir = os.path.join(
hybas_root_dir, f'hybas_{hybas_id}_processed_vectors')
hybas_path_list = build_vector_path_list(hybas_process_dir)

# Refine hydro files by level
file_matcher = f'{hybas_id}_perc'
hybas_selected_path_list = [x for x in hybas_path_list if file_matcher in x]
Expand Down Expand Up @@ -112,3 +151,34 @@ def build_vector_path_list(vector_directory):
merged_out_path, gadm_path])

LOGGER.debug(f"{idx + 1} out of {number_of_vectors} merged")

if merge_protected:
merged_out_dir = os.path.join(
protected_process_dir, f'merged_vectors')
if not os.path.isdir(merged_out_dir):
os.makedirs(merged_out_dir)

merged_out_path = os.path.join(
merged_out_dir, f"protected_{geom_type}_{protected_sub_dir}.shp")
# if this file already exists, then remove it
if os.path.isfile(merged_out_path):
os.remove(merged_out_path)

file_matcher = f'{geom_type}'
protected_selected_path_list = [x for x in protected_path_list if file_matcher in x]

number_of_vectors = len(protected_selected_path_list)

for idx, protected_path in enumerate(protected_selected_path_list):
if idx == 0:
# ogr2ogr -f "ESRI Shapefile" merged a.ship
# ogr2ogr -f "GeoJSONSeq" merged a.ship
subprocess.run(
["ogr2ogr", "-f", "ESRI Shapefile", merged_out_path, protected_path])
else:
# ogr2ogr -f "ESRI Shapefile" -append -update merged b.ship
subprocess.run(
["ogr2ogr", "-f", "ESRI Shapefile", "-append", "-update",
merged_out_path, protected_path])

LOGGER.debug(f"{idx + 1} out of {number_of_vectors} merged")
168 changes: 168 additions & 0 deletions map-viewer/src/LayerDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,174 @@ const mapLayers = [
},
}
},
{
layerID: 'protected-points',
name: 'Protected points',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-points',
'source-layer': 'protected_points_all_no_duplicatesgeojsonl',
type: 'circle',
paint: {
'circle-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.b29f9oyl',
},
}
},
{
layerID: 'protected-asia-pacific',
name: 'Protected Asia and Pacific',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-asia-pacific',
'source-layer': 'protected_polygons_Asia_and_Pacific',
type: 'fill',
paint: {
'fill-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.9es2n1jq',
},
}
},
{
layerID: 'protected-la-caribbean',
name: 'Protected Latin America and Caribbean',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-la-caribbean',
'source-layer': 'protected_polygons_LatinAmerica_Caribbean',
type: 'fill',
paint: {
'fill-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.d4a9sff0',
},
}
},
{
layerID: 'protected-af-polar-wa',
name: 'Protected Africa, Polar, West Asia',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-af-polar-wa',
'source-layer': 'protected_polygons_Africa_Polar_WestAsia',
type: 'fill',
paint: {
'fill-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.71dz1ont',
},
}
},
{
layerID: 'protected-north-america',
name: 'Protected North America',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-north-america',
'source-layer': 'protected_polygons_NorthAmerica',
type: 'fill',
paint: {
'fill-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.77rrl311',
},
}
},
{
layerID: 'protected-eu-0',
name: 'Protected Europe 0',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-eu-0',
'source-layer': 'protected_polygon_Europe_0',
type: 'fill',
paint: {
'fill-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.8yydsukv',
},
}
},
{
layerID: 'protected-eu-1',
name: 'Protected Europe 1',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-eu-1',
'source-layer': 'protected_polygon_Europe_1',
type: 'fill',
paint: {
'fill-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.9hiyxrqz',
},
}
},
{
layerID: 'protected-eu-2',
name: 'Protected Europe 2',
serviceType: 'protected-areas',
scaleID: 'all',
mapLayer: {
id: 'protected-eu-2',
'source-layer': 'protected_polygon_Europe_2',
type: 'fill',
paint: {
'fill-color': '#31a335',
},
layout: {
visibility: 'none',
},
source: {
type: 'vector',
url: 'mapbox://ddenu.protected-EU-2',
},
}
},
]

export default mapLayers;
19 changes: 15 additions & 4 deletions map-viewer/src/Map.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
z-index: 1;
}

/* TOGGLE CSS */
.custom-control-input:focus ~ .custom-control-label::before {
/* when the button is toggled off it is still in focus and a green border will appear */
border-color: #009b76 !important;
Expand All @@ -66,6 +67,7 @@
border-color: #009b76 !important;
}

/* POPOVER CSS */
.popover-body {
font-family: 'Source Sans Pro', sans-serif;
}
Expand All @@ -82,6 +84,7 @@
font-size: 20px;
}

/* INFO BUTTON CSS */
.btn {
outline: none;
box-shadow:none;
Expand Down Expand Up @@ -116,6 +119,7 @@
padding-left: .3rem;
}

/* BASEMAP CSS */
.basemap-control {
z-index: 1;
position: absolute;
Expand Down Expand Up @@ -163,6 +167,7 @@
padding: 0.25rem;
}

/* LEGEND CSS */
.legend-group {
font-family: 'Source Sans Pro', sans-serif;
z-index: 1;
Expand Down Expand Up @@ -208,6 +213,12 @@
height: 200px;
overflow-y: auto;
}
.d3-legend.ordinal.protected-areas{
z-index: 1;
width: 220px;
height: 20px;
overflow-y: auto;
}
.d3-x-axis:not(:last-child) {
padding-right: 4.75rem;
}
Expand All @@ -222,6 +233,7 @@
cursor: pointer;
}

/* MAPBOX POPUP CSS */
.mapboxgl-popup {
padding-bottom: 20px;
width: 280px;
Expand Down Expand Up @@ -277,19 +289,18 @@
font-weight: 200;
/*float: right;*/
}

.mapboxgl-popup-content div {
padding: 10px;
}

.mapboxgl-container .leaflet-marker-icon {
cursor: pointer;
}

.mapboxgl-popup-anchor-top > .mapboxgl-popup-content {
margin-top: 15px;
}

.mapboxgl-popup-anchor-top > .mapboxgl-popup-tip {
border-bottom-color: #91c949;
}
Loading

0 comments on commit eef998b

Please sign in to comment.