Skip to content

Commit

Permalink
fix(cutline): ignore path when updating vrt (#504)
Browse files Browse the repository at this point in the history
s3 paths are different for gdal /vsis3/ rather than s3://
  • Loading branch information
jacott committed Apr 22, 2020
1 parent ed83292 commit 714c554
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
19 changes: 14 additions & 5 deletions packages/cog/src/cog/__test__/cog.cutline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ o.spec('cog.cutline', () => {
const job = {
source: {
files: [] as string[],
path: '',
options: {
maxConcurrency: 3,
maxCogs: 3,
Expand Down Expand Up @@ -60,6 +61,9 @@ o.spec('cog.cutline', () => {

const [tif1, tif2] = [1, 2].map((i) => `${testDir}/tif${i}.tiff`);

const vtif1 = '/vsis3/' + tif1,
vtif2 = '/vsis3/' + tif2;

const tif1Poly = [
[174.56568549279925, -40.83842049282911],
[174.57337757492053, -41.162595138463644],
Expand Down Expand Up @@ -92,7 +96,7 @@ o.spec('cog.cutline', () => {
<VRTRasterBand dataType="Byte" band="${i + 1}">
<HideNoDataValue>1</HideNoDataValue>
<ColorInterp>${c}</ColorInterp>
${tifs.map((n) => (c === 'alpha' ? complexSource(n) : simpleSource(n, i + 1))).join('\n')}
${tifs.map((n) => (c === 'alpha' ? complexSource(n) : simpleSource('/vsis3/' + n, i + 1))).join('\n')}
</VRTRasterBand>`,
);

Expand Down Expand Up @@ -124,7 +128,7 @@ o.spec('cog.cutline', () => {

const vrt = await Cutline.buildVrt(tmpFolder, job, sourceGeo, makeVrtString(), '313', logger);

o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([tif2, tif2]);
o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([vtif2, vtif2]);
});

o('not within quadKey', async () => {
Expand All @@ -139,7 +143,12 @@ o.spec('cog.cutline', () => {
o('no cutline', async () => {
const vrt = await Cutline.buildVrt(tmpFolder, job, sourceGeo, makeVrtString(), '31', logger);

o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([tif1, tif2, tif1, tif2]);
o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([
vtif1,
vtif2,
vtif1,
vtif2,
]);
o(cutTiffArgs.length).equals(0);
});

Expand All @@ -150,7 +159,7 @@ o.spec('cog.cutline', () => {

const vrt = await Cutline.buildVrt(tmpFolder, job, sourceGeo, makeVrtString(), qkey, logger);

o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([tif2, tif2]);
o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([vtif2, vtif2]);
o(cutTiffArgs.length).equals(0);
});

Expand Down Expand Up @@ -178,7 +187,7 @@ o.spec('cog.cutline', () => {
]);
}

o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([tif1, tif1]);
o(Array.from(vrt.tags('SourceFilename')).map((e) => e.textContent)).deepEquals([vtif1, vtif1]);
});
});

Expand Down
12 changes: 6 additions & 6 deletions packages/cog/src/cog/cog.cutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ export const Cutline = {
if (!imgBounds.intersects(tiffBounds.bounds)) continue; // image outside quadKey

if (cutline == null) {
useTifs.add(path);
useTifs.add(tiffName);
continue;
}

const foundp: Polygon[] = [];

for (const p of polygons) {
if (booleanWithin(tiffBounds.poly, p)) {
useTifs.add(path);
useTifs.add(tiffName);
foundp.length = 0;
break;
}
Expand All @@ -161,12 +161,12 @@ export const Cutline = {

if (foundp.length != 0) {
++cropped;
useTifs.add(path);
useTifs.add(tiffName);
for (const p of foundp) usePolys.add(p);
}
}

job.source.files = Array.from(useTifs.values());
job.source.files = Array.from(useTifs.values()).map((n) => FileOperator.join(job.source.path, n));

if (usePolys.size == 0) {
job.output.cutline = undefined;
Expand All @@ -179,8 +179,8 @@ export const Cutline = {
for (const elm of b.elementChildren()) {
if (elm.tag === 'SimpleSource' || elm.tag === 'ComplexSource') {
const sf = elm.tags('SourceFilename').next().value!;
const path = sf.textContent;
if (!useTifs.has(path)) continue;
const name = basename(sf.textContent);
if (!useTifs.has(name)) continue;
}
children.push(elm);
}
Expand Down

0 comments on commit 714c554

Please sign in to comment.