Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cutline): ignore path when updating vrt #504

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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