-
Notifications
You must be signed in to change notification settings - Fork 17
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
27 changed files
with
862 additions
and
79 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
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
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
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 |
---|---|---|
@@ -1,60 +1,76 @@ | ||
/* global loam */ | ||
|
||
// Use the locally built version of loam, with a CDN copy of GDAL from unpkg. | ||
loam.initialize('/', 'https://unpkg.com/gdal-js@2.0.0/'); | ||
loam.initialize('/', 'https://unpkg.com/gdal-js@2.1.0/'); | ||
|
||
const EPSG4326 = | ||
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]'; | ||
|
||
function displayInfo() { | ||
const file = document.querySelector('#geotiff-file').files[0]; | ||
const sourceFile = document.querySelector('#source-file').files[0]; | ||
const sidecars = Array.from(document.querySelector('#sidecar-files').files); | ||
|
||
const displayElem = document.getElementById('gdalinfo'); | ||
|
||
// Clear display text | ||
displayElem.innerText = ''; | ||
// Use Loam to get GeoTIFF metadata | ||
loam.open(file).then((ds) => { | ||
return Promise.all([ds.width(), ds.height(), ds.count(), ds.wkt(), ds.transform()]).then( | ||
([width, height, count, wkt, geoTransform]) => { | ||
displayElem.innerText += | ||
'Size: ' + width.toString() + ', ' + height.toString() + '\n'; | ||
displayElem.innerText += 'Band count: ' + count.toString() + '\n'; | ||
displayElem.innerText += 'Coordinate system:\n' + wkt + '\n'; | ||
|
||
const cornersPx = [ | ||
[0, 0], | ||
[width, 0], | ||
[width, height], | ||
[0, height], | ||
loam.open(sourceFile, sidecars).then((ds) => { | ||
return Promise.all([ | ||
ds.width(), | ||
ds.height(), | ||
ds.count(), | ||
ds.layerCount(), | ||
ds.wkt(), | ||
ds.transform(), | ||
]).then(([width, height, count, layerCount, wkt, geoTransform]) => { | ||
displayElem.innerText += 'Size: ' + width.toString() + ', ' + height.toString() + '\n'; | ||
displayElem.innerText += 'Raster band count: ' + count.toString() + '\n'; | ||
displayElem.innerText += 'Vector layer count: ' + layerCount.toString() + '\n'; | ||
displayElem.innerText += 'Coordinate system:\n' + wkt + '\n'; | ||
|
||
const cornersPx = [ | ||
[0, 0], | ||
[width, 0], | ||
[width, height], | ||
[0, height], | ||
]; | ||
const cornersGeo = cornersPx.map(([x, y]) => { | ||
return [ | ||
// http://www.gdal.org/gdal_datamodel.html | ||
geoTransform[0] + geoTransform[1] * x + geoTransform[2] * y, | ||
geoTransform[3] + geoTransform[4] * x + geoTransform[5] * y, | ||
]; | ||
const cornersGeo = cornersPx.map(([x, y]) => { | ||
return [ | ||
// http://www.gdal.org/gdal_datamodel.html | ||
geoTransform[0] + geoTransform[1] * x + geoTransform[2] * y, | ||
geoTransform[3] + geoTransform[4] * x + geoTransform[5] * y, | ||
]; | ||
}); | ||
|
||
loam.reproject(wkt, EPSG4326, cornersGeo).then((cornersLngLat) => { | ||
displayElem.innerText += 'Corner Coordinates:\n'; | ||
cornersLngLat.forEach(([lng, lat], i) => { | ||
displayElem.innerText += | ||
'(' + | ||
cornersGeo[i][0].toString() + | ||
', ' + | ||
cornersGeo[i][1].toString() + | ||
') (' + | ||
lng.toString() + | ||
', ' + | ||
lat.toString() + | ||
')\n'; | ||
}); | ||
}); | ||
|
||
loam.reproject(wkt, EPSG4326, cornersGeo).then((cornersLngLat) => { | ||
displayElem.innerText += 'Corner Coordinates:\n'; | ||
cornersLngLat.forEach(([lng, lat], i) => { | ||
displayElem.innerText += | ||
'(' + | ||
cornersGeo[i][0].toString() + | ||
', ' + | ||
cornersGeo[i][1].toString() + | ||
') (' + | ||
lng.toString() + | ||
', ' + | ||
lat.toString() + | ||
')\n'; | ||
}); | ||
if (count > 0) { | ||
ds.bandStatistics(1).then((stats) => { | ||
displayElem.innerText += 'Band 1 min: ' + stats.minimum + '\n'; | ||
displayElem.innerText += 'Band 1 max: ' + stats.maximum + '\n'; | ||
displayElem.innerText += 'Band 1 median: ' + stats.median + '\n'; | ||
displayElem.innerText += 'Band 1 standard deviation: ' + stats.stdDev + '\n'; | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
document.getElementById('geotiff-file').onchange = function () { | ||
document.getElementById('display-metadata-button').onclick = function () { | ||
displayInfo(); | ||
}; |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"name": "loam", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Javascript wrapper for GDAL in the browser", | ||
"main": "lib/loam.js", | ||
"scripts": { | ||
"build": "webpack --config=webpack.dev.js && webpack --config=webpack.prod.js", | ||
"dev": "webpack --progress --color --watch --config=webpack.dev.js", | ||
"demo": "webpack serve --config=webpack.dev.js", | ||
"format": "prettier --write ./src", | ||
"format": "prettier --write ./src ./test ./demo", | ||
"test": "karma start --single-run --browser ChromeHeadless karma.conf.js", | ||
"test:watch": "karma start --auto-watch --browser ChromeHeadless karma.conf.js", | ||
"test:ci": "prettier --check src/**/*.js && webpack --config=webpack.dev.js && webpack --config=webpack.prod.js && karma start --single-run --browser ChromeHeadless karma.conf.js" | ||
|
@@ -58,7 +58,7 @@ | |
"yargs": "^17.5.1" | ||
}, | ||
"dependencies": { | ||
"gdal-js": "2.0.0" | ||
"gdal-js": "2.1.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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
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,19 @@ | ||
// In order to make enums available from JS it's necessary to use embind, which seems like | ||
// overkill for something this small. This replicates the GDALDataType enum: | ||
// https://gdal.org/api/raster_c_api.html#_CPPv412GDALDataType and will need to be changed | ||
// if that enum changes. There is a smoke test that should warn us if it changes upstream. | ||
export const GDALDataTypes = [ | ||
'Unknown', | ||
'Byte', | ||
'UInt16', | ||
'Int16', | ||
'UInt32', | ||
'Int32', | ||
'Float32', | ||
'Float64', | ||
'CInt16', | ||
'CInt32', | ||
'CFloat32', | ||
'CFloat64', | ||
'TypeCount', | ||
]; |
Oops, something went wrong.