Public
Edited
Feb 17, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
geotoptiff = geotiff.fromUrl(geotopurl)
Insert cell
Insert cell
numlevels = geotoptiff.getImageCount()
Insert cell
Insert cell
geotopimage = geotoptiff.getImage()
Insert cell
numbands = geotopimage.getSamplesPerPixel()
Insert cell
image_bbox = geotopimage.getBoundingBox()
Insert cell
image_width = geotopimage.getWidth()
Insert cell
image_resolution = geotopimage.getResolution()[0]; //only x direction [0] because we assume cells are square
Insert cell
Insert cell
geotoptthumbnail = geotoptiff.getImage(3)
Insert cell
Insert cell
surfraster = await geotoptthumbnail.readRasters({pool,samples:[0]})
Insert cell
Insert cell
[...new Set(surfraster[0])].sort();
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
extent_gh = [98981,455098,114010, 465324]
Insert cell
rwindow = [
Math.floor(~~(extent_gh[0] - image_bbox[0]) / image_resolution),
Math.floor(~~(image_bbox[3] - extent_gh[3]) / image_resolution),
Math.ceil(~~(extent_gh[2] - image_bbox[0]) / image_resolution),
Math.ceil(~~(image_bbox[3] - extent_gh[1]) / image_resolution)
];
Insert cell
surfraster_gh = await geotopimage.readRasters({pool,samples:[0],window: rwindow})
Insert cell
Insert cell
crossline = d3.line().x(d => (d.x)).y(d => (d.y))
Insert cell
Insert cell
Insert cell
Insert cell
rasters = await geotopimage.readRasters({pool,samples:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],window: rwindow});
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cross_section = {
const durchschnitt = new Uint8Array(rasters.length * rasters.width);
for (let j = 0; j<rasters.length;j++){
durchschnitt.set(rasters[j].slice(schnitt*rasters.width,schnitt*rasters.width+rasters.width),j*rasters.width);
}
durchschnitt.height = rasters.length;
durchschnitt.width = rasters.width;
return durchschnitt;
}
Insert cell
Insert cell
Insert cell
Insert cell
depthraster = {
let returnraster = [];
returnraster.width = rasters.width;
returnraster.height = rasters.height;
for (let i=0;i<=9;i++){
let resultraster = rasters[0].slice().fill(0);
rasters.map((raster,_)=>raster.map((d,j)=>{
if ( d===i ) resultraster[j] = resultraster[j] + 1; //increase raster cell by 1 when soilvalue==1 found
}));
returnraster.push(resultraster);
}
return returnraster;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pathGenerator = function(data,mapscale){
const coords = data.geometry.coordinates;
const newcoords = coords.map(c=>{
return [
(c[0]-extent_gh[0])/mapscale,
(c[1]-extent_gh[1])/mapscale
];
});
return newcoords;
}
Insert cell
function getimgdata(raster, width, height, colorscale) {
const data = new Uint8ClampedArray(width * height * 4);
for (let i = 0; i < raster.length; i++) {
let color = d3.color(colorscale(raster[i]))|| {r:0,g:0,b:0};
data[i * 4] = color.r;
data[i * 4 + 1] = color.g;
data[i * 4 + 2] = color.b;
data[i * 4 + 3] = isNaN(raster[i]) || raster[i] == -3.4028234663852886e+38 || raster[i] == 3.4028234663852886e+38 || raster[i] == 255 ? 0 : 255;
}
return new ImageData(data, width, height);
}
Insert cell
//geotiff = require( "geotiff.js/dist/geotiff.bundle.min.js")
geotiff = require('geotiff@2.0.4/dist-browser/geotiff.js')
Insert cell
pool = new geotiff.Pool();
Insert cell
spoordata = FileAttachment("spoor_alphen@3.geojson").json()
Insert cell
Insert cell
d3 = require("d3@6", "d3-geo-projection@3")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more