GeoTrellis

GeoTrellis

    ›Vector

    Getting Started

    • Getting Started
    • Reading Scala

    Vector

    • Vectors
    • Extents
    • Projection

    Raster

    • Rasters
    • Tiles
    • RasterSource
    • Rendering Images

    Layer

    • Layer Model

    Spark

    • Basics
    • Tile Layer RDD
    • Indexed Layers

    Projection

    GoeTrellis uses Proj4J library to work with coordinate reference systems. In practice Proj4J classes are hidden behind the geotrellis.proj4.CRS trait which provides Scala API into the library.

    import geotrellis.proj4._
    
    val wgs84 = LatLng
    // wgs84: LatLng.type = LatLng
    val utm15N = CRS.fromEpsgCode(2027)
    // utm15N: CRS = EPSG:2027
    val southPA = CRS.fromString("+proj=lcc +lat_1=40.96666666666667 +lat_2=39.93333333333333 +lat_0=39.33333333333334 +lon_0=-77.75 +x_0=600000 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs")
    // southPA: CRS = lcc-CS
    

    Reproject

    GeoTrellis adds reproject methods to geometry and raster instances through implicit methods extension which allow their transformation between two coordinate reference systems.

    import geotrellis.vector._
    import geotrellis.raster._
    
    val philly = Point(-75.1652, 39.9526)
    // philly: Point = POINT (-75.1652 39.9526)
    
    philly.reproject(LatLng, southPA)
    // res0: Point = POINT (2693060.2165455655 236194.91633822946)
    
    val raster = Raster(
      tile = ArrayTile.empty(DoubleCellType, 2, 2),
      extent = philly.buffer(0.01).extent)
    // raster: Raster[MutableArrayTile] = Raster(
    //   DoubleRawArrayTile(Array(0.0, 0.0, 0.0, 0.0), 2, 2),
    //   Extent(-75.1752, 39.9426, -75.1552, 39.962599999999995)
    // )
    
    raster.reproject(LatLng, southPA)
    // res1: SinglebandRaster = Raster(
    //   DoubleRawArrayTile(Array(0.0, 0.0, 0.0, 0.0), 2, 2),
    //   Extent(
    //     2690151.6598284524,
    //     233236.29156599852,
    //     2696833.7380493623,
    //     239918.36978690865
    //   )
    // )
    

    Note that neither Geometry nor Raster actually carry associated projection with them. It is up to the developer and the application to ensure that the reprojection being applied is consistent with the source data. Commonly small applications or batch jobs will know the source projection of the data during development. However, its a common source of perplexing data errors.

    When building more complicated applications it may be helpful to associate the projection information with the rasters data using ProjectedRaster class.

    ProjectedRaster(raster, LatLng)
    
    ← ExtentsRasters →
    • Reproject
    GeoTrellis
    Community
    User ShowcaseGitter.im
    More
    BlogStar
    Copyright © 2020 Azavea