读取单波段的栅格
import geotrellis.raster.io.geotiff.SinglebandGeoTiff
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
object demo4 {
def main(args:Array[String]): Unit = {
val geoTiff: SinglebandGeoTiff = GeoTiffReader.readSingleband("/Users/mocker/Documents/test/jpeg-test-small.tif");
println(geoTiff)
}
}
读取多波段栅格
mport geotrellis.raster.io.geotiff.{MultibandGeoTiff, SinglebandGeoTiff}
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
object demo4 {
def main(args:Array[String]): Unit = {
val geoTiff: MultibandGeoTiff = GeoTiffReader.readMultiband("/Users/mocker/Documents/test/jpeg-test-small.tif");
println(geoTiff)
}
使用流读取栅格
通过流读取的tif,单个小文件可以完整的读取,大文件则Java虚拟机会内存溢出崩溃,大文件和小文件都有一个共同之处,所选的区域越小读取的速度也快,所以对栅格读取区域的范围要严格的控制,避免程序崩溃。
使用流读取指定区域的栅格数据
import geotrellis.raster.io.geotiff.{MultibandGeoTiff, SinglebandGeoTiff}
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
import geotrellis.vector.Extent
object demo5 {
def main(args:Array[String]): Unit = {
val path: String = "/Volumes/Samsung_T5/1.tif";
//指定区域
val e: Extent = Extent(361557.21354599966, 3374714.92064873, 361559.67652580043, 3379714.2052475177);
//单波段读取
SinglebandGeoTiff(path, e)
GeoTiffReader.readSingleband(path, e)
//多波段读取
MultibandGeoTiff(path, e)
GeoTiffReader.readMultiband(path, e)
//单波段读取
SinglebandGeoTiff(path, Some(e))
GeoTiffReader.readSingleband(path, Some(e))
//多波段读取
MultibandGeoTiff(path, Some(e))
GeoTiffReader.readMultiband(path, Some(e))
}
使用流读取已加载的栅格进行裁剪
通过裁剪读取已经加载的tif数据,使用此方法不需要去读取文件,直接就可以访问数据,先加载文件再进行裁剪。
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
import geotrellis.raster.io.geotiff.{MultibandGeoTiff, SinglebandGeoTiff}
import geotrellis.vector.Extent
object demo6 {
def main(args:Array[String]): Unit = {
val path: String = "/Volumes/Samsung_T5/1.tif";
//指定区域
val e: Extent = Extent(361557.21354599966, 3374714.92064873, 361559.67652580043, 3379714.2052475177);
//单波段读取裁剪
SinglebandGeoTiff.streaming(path).crop(e)
println(SinglebandGeoTiff.streaming(path).crop(e))
GeoTiffReader.readSingleband(path, true).crop(e)
//多波段读取裁剪
MultibandGeoTiff.streaming(path).crop(e)
GeoTiffReader.readMultiband(path,true).crop(e)
}
}
a
网友评论