geotrellis初体验

作者: 胜利路10号 | 来源:发表于2018-12-22 16:00 被阅读0次

    使用Geotrellis,首先得明白geotrellis里面的一些概念,这些对于初学者来说是至关重要的。

    1. Tile:A grid of numeric cells that represent some data on the Earth.这是官方给的解释,个人理解为一个多维数组,在geotrellis里面可以从构造方法来理解,一个array数组,加上行列,就构成了二维数组,再加上celltype。
    2. Extent=Bounding Box((bbox):一个轴对称的矩形区域,Extent(-109, 37, -102, 41),通常是经纬度(方里网)信息(Xmin,Ymin,Xmax,Ymax)
    3. Raster:A Tile with an Extent; places data over a specific region of the Earth,也就是没有投影信息的GEOTIFF。Raster(Tile[T],Extent(?,?,?,?))
    4. TileLayout(7, 4, 100, 100) 得到一个7x4的Tiles,每个tile里面有100x100个cells
    5. Vector=Geometry:通过连续的点进行构建的矢量数据,包括点、线、面。
    6. Feature:vector或者geometry加上元数据,也就是矢量数据,加上其所代表的值。Feature(Geometry,data)
    7. Layout Definition = Layout: 看构造方法 LayoutDefinition(Extent, TileLayout),也就是定义了瓦片的布局,以此建立索引,关联瓦片的key和对应的地理位置,反之亦然。
    8. Layer or Tile Layer:tiles和keys结合的一种数据结构,附带有元数据信息。代表了在分布式计算环境中一个很大的栅格。

    在非分布式环境下的栅格数据(.tif .geotiff .TIFF)读取

    tiff文件读取
    import geotrellis.raster._ 
    val geotiff = GeoTiff.readSingleband(bandpath)
    val multibandGeoTiff = GeoTiff.readMultiband(path)
    
    //或者进行直接调用
    val geotiff = GeoTiffReader.readSingleband(path)
    val geotiff = GeoTiffReader.readMultiband(path)
    

    非分布式环境下矢量数据读取

    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()
    

    相关文章

      网友评论

        本文标题:geotrellis初体验

        本文链接:https://www.haomeiwen.com/subject/griikqtx.html