-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSHP-zipfile-URL-to-local-json.html
78 lines (60 loc) · 2.68 KB
/
SHP-zipfile-URL-to-local-json.html
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
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SHP Zipfile into JSON [Using Arraybuffer & SHP.js]</title>
<!--<link rel="stylesheet" href="css/style.css">-->
<meta name="description" content="Read SHP Zipfile from URL endpoint into browser as JSON [Using Arraybuffer & SHP.js]">
<meta property="og:title" content="">
<meta property="og:type" content="">
<meta property="og:url" content="">
<meta property="og:image" content="">
<meta property="og:image:alt" content="">
<!-- <link rel="icon" href="/favicon.ico" sizes="any">-->
<!-- <link rel="icon" href="/icon.svg" type="image/svg+xml"> -->
<!-- <link rel="apple-touch-icon" href="icon.png"> -->
<!-- <link rel="manifest" href="site.webmanifest"> -->
<meta name="theme-color" content="#fafafa">
</head>
<body>
<!-- Add your site or application content here -->
<p>Load a shapefile and render data into console.</p>
<script src='https://unpkg.com/shpjs@latest/dist/shp.js' type="module"></script>
<script type="module">
// You can now use the shp object/methods here
console.log(shp);
window.shp = shp; // Add shp to global scope
// Call loadData() after shp is defined
loadData();
</script>
<script>
async function loadData() {
try {
// Load all files simultaneously
const promises = [
fetch("https://s3.amazonaws.com/geospatial.data/usa/ma/RTA_Boundaries.zip").then(r => r.arrayBuffer()),
//fetch("https://s3.amazonaws.com/geospatial.data/usa/ma/BioMap3.zip").then(r => r.arrayBuffer()),
fetch("https://s3.amazonaws.com/geospatial.data/usa/ma/dcrtrails.zip").then(r => r.arrayBuffer())
// Add more file URLs here if needed
];
// Wait for all promises to resolve
const results = await Promise.all(promises);
// Parse each result
const rta_boundaries_interp = await shp.parseZip(results[0]);
console.log('RTA Boundaries loaded successfully:', rta_boundaries_interp);
//const BioMap3_interp = await shp.parseZip(results[1]);
//console.log('BioMap3 loaded successfully:', BioMap3_interp);
const dcr_trails_interp = await shp.parseZip(results[1]);
console.log('DCR Trails loaded successfully:', dcr_trails_interp);
// Add more data objects as needed
// Print success message after all data objects are loaded
console.log('All data objects loaded successfully');
} catch (error) {
// Print failure message if any data object failed to load
console.error('Failed to load data:', error);
}
}
</script>
</body>
</html>