Created
July 5, 2017 18:08
-
-
Save echeipesh/4c361c9c59c9ba20953ce2724c3c7031 to your computer and use it in GitHub Desktop.
GeoTrellis Samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| s3 > test:console | |
| [info] Starting scala interpreter... | |
| [info] | |
| Welcome to Scala 2.11.11 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131). | |
| Type in expressions for evaluation. Or try :help. | |
| scala> import geotrellis.raster._ | |
| import geotrellis.vector._ | |
| import geotrellis.proj4._ | |
| import geotrellis.spark._ | |
| import geotrellis.spark.util._ | |
| import geotrellis.spark.tiling._ | |
| scala> implicit val sc = geotrellis.spark.util.SparkUtils.createLocalSparkContext("local[*]", "test") | |
| Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties | |
| 17/07/05 13:54:15 INFO SparkContext: Running Spark version 2.1.1 | |
| sc: org.apache.spark.SparkContext = org.apache.spark.SparkContext@8ba4bdc | |
| scala> import geotrellis.spark.io.s3._ | |
| import geotrellis.spark.io.s3._ | |
| scala> val store = S3AttributeStore("azavea-datahub", "catalog") | |
| store: geotrellis.spark.io.s3.S3AttributeStore = geotrellis.spark.io.s3.S3AttributeStore@3c8aadeb | |
| scala> val reader = S3LayerReader(store) | |
| reader: geotrellis.spark.io.s3.S3LayerReader = geotrellis.spark.io.s3.S3LayerReader@5436da24 | |
| scala> import geotrellis.spark._ | |
| import geotrellis.spark._ | |
| scala> import geotrellis.spark.io._ | |
| import geotrellis.spark.io._ | |
| scala> val layer = reader.query[SpatialKey, Tile, TileLayerMetadata[SpatialKey]](LayerId("nlcd-tms-epsg3857", 5)).result | |
| layer: org.apache.spark.rdd.RDD[(geotrellis.spark.SpatialKey, geotrellis.raster.Tile)] with geotrellis.spark.Metadata[geotrellis.spark.TileLayerMetadata[geotrellis.spark.SpatialKey]] = ContextRDD[2] at RDD at ContextRDD.scala:35 | |
| scala> val raster = layer.stitch() | |
| 17/07/05 13:57:20 INFO SparkContext: Starting job: collect at StitchRDDMethods.scala:58 | |
| raster: geotrellis.raster.Raster[geotrellis.raster.Tile] = Raster(ByteUserDefinedNoDataArrayTile([B@73038b25,3584,2560,int8ud0),Extent(-1.5028131257091932E7, 1252344.271424327, -6261721.357121639, 7514065.628545966)) | |
| scala> val thumb = raster.resample(256,256) | |
| thumb: geotrellis.raster.SinglebandRaster = Raster(ByteUserDefinedNoDataArrayTile([B@30adb7ec,256,256,int8ud0),Extent(-1.5028131257091932E7, 1252344.271424327, -6261721.357121639, 7514065.628545966)) | |
| scala> :paste | |
| // Entering paste mode (ctrl-D to finish) | |
| val nlcdBreaks = Array( | |
| (0 , 0x00000000), | |
| (11 , 0x526095FF), | |
| (12 , 0xFFFFFFFF), | |
| (21 , 0xD28170FF), | |
| (22 , 0xEE0006FF), | |
| (23 , 0x990009FF), | |
| (31 , 0xBFB8B1FF), | |
| (32 , 0x969798FF), | |
| (33 , 0x382959FF), | |
| (41 , 0x579D57FF), | |
| (42 , 0x2A6B3DFF), | |
| (43 , 0xA6BF7BFF), | |
| (51 , 0xBAA65CFF), | |
| (61 , 0x45511FFF), | |
| (71 , 0xD0CFAAFF), | |
| (81 , 0xCCC82FFF), | |
| (82 , 0x9D5D1DFF), | |
| (83 , 0xCD9747FF), | |
| (84 , 0xA7AB9FFF), | |
| (85 , 0xE68A2AFF), | |
| (91 , 0xB6D8F5FF), | |
| (92 , 0xB6D8F5FF)) | |
| // Exiting paste mode, now interpreting. | |
| nlcdBreaks: Array[(Int, Int)] = Array((0,0), (11,1382061567), (12,-1), (21,-763268865), (22,-301988097), (23,-1728050689), (31,-1078414849), (32,-1768449793), (33,942234111), (41,1469929471), (42,711671295), (43,-1497400321), (51,-1163502337), (61,1162944511), (71,-791696641), (81,-859295745), (82,-1654841857), (83,-845723649), (84,-1481924609), (85,-427152641), (91,-1227295233), (92,-1227295233)) | |
| scala> import geotrellis.raster.render._ | |
| import geotrellis.raster.render._ | |
| scala> val nlcdColorMap = ColorMap(nlcdBreaks:_*) | |
| nlcdColorMap: geotrellis.raster.render.ColorMap = geotrellis.raster.render.IntColorMap@27d70385 | |
| scala> val png = thumb.tile.renderPng(nlcdColorMap) | |
| png: geotrellis.raster.render.Png = Png([B@73ac46b9) | |
| scala> import java.nio.file.Files | |
| import java.nio.file.Files | |
| scala> import java.nio.file.Paths | |
| import java.nio.file.Paths | |
| scala> Files.write(Paths.get("/tmp/thumbnail.png"), png.bytes) | |
| res0: java.nio.file.Path = /tmp/thumbnail.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment