Skip to content

Commit

Permalink
update oceania/au/nsw to include full HAPE and Floods layers (#2604)
Browse files Browse the repository at this point in the history
* update oceania/au/nsw to include full HAPE and Floods layers

* fix geojson geometries

* fix indent and apply geojson-rewind
  • Loading branch information
andrewharvey authored Jan 24, 2025
1 parent e864ac9 commit 1ff3b72
Show file tree
Hide file tree
Showing 74 changed files with 7,589 additions and 694 deletions.
90 changes: 90 additions & 0 deletions scripts/sources/oceania/au/nsw/NSW_SS_Floods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

// scripted used to help generate NSW SS Floods layers

const fs = require('fs');

const services = [
'Floods_2021',
'Floods_Historical',
'Floods_Mar_2022',
'Floods_Nov_2021',
'Floods_Nov_2022'
];

const template = {
"type": "Feature",
"properties": {
"attribution": {
"url": "https://www.spatial.nsw.gov.au/",
"text": "© State of New South Wales (Spatial Services, a business unit of the Department of Customer Service NSW). For current information go to spatial.nsw.gov.au.",
"required": true
},
"license_url": "https://wiki.openstreetmap.org/wiki/File:SpatialServices_NSW_OSM_Waiver_completed.pdf",
"privacy_policy_url": "https://www.spatial.nsw.gov.au/privacy",
"name": "",
"url": null,
"available_projections": [
"EPSG:3857"
],
"max_zoom": 21,
"min_zoom": 1,
"start_date": null,
"end_date": null,
"country_code": "AU",
"type": "wms",
"id": "",
"icon": "https://www.spatial.nsw.gov.au/__data/assets/file/0017/224801/favicon.ico",
"category": "historicphoto"
}
};

(async() => {
for (const service of services) {
const serviceName = service.replaceAll('_', ' ');
const response = await fetch(`https://portal.spatial.nsw.gov.au/server/rest/services/${service}/MapServer?f=pjson`);
const data = await response.json();
for (const layer of data.layers) {
const id = layer.id;
const name = layer.name?.replace(/\.jp2$/, '').replaceAll('_', ' ');
const layerId = layer.name?.replace(/\.jp2$/, '').replaceAll(' ', '_');

// 03122022 -> 2022-12-03
// 2021_11_15 -> 2021-11-15
// 2021_11_13cm -> 2021-11
const date = layer.name?.match(/(?<dd>\d\d)(?<mm>\d\d)(?<yyyy>\d\d\d\d)_/)?.groups ??
layer.name?.match(/(?<yyyy>\d\d\d\d)_(?<mm>\d\d)_(?<dd>\d\d)_/)?.groups ??
layer.name?.match(/(?<yyyy>\d\d\d\d)_(?<mm>\d\d)_/)?.groups;

const result = { ...template };

result.properties.url = `https://portal.spatial.nsw.gov.au/server/rest/services/${service}/MapServer/export?f=image&format=png&transparent=true&imageSR=3857&bboxSR=3857&bbox={bbox}&size={width},{height}&layers=show:${id}&foo={proj}`;

let formattedDate;
if (date && date.yyyy && date.mm && date.dd) {
formattedDate = `${date.yyyy}-${date.mm}-${date.dd}`;
}else if (date && date.yyyy && date.mm) {
formattedDate = `${date.yyyy}-${date.mm}`;
}else if (date && date.yyyy) {
formattedDate = `${date.yyyy}`;
}
if (formattedDate) {
result.properties.start_date = formattedDate;
result.properties.end_date = formattedDate;
} else {
delete result.properties.start_date;
delete result.properties.end_date;
}

result.properties.name = `DCS NSW ${serviceName} ${name}`;
result.properties.id = `DCS_NSW_${service}_${layerId}`;

if (formattedDate) {
console.log(`${service} ${layer.id}: ${layer.name} (${formattedDate})`);
} else {
console.log(`${service} ${layer.id}: ${layer.name}`);
}
fs.writeFileSync(`output/NSW_SS_${service}_${layerId}.geojson`, JSON.stringify(result, null, 4));
}
}
})();
Loading

0 comments on commit 1ff3b72

Please sign in to comment.