Geotrellis学习(3)-Reading GeoTiffs

  • 本教程的目的是教我们如何使用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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 11,096评论 6 13
  • ORA-00001: 违反唯一约束条件 (.) 错误说明:当在唯一索引所对应的列上键入重复值时,会触发此异常。 O...
    我想起个好名字阅读 5,423评论 0 9
  • 一、基础知识:1、JVM、JRE和JDK的区别:JVM(Java Virtual Machine):java虚拟机...
    杀小贼阅读 2,404评论 0 4
  • WinRAR - 最新版本的更新 版本 5.50 1. WinRAR 和命令行 RAR 默认使用 RAR ...
    王舒璇阅读 2,412评论 0 2
  • 文字/素言淡漠 七月的太阳 像极了一个暴君 毒辣辣的日头肆虐 地上的水分蒸发成热气 包裹着生灵无处藏身 我计划着一...
    素言淡漠阅读 272评论 0 0