Skip to content

Commit

Permalink
added tile_resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Mar 9, 2023
1 parent 2e3a578 commit 27730af
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm install geotiff-tile
```js
import { createTile } from "geotiff-tile";

createTile({
await createTile({
// bounding box of tile in format [xmin, ymin, xmax, ymax]
bbox: [-122.49755859375, 38.8520508, -120.06958007812499, 40.697299008636755],

Expand Down Expand Up @@ -71,6 +71,10 @@ createTile({
// width of tile in pixels
tile_width: 512,

// resolution of the tile
// from 0 (lowest) to 1 (highest)
tile_resolution: 0.5,

// whether to use overviews if available
use_overview,

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"geotiff-epsg-code": "^0.2.0",
"geotiff-no-data": "^0.2.0",
"geotiff-read-bbox": "^1.3.0",
"geowarp": "^1.19.0",
"geowarp": "^1.21.0",
"pixel-utils": "^0.9.0",
"proj4": "^2.8.1",
"proj4-fully-loaded": "^0.2.0",
"reproject-bbox": "^0.9.0"
"reproject-bbox": "^0.10.0"
},
"devDependencies": {
"@babel/cli": "^7.21.0",
Expand All @@ -62,12 +62,12 @@
"@babel/preset-typescript": "^7.21.0",
"chroma-js": "^2.4.2",
"envisage": "^0.1.0",
"flug": "^2.5.0",
"flug": "^2.6.0",
"geotiff": "^2.0.7",
"rimraf": "^4.3.0",
"rimraf": "^4.4.0",
"snap-bbox": "^0.3.0",
"srvd": "^0.6.0",
"webpack": "^5.75.0",
"webpack": "^5.76.0",
"webpack-cli": "^5.0.1"
}
}
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export default async function createTile({
tile_srs = 3857, // epsg code of the output tile
tile_array_types_strategy = "auto",
tile_layout = "[band][row,column]",
timed = false,
tile_resolution = [1, 1],
tile_width = 256,
timed = false,
use_overview = true,
turbo = false
}: {
Expand Down Expand Up @@ -62,6 +63,7 @@ export default async function createTile({
tile_srs?: number;
tile_height: number;
tile_layout?: string;
tile_resolution?: number | number[] | [number, number] | Readonly<[number, number]> | undefined;
tile_width: number;
timed?: boolean | undefined;
use_overview?: boolean;
Expand Down Expand Up @@ -195,7 +197,9 @@ export default async function createTile({
return tile_array_types;
} else if (tile_array_types_strategy === "auto") {
if (_expr) {
return new Array(array_depth - 1).fill("Array");
// ex: [row,column,band] -> ["Array"]
// ex: [band][row,column] -> ["Array", "Array"]
return new Array(array_depth).fill("Array");
} else {
return new Array(array_depth - 1).fill("Array").concat([sourceArrayType]);
}
Expand All @@ -208,7 +212,7 @@ export default async function createTile({
})();
if (debug_level >= 2) console.log("[geotiff-tile] tile_array_types:\n", tile_array_types);

const { data: out_data } = geowarp({
const { data: out_data } = await geowarp({
cutline,
cutline_srs,
cutline_forward: cutline ? proj4fullyloaded("EPSG:" + cutline_srs, "EPSG:" + tile_srs).forward : undefined,
Expand All @@ -225,10 +229,11 @@ export default async function createTile({
method,
// out_bands: should use if repeated bands in output
out_array_types: tile_array_types,
out_bbox: bbox_in_tile_srs.map(it => Number(it)),
out_bbox: bbox_in_tile_srs.map((it: number) => Number(it)),
out_height: tile_height,
out_layout: tile_layout,
out_pixel_depth: pixel_depth,
out_resolution: typeof tile_resolution === "number" ? [tile_resolution, tile_resolution] : tile_resolution,
out_srs: tile_srs,
out_width: tile_width,
round,
Expand Down
31 changes: 11 additions & 20 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<script>
window.process = {
env: {
// TEST_NAME: "ycbcr"
TEST_TIMED: true,
// TEST_NAME: "pulling tile from 4-band Web Mercator GeoTIFF"
}
}
</script>
Expand Down Expand Up @@ -132,31 +133,21 @@
debug_level: 0,
geotiff,
bbox: [74.35546875, 4.214943141390651, 84.90234375, 13.752724664396988],
expr: async ({ pixel: [r, g, b, a] }) => b > 150 ? [223, 255, 0] : [r, g, b],
method: "near",
tile_array_types: ["Array", "Array", "Uint8Array"],
tile_height: 512,
tile_layout: "[row,column,band]",
tile_width: 512,
timed: true
});
eq(tile.constructor.name, "Uint8Array");
displayTile({ height, width, tile });
});

test("pulling tile from 4-band Web Mercator GeoTIFF (turbo)", async ({ eq }) => {
const geotiff = await GeoTIFF.fromUrl("./data/gadas.tif");
const { height, width, tile } = await geotiff_tile.createTile({
debug_level: 0,
geotiff,
bbox: [74.35546875, 4.214943141390651, 84.90234375, 13.752724664396988],
method: "near",
tile_height: 512,
tile_layout: "[row,column,band]",
tile_layout: "[band][row][column]",
tile_resolution: 0.25,
tile_width: 512,
timed: true,
turbo: true
});
eq(tile.constructor.name, "Uint8Array");
displayTile({ id: "gadas-turbo", height, width, tile });
eq(tile[0][0].constructor.name, "Uint8Array");

const data = three_to_four_bands({ height, width, tile })

displayTile({ height, width, tile: data });
});

test("pulling tile from 3-band Geographic GeoTIFF", async ({ eq }) => {
Expand Down

0 comments on commit 27730af

Please sign in to comment.