Skip to content

Commit

Permalink
Expand KMLSuperOverlay tile size to 512 < side < 1024px rather than 2…
Browse files Browse the repository at this point in the history
…00 < side < 400px
  • Loading branch information
rcoup authored and craigds committed Jul 1, 2024
1 parent 95249de commit bab2b07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 59 deletions.
74 changes: 18 additions & 56 deletions autotest/gdrivers/kmlsuperoverlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def setup_and_cleanup():


def test_kmlsuperoverlay_1():

tst = gdaltest.GDALTest(
"KMLSUPEROVERLAY", "small_world.tif", 1, 30111, options=["FORMAT=PNG"]
)
Expand All @@ -72,7 +71,6 @@ def test_kmlsuperoverlay_1():


def test_kmlsuperoverlay_2():

tst = gdaltest.GDALTest(
"KMLSUPEROVERLAY", "small_world.tif", 1, 30111, options=["FORMAT=PNG"]
)
Expand All @@ -85,7 +83,6 @@ def test_kmlsuperoverlay_2():


def test_kmlsuperoverlay_3():

src_ds = gdal.Open("data/utm.tif")
ds = gdal.GetDriverByName("KMLSUPEROVERLAY").CreateCopy("tmp/tmp.kml", src_ds)
del ds
Expand All @@ -100,35 +97,21 @@ def test_kmlsuperoverlay_3():
assert "<east>-117.309" in data, data
assert "<west>-117.639" in data, data

filelist = [
"tmp/0/0/0.jpg",
"tmp/0/0/0.kml",
"tmp/1/0/0.jpg",
"tmp/1/0/0.kml",
"tmp/1/0/1.jpg",
"tmp/1/0/1.kml",
"tmp/1/1/0.jpg",
"tmp/1/1/0.kml",
"tmp/1/1/1.jpg",
"tmp/1/1/1.kml",
"tmp/tmp.kml",
]
# Kx: modified from upstream tests
# (since we've changed the kmlsuperoverlay target tile size to 1024px, we have less files)
filelist = ["tmp/0/0/0.jpg", "tmp/0/0/0.kml", "tmp/tmp.kml"]
for filename in filelist:
try:
os.remove(filename)
except OSError:
pytest.fail("Missing file: %s" % filename)

shutil.rmtree("tmp/0")
shutil.rmtree("tmp/1")


###############################################################################
# Test overviews


def test_kmlsuperoverlay_4():

