
geotrellis.engine.ArgFileRasterLayer.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geotrellis-engine_2.11 Show documentation
Show all versions of geotrellis-engine_2.11 Show documentation
GeoTrellis is an open source geographic data processing engine for high performance applications.
/*
* Copyright (c) 2014 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 geotrellis.engine
import geotrellis.raster._
import geotrellis.raster.io.arg.ArgReader
import geotrellis.util.Filesystem
import com.typesafe.config.Config
import java.io.File
@deprecated("geotrellis-engine has been deprecated", "Geotrellis Version 0.10")
object ArgFileRasterLayerBuilder
extends RasterLayerBuilder {
def apply(ds: Option[String], jsonPath: String, json: Config): RasterLayer = {
val f =
if(json.hasPath("path")) {
val f = new File(json.getString("path"))
if(f.isAbsolute) {
f
} else {
new File(new File(jsonPath).getParent, f.getPath)
}
} else {
// Default to a .arg file with the same name as the layer name.
new File(new File(jsonPath).getParent, getName(json) + ".arg")
}
if(!f.exists) {
throw new java.io.IOException(s"[ERROR] ${f.getAbsolutePath} does not exist")
} else {
val cols = json.getInt("cols")
val rows = json.getInt("rows")
val (cellWidth, cellHeight) = getCellWidthAndHeight(json)
val rasterExtent = RasterExtent(getExtent(json), cellWidth, cellHeight, cols, rows)
val info =
RasterLayerInfo(
LayerId(ds, getName(json)),
getCellType(json),
rasterExtent,
getEpsg(json),
getXskew(json),
getYskew(json),
getCacheFlag(json)
)
new ArgFileRasterLayer(info, f.getAbsolutePath)
}
}
}
@deprecated("geotrellis-engine has been deprecated", "Geotrellis Version 0.10")
class ArgFileRasterLayer(info: RasterLayerInfo, val rasterPath: String)
extends UntiledRasterLayer(info) {
def getRaster(targetExtent: Option[RasterExtent]) = {
if(isCached) {
getCache.lookup[Array[Byte]](info.id.toString) match {
case Some(bytes) =>
targetExtent match {
case Some(re) =>
ArgReader.resampleBytes(bytes, info.cellType, info.rasterExtent, re)
case None =>
ArrayTile.fromBytes(bytes, info.cellType, info.rasterExtent.cols, info.rasterExtent.rows)
}
case None =>
sys.error("Cache problem: Layer thinks it's cached but it is in fact not cached.")
}
} else {
targetExtent match {
case Some(re) =>
ArgReader.read(rasterPath, info.cellType, info.rasterExtent, re)
case None =>
ArgReader.read(rasterPath, info.cellType, info.rasterExtent.cols, info.rasterExtent.rows)
}
}
}
def cache(c: Cache[String]) =
c.insert(info.id.toString, Filesystem.slurp(rasterPath))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy