- 本教程的目的是教我们如何使用Geotrellis从本地文件系统读取GeoTiff文件。
- 数据来源
- GeoTiff是一种最常用的存储地理空间信息数据的格式之一。
读取单波段/多波段影像
import geotrellis.raster.io.geotiff.{MultibandGeoTiff, SinglebandGeoTiff}
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
val path:String = "C:\\Users\\79128\\IdeaProjects\\Geotrellis\\geotrellis-sbt-template\\geotrellis\\raster\\data\\geotiff-test-files\\jpeg-test-deflate-small.tif"
//读取单波段
val geoTiff:SinglebandGeoTiff = GeoTiffReader.readSingleband(path);
//读取多波段影像
val geoTiff2:MultibandGeoTiff = GeoTiffReader.readMultiband(path)
此外,也可以用影像路径为参数直接构造一个Geotiff对象
val geoTiff3:SinglebandGeoTiff = SinglebandGeoTiff(path)
val geoTiff4: MultibandGeoTiff = MultibandGeoTiff(path)
处理压缩的GeoTiff--
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
import geotrellis.raster.io.geotiff._
// reading in a compressed GeoTiff and keeping it compressed
val compressedGeoTiff: SinglebandGeoTiff = GeoTiffReader.readSingleband("path/to/compressed/geotiff.tif", false, false)
// reading in a compressed GeoTiff and uncompressing it
val compressedGeoTiff: SinglebandGeoTiff = GeoTiffReader.readSingleband("path/to/compressed/geotiff.tif", true, false)
第一个Boolean类型的参数表示文件是否需要解压
第二个Boolean类型的参数表示
默认需要解压
有问题提示沒有該方法
GeoTiffReader.readSingleband("path/to/compressed/geotiff.tif")
GeoTiffReader.readSingleband("path/to/compressed/geotiff.tif", true, false)
根据提供的范围和文件路径,裁切现有文件
val path: String = "path/to/my/geotiff.tif"
val e: Extent = Extent(0, 1, 2, 3)
// supplying the extent as an Extent
// if the file is singleband
SinglebandGeoTiff(path, e)
// or
GeoTiffReader.readSingleband(path, e)
// if the file is multiband
MultibandGeoTiff(path, e)
// or
GeoTiffReader.readMultiband(path, e)
// supplying the extent as an Option[Extent]
// if the file is singleband
SinglebandGeoTiff(path, Some(e))
// or
GeoTiffReader.readSingleband(path, Some(e))
// if the file is multiband
MultibandGeoTiff(path, Some(e))
// or
GeoTiffReader.readMultiband(path, Some(e))
val path: String = "path/to/my/geotiff.tif"
val e: Extent = Extent(0, 1, 2, 3)
// doing the reading and cropping in one line
// if the file is singleband
SinglebandGeoTiff.streaming(path).crop(e)
// or
GeoTiffReader.readSingleband(path, false, true).crop(e)
// if the file is multiband
MultibandGeoTiff.streaming(path).crop(e)
// or
GeoTiffReader.readMultiband(path, false, true).crop(e)
// doing the reading and cropping in two lines
// if the file is singleband
val sgt: SinglebandGeoTiff =
SinglebandGeoTiff.streaming(path)
// or
GeoTiffReader.readSingleband(path, false, true)
sgt.crop(e)
// if the file is multiband
val mgt: MultibandGeoTiff =
MultibandGeoTiff.streaming(path)
// or
GeoTiffReader.readMultiband(path, false, true)
mgt.crop(e)
网友评论