使用Geotrellis厉斟,首先得明白geotrellis里面的一些概念挚躯,這些對(duì)于初學(xué)者來(lái)說(shuō)是至關(guān)重要的。
- Tile:A grid of numeric cells that represent some data on the Earth.這是官方給的解釋?zhuān)瑐€(gè)人理解為一個(gè)多維數(shù)組捏膨,在geotrellis里面可以從構(gòu)造方法來(lái)理解秧均,一個(gè)array數(shù)組,加上行列号涯,就構(gòu)成了二維數(shù)組目胡,再加上celltype。
- Extent=Bounding Box((bbox):一個(gè)軸對(duì)稱(chēng)的矩形區(qū)域链快,Extent(-109, 37, -102, 41),通常是經(jīng)緯度(方里網(wǎng))信息(Xmin,Ymin,Xmax,Ymax)
- Raster:A Tile with an Extent; places data over a specific region of the Earth誉己,也就是沒(méi)有投影信息的GEOTIFF。Raster(Tile[T],Extent(?,?,?,?))
- TileLayout(7, 4, 100, 100) 得到一個(gè)7x4的Tiles,每個(gè)tile里面有100x100個(gè)cells
- Vector=Geometry:通過(guò)連續(xù)的點(diǎn)進(jìn)行構(gòu)建的矢量數(shù)據(jù)域蜗,包括點(diǎn)巨双、線(xiàn)、面霉祸。
- Feature:vector或者geometry加上元數(shù)據(jù)筑累,也就是矢量數(shù)據(jù),加上其所代表的值丝蹭。Feature(Geometry,data)
- Layout Definition = Layout: 看構(gòu)造方法 LayoutDefinition(Extent, TileLayout)慢宗,也就是定義了瓦片的布局,以此建立索引,關(guān)聯(lián)瓦片的key和對(duì)應(yīng)的地理位置镜沽,反之亦然敏晤。
- Layer or Tile Layer:tiles和keys結(jié)合的一種數(shù)據(jù)結(jié)構(gòu),附帶有元數(shù)據(jù)信息缅茉。代表了在分布式計(jì)算環(huán)境中一個(gè)很大的柵格嘴脾。
在非分布式環(huán)境下的柵格數(shù)據(jù)(.tif .geotiff .TIFF)讀取
tiff文件讀取
import geotrellis.raster._
val geotiff = GeoTiff.readSingleband(bandpath)
val multibandGeoTiff = GeoTiff.readMultiband(path)
//或者進(jìn)行直接調(diào)用
val geotiff = GeoTiffReader.readSingleband(path)
val geotiff = GeoTiffReader.readMultiband(path)
非分布式環(huán)境下矢量數(shù)據(jù)讀取
shp文件讀取
import geotrellis.shapefile.ShapeFileReader
import geotrellis.vector.{Polygon, PolygonFeature}
val path = ""
val features = ShapeFileReader.readPolygonFeatures(path)
//輸出這些shp里面屬性的key
for(PolygonFeature(polygon: Polygon, data: Map[String, Object]) <- features) {
data.keys.toSeq.foreach(println(_))
}
geojson文件讀取
import scala.io.Source
val geojson = Source.fromFile("").getLines.mkString
import geotrellis.vector.io.json._
val gjCol = geojson.parseGeoJson[JsonFeatureCollection]
val pf = gjCol.getAllPolygonFeatures()