Skip to content

Commit 6a57e06

Browse files
committed
Unit tests around implicit file:// for schemeless paths with leading /
Signed-off-by: Jason T. Brown <[email protected]>
1 parent 371e4c8 commit 6a57e06

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

core/src/test/scala/org/locationtech/rasterframes/ref/RasterSourceSpec.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ class RasterSourceSpec extends TestEnvironment with TestData {
106106
val src = RasterSource(localSrc)
107107
assert(!src.extent.isEmpty)
108108
}
109+
it("should interpret no scheme as file://"){
110+
val localSrc = geotiffDir.resolve("LC08_B7_Memphis_COG.tiff").toString()
111+
val schemelessUri = new URI(localSrc)
112+
val src = RasterSource(schemelessUri)
113+
assert(!src.extent.isEmpty)
114+
}
109115
}
110116

111117
if(GDALRasterSource.hasGDAL) {

pyrasterframes/src/main/python/tests/GeoTiffWriterTests.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ def _tmpfile():
3333

3434
def test_identity_write(self):
3535
rf = self.spark.read.geotiff(self.img_uri)
36+
rf_count = rf.count()
37+
self.assertTrue(rf_count > 0)
3638

3739
dest = self._tmpfile()
3840
rf.write.geotiff(dest)
3941

40-
rf2 = self.spark.read.geotiff('file://' + dest)
42+
rf2 = self.spark.read.geotiff(dest)
43+
4144
self.assertEqual(rf2.count(), rf.count())
4245

4346
os.remove(dest)
@@ -47,7 +50,7 @@ def test_unstructured_write(self):
4750
dest_file = self._tmpfile()
4851
rf.write.geotiff(dest_file, crs='EPSG:32616')
4952

50-
rf2 = self.spark.read.raster('file://' + dest_file)
53+
rf2 = self.spark.read.raster(dest_file)
5154
self.assertEqual(rf2.count(), rf.count())
5255

5356
with rasterio.open(self.img_uri) as source:
@@ -58,6 +61,22 @@ def test_unstructured_write(self):
5861

5962
os.remove(dest_file)
6063

64+
def test_unstructured_write_schemeless(self):
65+
# should be able to write a projected raster tile column to path like '/data/foo/file.tif'
66+
from pyrasterframes.rasterfunctions import rf_agg_stats, rf_crs
67+
rf = self.spark.read.raster(self.img_uri)
68+
max = rf.agg(rf_agg_stats('proj_raster').max.alias('max')).first()['max']
69+
crs = rf.select(rf_crs('proj_raster').crsProj4.alias('c')).first()['c']
70+
71+
dest_file = self._tmpfile()
72+
self.assertTrue(not dest_file.startswith('file://'))
73+
rf.write.geotiff(dest_file, crs=crs)
74+
75+
with rasterio.open(dest_file) as src:
76+
self.assertEqual(src.read().max(), max)
77+
78+
os.remove(dest_file)
79+
6180
def test_downsampled_write(self):
6281
rf = self.spark.read.raster(self.img_uri)
6382
dest = self._tmpfile()

pyrasterframes/src/main/python/tests/PyRasterFramesTests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ def l8path(b):
470470
print(path_count.toPandas())
471471
self.assertTrue(path_count.count() == 3)
472472

473+
def test_raster_source_reader_schemeless(self):
474+
import os.path
475+
path = os.path.join(self.resource_dir, "L8-B8-Robinson-IL.tiff")
476+
self.assertTrue(not path.startswith('file://'))
477+
df = self.spark.read.raster(path)
478+
self.assertTrue(df.count() > 0)
479+
473480
def test_raster_source_catalog_reader(self):
474481
import pandas as pd
475482

0 commit comments

Comments
 (0)