-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE OR REPLACE FUNCTION ST_partitionCentroid as 'com.azavea.hiveless.spatial.index.ST_PartitionCentroid'; |
45 changes: 45 additions & 0 deletions
45
spatial-index/src/main/scala/com/azavea/hiveless/spatial/index/ST_PartitionCentroid.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2022 Azavea | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.azavea.hiveless.spatial.index | ||
|
||
import com.azavea.hiveless.HUDF | ||
import com.azavea.hiveless.spatial._ | ||
import geotrellis.layer.{SpatialKey, ZoomedLayoutScheme} | ||
import geotrellis.vector._ | ||
import geotrellis.proj4.{CRS, LatLng} | ||
import geotrellis.store.index.zcurve.Z2 | ||
import org.locationtech.jts.geom.Geometry | ||
|
||
class ST_PartitionCentroid extends HUDF[(Geometry, Int, Option[CRS], Option[Int], Option[Double], Option[Int]), Long] { | ||
val name: String = "st_partitionCentroid" | ||
def function = { | ||
case (geom: Geometry, zoom: Int, crsOpt: Option[CRS], tileSizeOpt: Option[Int], resolutionThresholdOpt: Option[Double], bitsOpt: Option[Int]) => | ||
// set default values | ||
val crs = crsOpt.getOrElse(LatLng) | ||
val tileSize = tileSizeOpt.getOrElse(ZoomedLayoutScheme.DEFAULT_TILE_SIZE) | ||
val resolutionThreshold = resolutionThresholdOpt.getOrElse(ZoomedLayoutScheme.DEFAULT_RESOLUTION_THRESHOLD) | ||
val bits = bitsOpt.getOrElse(8) | ||
|
||
// compute key | ||
val SpatialKey(col, row) = new ZoomedLayoutScheme(crs, tileSize, resolutionThreshold) | ||
.levelForZoom(zoom) | ||
.layout | ||
.mapTransform(geom.extent.center) | ||
|
||
Z2(col, row).z >> bits | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
spatial-index/src/main/scala/com/azavea/hiveless/spatial/index/package.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2022 Azavea | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.azavea.hiveless.spatial | ||
|
||
import com.azavea.hiveless.serializers.{HConverter, HSerializer, UnaryDeserializer} | ||
import com.azavea.hiveless.implicits.syntax._ | ||
import cats.Id | ||
import geotrellis.proj4.CRS | ||
import org.apache.spark.sql.types.{DataType, StringType} | ||
|
||
package object index { | ||
implicit def crsConverter: HConverter[CRS] = new HConverter[CRS] { | ||
def convert(argument: Any): CRS = CRS.fromString(argument.convert[String]) | ||
} | ||
|
||
implicit def crsUnaryDeserializer: UnaryDeserializer[Id, CRS] = | ||
(arguments, inspectors) => arguments.deserialize[Id, String](inspectors).convert[CRS] | ||
|
||
implicit def crsSerializer: HSerializer[CRS] = new HSerializer[CRS] { | ||
def dataType: DataType = StringType | ||
def serialize: CRS => Any = crs => crs.toProj4String.serialize | ||
} | ||
} |
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