-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from azavea/feature/dpd/vector-datasets
Add basic support for vector datasets
- Loading branch information
Showing
20 changed files
with
480 additions
and
75 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,67 @@ | ||
/* 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'; | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"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
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 @@ | ||
export default function (GDALDatasetGetLayerCount, errorHandling) { | ||
return function (datasetPtr) { | ||
const result = GDALDatasetGetLayerCount(datasetPtr); | ||
|
||
const errorType = errorHandling.CPLGetLastErrorType(); | ||
|
||
// Check for errors; clean up and throw if error is detected | ||
if ( | ||
errorType === errorHandling.CPLErr.CEFailure || | ||
errorType === errorHandling.CPLErr.CEFatal | ||
) { | ||
const message = errorHandling.CPLGetLastErrorMsg(); | ||
|
||
throw new Error('Error in GDALDatasetGetLayerCount: ' + message); | ||
} else { | ||
return result; | ||
} | ||
}; | ||
} |
Oops, something went wrong.