-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
I was looking at the slopes on the droplets model https://code.agentscript.org/views2/droplets.html , and it occurred to me that the slopes look wrong. If you look at model.slopes they are all values like 1.4 which is like 80 degrees. I was not expecting slopes bigger than like 10 degrees for that area.
I think it has to do with the way dzdx and dzdy are calculated. They are treating the z values in meters, but the x,y values in terms of pixel dimensions. I think that the x and y should be in terms of meters too.
I wrote some helper functions that seem to work. My question is wether you would be interested in me putting those into a pull request? would we be interested in another class for GeoDatasets?
/**
* utils
*
* */
function geoDzdx(elevation, widthInMeters) {
const pixelScale = widthInMeters / elevation.width
const dzdx = elevation.dzdx(2, (1/8) * (1/pixelScale)) // (1/8) for the kernel and 1/pixelscale to get units right
return dzdx
}
function geoDzdy(elevation, heightInMeters) {
const pixelScale = heightInMeters / elevation.height
const dzdy = elevation.dzdy(2, (1/8) * (1/pixelScale))
return dzdy
}
function slope(dzdx, dzdy) {
const slopes = dzdx.map((x, i) => {
const y = dzdy.data[i]
const a = Math.hypot(-x, -y)
const sl = (Math.PI / 2) - Math.atan2(1, a)
return sl
})
return slopes
}
/**
* Calculate the slope of elevation Dataset in meters
* @param {DataSet} elevationDS
* @param {number} widthMeters The width in meters of the elevation dataset
* @param {number} heightMeters The height in meters of the elevation dataset
* @return {DataSet} slopes The slopes in radians
* */
function slopeFromElevationDS(elevationDS, widthMeters, heightMeters) {
const dzdx = geoDzdx(elevationDS, widthMeters)
const dzdy = geoDzdy(elevationDS, heightMeters)
const slopes = slope(dzdx, dzdy)
return slopes
}
/**
* Calculate the slope of elevation Dataset in meters
* @param {DataSet} elevationDS
* @param {[west, south, east, north]} bounds
* @return {DataSet} slopes The slopes in radians
* */
function slopeFromElevationDS_bounds(elevationDS, bounds) {
const sizeMeters = bboxMetricSize(bounds)
return slopeFromElevationDS(elevationDS, sizeMeters[0], sizeMeters[1])
}Metadata
Metadata
Assignees
Labels
No labels