vrt_xml = """<VRTDataset rasterXSize="800" rasterYSize="400">
<SRS>GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]</SRS>
<GeoTransform> -1.8000000000000000e+02, 4.5000000000000001e-01, 0.0000000000000000e+00, 9.0000000000000000e+01, 0.0000000000000000e+00, -4.5000000000000001e-01</GeoTransform>
Expand Down Expand Up @@ -189,13 +172,7 @@ def test_kmlsuperoverlay_4():
)
assert ds.GetMetadataItem("NAME") == "myname"
assert ds.GetMetadataItem("DESCRIPTION") == "mydescription"
if ds.GetRasterBand(1).GetOverviewCount() != 1:
ds = None
src_ds = None
gdal.Unlink("/vsimem/src.vrt")
gdal.Unlink("/vsimem/kmlsuperoverlay_4.kmz")
pytest.fail()
if ds.GetRasterBand(1).GetOverview(0).Checksum() != 30111:
if ds.GetRasterBand(1).GetOverviewCount() != 0:
ds = None
src_ds = None
gdal.Unlink("/vsimem/src.vrt")
Expand Down Expand Up @@ -232,7 +209,6 @@ def test_kmlsuperoverlay_4():


def test_kmlsuperoverlay_5():

from xml.etree import ElementTree

src_ds = gdal.Open(
Expand Down Expand Up @@ -275,10 +251,6 @@ def test_kmlsuperoverlay_5():
files = [
"tmp/tmp.kml",
"tmp/0/0/0.kml",
"tmp/1/0/0.kml",
"tmp/1/0/1.kml",
"tmp/1/1/0.kml",
"tmp/1/1/1.kml",
]

for f in files:
Expand All @@ -301,7 +273,6 @@ def test_kmlsuperoverlay_5():


def test_kmlsuperoverlay_6():

ds = gdal.Open("data/kml/kmlimage.kmz")
assert ds.GetProjectionRef().find("WGS_1984") >= 0
got_gt = ds.GetGeoTransform()
Expand Down Expand Up @@ -332,7 +303,6 @@ def test_kmlsuperoverlay_6():


def test_kmlsuperoverlay_7():

ds = gdal.Open("data/kml/small_world.kml")
assert ds.GetProjectionRef().find("WGS_1984") >= 0
got_gt = ds.GetGeoTransform()
Expand All @@ -350,7 +320,6 @@ def test_kmlsuperoverlay_7():


def test_kmlsuperoverlay_single_overlay_document_folder_pct():

ds = gdal.Open("data/kml/small_world_in_document_folder_pct.kml")
assert ds.GetProjectionRef().find("WGS_1984") >= 0
got_gt = ds.GetGeoTransform()
Expand All @@ -367,7 +336,6 @@ def test_kmlsuperoverlay_single_overlay_document_folder_pct():


def test_kmlsuperoverlay_single_overlay_document_pct():

ds = gdal.Open("data/kml/small_world_in_document_pct.kml")
assert ds.GetProjectionRef().find("WGS_1984") >= 0
got_gt = ds.GetGeoTransform()
Expand All @@ -385,10 +353,9 @@ def test_kmlsuperoverlay_single_overlay_document_pct():


def test_kmlsuperoverlay_8():

# a large raster with actual data on each end and blank space in between
src_ds = gdal.Open(
"""<VRTDataset rasterXSize="2048" rasterYSize="512">
"""<VRTDataset rasterXSize="4096" rasterYSize="1024">
<SRS>GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]</SRS>
<GeoTransform> 0, 0.01, 0, 0, 0, 0.01</GeoTransform>
<VRTRasterBand dataType="Byte" band="1">
Expand All @@ -398,14 +365,14 @@ def test_kmlsuperoverlay_8():
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="1024" ySize="1024" />
</SimpleSource>
<SimpleSource>
<SourceFilename relativeToVRT="1">data/utm.tif</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="1024" ySize="1024" />
</SimpleSource>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="2">
Expand All @@ -415,14 +382,14 @@ def test_kmlsuperoverlay_8():
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="1024" ySize="1024" />
</SimpleSource>
<SimpleSource>
<SourceFilename relativeToVRT="1">data/utm.tif</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="1024" ySize="1024" />
</SimpleSource>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="3">
Expand All @@ -432,14 +399,14 @@ def test_kmlsuperoverlay_8():
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="1024" ySize="1024" />
</SimpleSource>
<SimpleSource>
<SourceFilename relativeToVRT="1">data/utm.tif</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="1024" ySize="1024" />
</SimpleSource>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="4">
Expand All @@ -449,7 +416,7 @@ def test_kmlsuperoverlay_8():
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="0" yOff="0" xSize="1024" ySize="1024" />
<ScaleOffset>255</ScaleOffset>
<ScaleRatio>0</ScaleRatio>
</ComplexSource>
Expand All @@ -458,7 +425,7 @@ def test_kmlsuperoverlay_8():
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="512" RasterYSize="512" DataType="Byte" BlockXSize="512" BlockYSize="16" />
<SrcRect xOff="0" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="512" ySize="512" />
<DstRect xOff="1536" yOff="0" xSize="1024" ySize="1024" />
<ScaleOffset>255</ScaleOffset>
<ScaleRatio>0</ScaleRatio>
</ComplexSource>
Expand All @@ -472,7 +439,9 @@ def test_kmlsuperoverlay_8():
src_ds = None

assert set(os.listdir("tmp/0/0")) == set(("0.kml", "0.png"))
assert set(os.listdir("tmp/3/1")) == set(
# Kx: modified from upstream tests
# (since we've changed the kmlsuperoverlay target tile size to 1024px, we have less files)
assert set(os.listdir("tmp/2/0")) == set(
(
"0.jpg",
"0.kml",
Expand All @@ -482,17 +451,10 @@ def test_kmlsuperoverlay_8():
"2.kml",
"3.jpg",
"3.kml",
"4.jpg",
"4.kml",
"5.jpg",
"5.kml",
"6.jpg",
"6.kml",
"7.jpg",
"7.kml",
)
)
assert set(os.listdir("tmp/3/2")) == set()
# dir should be empty - 2/3 is entirely transparent so we skip generating files.
assert set(os.listdir("tmp/2/3")) == set()

shutil.rmtree("tmp/0")
shutil.rmtree("tmp/1")
Expand Down
7 changes: 4 additions & 3 deletions frmts/kmlsuperoverlay/kmlsuperoverlaydataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,11 @@ KmlSuperOverlayCreateCopy(const char *pszFilename, GDALDataset *poSrcDS,
int tilexsize;
int tileysize;
// Let the longer side determine the max zoom level and x/y tilesizes.
if (xsize >= ysize)
// tilesizes will be between 512 and 1024px
if ( xsize >= ysize )
{
double dtilexsize = xsize;
while (dtilexsize > 400) // calculate x tile size
while (dtilexsize > 1024) //calculate x tile size
{
dtilexsize = dtilexsize / 2;
maxzoom++;
Expand All @@ -738,7 +739,7 @@ KmlSuperOverlayCreateCopy(const char *pszFilename, GDALDataset *poSrcDS,
else
{
double dtileysize = ysize;
while (dtileysize > 400) // calculate y tile size
while (dtileysize > 1024) //calculate y tile size
{
dtileysize = dtileysize / 2;
maxzoom++;
Expand Down

0 comments on commit bab2b07

Please sign in to comment.