Created
February 14, 2018 18:51
-
-
Save schwehr/39680bec7fd8e3e3f840122ea3bafc65 to your computer and use it in GitHub Desktop.
This does not work to create a cogeo file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2018 Google Inc. All Rights Reserved. | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
// See the License for the specific language governing permissions and | |
// limitations under the License. | |
// Test Ocreating Cloud Optimized GeoTiffs (cogeo). | |
package org.gdal.frmts.gtiff; | |
import static com.google.common.truth.Truth.assertThat; | |
import com.google.common.collect.ImmutableList; | |
import com.google.testing.util.TestUtil; | |
import java.nio.file.Paths; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import org.gdal.gdal.Band; | |
import org.gdal.gdal.Dataset; | |
import org.gdal.gdal.Driver; | |
import org.gdal.gdalconst.gdalconst; | |
import org.gdal.gdal.gdal; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.JUnit4; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.Vector; | |
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | |
@RunWith(JUnit4.class) | |
public final class CogeoTest { | |
private static final String TESTDATA_DIR = | |
TestUtil.getSrcDir() | |
+ "autotest2/javatests/org/gdal/frmts/gtiff/testdata/cogeo/"; | |
private static final String GEOTIFF_GDAL_FORMAT = "GTiff"; | |
private Driver driver; | |
@Before | |
public void setupGdal() { | |
gdal.AllRegister(); | |
driver = gdal.GetDriverByName(GEOTIFF_GDAL_FORMAT); | |
} | |
@Test | |
public void createCogeo() throws Exception { | |
// Follow the naming convention of output from an EE flume. | |
String srcPath = TESTDATA_DIR + "0000000000-0000000000.tif"; | |
String tmpPath = "/tmp/partial.tif"; | |
String dstPath = "/tmp/cogeo.tif"; | |
Files.copy(Paths.get(srcPath), Paths.get(tmpPath), REPLACE_EXISTING); | |
Dataset src = gdal.Open(tmpPath, gdalconst.GA_Update); | |
assertThat(src).isNotNull(); | |
int[] overviewList = {2, 4, 8, 16, 32}; | |
assertThat(src.BuildOverviews("average", overviewList)).isEqualTo(gdalconst.CE_None); | |
// Be agressive about shoving this to disk. | |
// src.FlushCache(); | |
// src.delete(); | |
// src = dal.Open(srcPath, gdalconst.GA_ReadOnly); | |
Vector<String> options = new Vector<>(ImmutableList.of("TILED=YES", "COMPRESS=LZW", | |
"COPY_SRC_OVERVIEWS=YES")); | |
Dataset dst = driver.CreateCopy(dstPath, src, options); | |
assertThat(dst).isNotNull(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment