Skip to content

Commit 047a63d

Browse files
committed
PR feedback.
1 parent 0ec9b6e commit 047a63d

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

core/src/main/scala/org/locationtech/rasterframes/RasterFunctions.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,38 @@ trait RasterFunctions {
6262
/** Extracts the bounding box from a RasterSource or ProjectedRasterTile */
6363
def rf_extent(col: Column): TypedColumn[Any, Extent] = GetExtent(col)
6464

65-
/** Constructs a XZ2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS
65+
/** Constructs a XZ2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS.
6666
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
6767
def rf_xz2_index(targetExtent: Column, targetCRS: Column, indexResolution: Short) = XZ2Indexer(targetExtent, targetCRS, indexResolution)
6868

6969
/** Constructs a XZ2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS
7070
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
7171
def rf_xz2_index(targetExtent: Column, targetCRS: Column) = XZ2Indexer(targetExtent, targetCRS, 18: Short)
7272

73-
/** Constructs a XZ2 index with level 18 resolution in WGS84 from either a ProjectedRasterTile or RasterSource
73+
/** Constructs a XZ2 index with provided resolution level in WGS84 from either a ProjectedRasterTile or RasterSource.
7474
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
7575
def rf_xz2_index(targetExtent: Column, indexResolution: Short) = XZ2Indexer(targetExtent, indexResolution)
7676

77-
/** Constructs a XZ2 index with level 18 resolution in WGS84 from either a ProjectedRasterTile or RasterSource
77+
/** Constructs a XZ2 index with level 18 resolution in WGS84 from either a ProjectedRasterTile or RasterSource.
7878
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
7979
def rf_xz2_index(targetExtent: Column) = XZ2Indexer(targetExtent, 18: Short)
8080

81-
/** Constructs a Z2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS
81+
/** Constructs a Z2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS.
8282
* First the native extent is extracted or computed, and then center is used as the indexing location.
8383
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
8484
def rf_z2_index(targetExtent: Column, targetCRS: Column, indexResolution: Short) = Z2Indexer(targetExtent, targetCRS, indexResolution)
8585

86-
/** Constructs a Z2 index in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS
86+
/** Constructs a Z2 index with index resolution of 31 in WGS84 from either a Geometry, Extent, ProjectedRasterTile, or RasterSource and its CRS.
8787
* First the native extent is extracted or computed, and then center is used as the indexing location.
8888
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
8989
def rf_z2_index(targetExtent: Column, targetCRS: Column) = Z2Indexer(targetExtent, targetCRS, 31: Short)
9090

91-
/** Constructs a Z2 index with level 18 resolution in WGS84 from either a ProjectedRasterTile or RasterSource
91+
/** Constructs a Z2 index with the given index resolution in WGS84 from either a ProjectedRasterTile or RasterSource
9292
* First the native extent is extracted or computed, and then center is used as the indexing location.
9393
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
9494
def rf_z2_index(targetExtent: Column, indexResolution: Short) = Z2Indexer(targetExtent, indexResolution)
9595

96-
/** Constructs a Z2 index with level 18 resolution in WGS84 from either a ProjectedRasterTile or RasterSource
96+
/** Constructs a Z2 index with index resolution of 31 in WGS84 from either a ProjectedRasterTile or RasterSource
9797
* First the native extent is extracted or computed, and then center is used as the indexing location.
9898
* For details: https://www.geomesa.org/documentation/user/datastores/index_overview.html */
9999
def rf_z2_index(targetExtent: Column) = Z2Indexer(targetExtent, 31: Short)

core/src/main/scala/org/locationtech/rasterframes/expressions/transformers/XZ2Indexer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ case class XZ2Indexer(left: Expression, right: Expression, indexResolution: Shor
6161

6262
override def checkInputDataTypes(): TypeCheckResult = {
6363
if (!envelopeExtractor.isDefinedAt(left.dataType))
64-
TypeCheckFailure(s"Input type '${left.dataType}' does not look like something with an Extent or something with one.")
64+
TypeCheckFailure(s"Input type '${left.dataType}' does not look like a geometry, extent, or something with one.")
6565
else if(!crsExtractor.isDefinedAt(right.dataType))
66-
TypeCheckFailure(s"Input type '${right.dataType}' does not look like something with a CRS.")
66+
TypeCheckFailure(s"Input type '${right.dataType}' does not look like a CRS or something with one.")
6767
else TypeCheckSuccess
6868
}
6969

core/src/main/scala/org/locationtech/rasterframes/expressions/transformers/Z2Indexer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ case class Z2Indexer(left: Expression, right: Expression, indexResolution: Short
6262

6363
override def checkInputDataTypes(): TypeCheckResult = {
6464
if (!centroidExtractor.isDefinedAt(left.dataType))
65-
TypeCheckFailure(s"Input type '${left.dataType}' does not look like something with a point.")
65+
TypeCheckFailure(s"Input type '${left.dataType}' does not look like something with a centroid.")
6666
else if(!crsExtractor.isDefinedAt(right.dataType))
67-
TypeCheckFailure(s"Input type '${right.dataType}' does not look like something with a CRS.")
67+
TypeCheckFailure(s"Input type '${right.dataType}' does not look like a CRS or something with one.")
6868
else TypeCheckSuccess
6969
}
7070

datasource/src/main/scala/org/locationtech/rasterframes/datasource/raster/RasterSourceRelation.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import org.locationtech.rasterframes.tiles.ProjectedRasterTile
4242
* @param bandIndexes band indexes to fetch
4343
* @param subtileDims how big to tile/subdivide rasters info
4444
* @param lazyTiles if true, creates a lazy representation of tile instead of fetching contents.
45-
* @param spatialIndexPartitions if not None, adds a spatial index. If Option value < 1, uses the value of `numShufflePartitions` in SparkContext.
45+
* @param spatialIndexPartitions Number of spatial index-based partitions to create.
46+
* If Option value > 0, that number of partitions are created after adding a spatial index.
47+
* If Option value <= 0, uses the value of `numShufflePartitions` in SparkContext.
48+
* If None, no spatial index is added and hash partitioning is used.
4649
*/
4750
case class RasterSourceRelation(
4851
sqlContext: SQLContext,

docs/src/main/paradox/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Constructs a XZ2 index in WGS84/EPSG:4326 from either a Geometry, Extent, Projec
8181
Long rf_z2_index(Extent extent, CRS crs)
8282
Long rf_z2_index(ProjectedRasterTile proj_raster)
8383

84-
Constructs a Z2 index in WGS84/EPSG:4326 from either a Geometry, Extent, ProjectedRasterTile and its CRS. First the native extent is extracted or computed, and then center is used as the indexing location. This function is useful for [range partitioning](http://spark.apache.org/docs/latest/api/python/pyspark.sql.html?highlight=registerjava#pyspark.sql.DataFrame.repartitionByRange).
84+
Constructs a Z2 index in WGS84/EPSG:4326 from either a Geometry, Extent, ProjectedRasterTile and its CRS. First the native extent is extracted or computed, and then center is used as the indexing location. This function is useful for [range partitioning](http://spark.apache.org/docs/latest/api/python/pyspark.sql.html?highlight=registerjava#pyspark.sql.DataFrame.repartitionByRange). See @ref:[Reading Raster Data](raster-read.md#spatial-indexing-and-partitioning) section for details on how to have an index automatically added when reading raster data.
8585

8686
## Tile Metadata and Mutation
8787

docs/src/main/paradox/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Updated to GeoTrellis 2.3.3 and Proj4j 1.1.0.
2424
* Fixed issues with `LazyLogger` and shading assemblies ([#293](https://github.com/locationtech/rasterframes/issues/293))
2525
* Updated `rf_crs` to accept string columns containing CRS specifications. ([#366](https://github.com/locationtech/rasterframes/issues/366))
26-
* Added `rf_xz2_index` function. ([#368](https://github.com/locationtech/rasterframes/issues/368))
26+
* Added `rf_spatial_index` function. ([#368](https://github.com/locationtech/rasterframes/issues/368))
2727
* _Breaking_ (potentially): removed `pyrasterframes.create_spark_session` in lieu of `pyrasterframes.utils.create_rf_spark_session`
2828

2929
### 0.8.2

pyrasterframes/src/main/python/pyrasterframes/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,15 @@ def temp_name():
149149
if band_indexes is None:
150150
band_indexes = [0]
151151

152-
if spatial_index_partitions is False:
153-
spatial_index_partitions = None
154-
155-
if spatial_index_partitions is not None:
156-
if spatial_index_partitions is True:
152+
if spatial_index_partitions:
153+
num = int(spatial_index_partitions)
154+
if num < 0:
155+
spatial_index_partitions = '-1'
156+
elif num == 0:
157+
spatial_index_partitions = None
158+
159+
if spatial_index_partitions:
160+
if spatial_index_partitions == True:
157161
spatial_index_partitions = "-1"
158162
else:
159163
spatial_index_partitions = str(spatial_index_partitions)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ def test_catalog_named_arg(self):
213213
self.assertTrue(df.select('b1_path').distinct().count() == 3)
214214

215215
def test_spatial_partitioning(self):
216-
df = self.spark.read.raster(self.path(1, 1), spatial_index_partitions=True)
216+
f = self.path(1, 1)
217+
df = self.spark.read.raster(f, spatial_index_partitions=True)
217218
self.assertTrue('spatial_index' in df.columns)
218-
# Other tests?
219219

220+
self.assertEqual(df.rdd.getNumPartitions(), int(self.spark.conf.get("spark.sql.shuffle.partitions")))
221+
self.assertEqual(self.spark.read.raster(f, spatial_index_partitions=34).rdd.getNumPartitions(), 34)
222+
self.assertEqual(self.spark.read.raster(f, spatial_index_partitions="42").rdd.getNumPartitions(), 42)
223+
self.assertFalse('spatial_index' in self.spark.read.raster(f, spatial_index_partitions=False).columns)
224+
self.assertFalse('spatial_index' in self.spark.read.raster(f, spatial_index_partitions=0).columns)

0 commit comments

Comments
 (0)