├── .gitignore ├── LC81070352015218LGN00.jpg ├── LICENSE ├── README.md ├── build.sbt ├── data └── landsat │ ├── README.md │ └── download-data.sh ├── project ├── build.properties └── plugins.sbt ├── sample-ndvi-thumbnail.png ├── sbt ├── src └── main │ ├── resources │ └── application.conf │ └── scala │ └── tutorial │ ├── Calculations.scala │ ├── CreateNDVIPng.scala │ ├── CreateNDWIPng.scala │ ├── IngestImage.scala │ ├── MaskBandsRandGandNIR.scala │ └── Serve.scala └── static ├── css └── l.geosearch.css ├── images ├── alert.png ├── geosearch.png ├── layers-2x.png ├── layers.png ├── marker-icon-2x.png ├── marker-icon.png ├── marker-shadow.png ├── spinner.gif └── transparent.png ├── index.html ├── js ├── l.control.geosearch.js └── l.geosearch.provider.nominatim.js ├── leaflet.css └── leaflet.js /.gitignore: -------------------------------------------------------------------------------- 1 | data 2 | 3 | project/boot 4 | project/plugins/project 5 | project/plugins/target 6 | project/target 7 | target 8 | .ensime 9 | \#*# 10 | *~ 11 | .#* 12 | .lib 13 | *.aux.xml 14 | *.jar 15 | *.crc 16 | _SUCCESS 17 | 18 | *.pyc 19 | .project 20 | .classpath 21 | .cache 22 | .settings 23 | .history 24 | .idea 25 | .DS_Store 26 | *.iml 27 | *.swp 28 | *.swo 29 | *.sublime-* 30 | .vagrant 31 | -------------------------------------------------------------------------------- /LC81070352015218LGN00.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/LC81070352015218LGN00.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GeoTrellis landsat tutorial project 2 | 3 | **Checkout branch with an experimental VLM support**: [feature/raster-source](https://github.com/geotrellis/geotrellis-landsat-tutorial/tree/feature/raster-source) 4 | 5 | This tutorial goes over how to process a single landsat image on a single machine, using GeoTrellis and spark. 6 | We will create a server that will serve out tiles onto a web map that represent NDVI and NDWI calculations on our image. 7 | The calculations of the NDVI/NDWI and the rendering of the PNG tile will be dynamic and happen per tile request. 8 | 9 | ![Sample NDVI thumbail](https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/master/sample-ndvi-thumbnail.png) 10 | 11 | ### Download a Landsat image bands 12 | Run the `data/landsat/download-data.sh` script to download the landsat image we will be working with: 13 | 14 | ```bash 15 | cd data/landsat 16 | ./download-data.sh 17 | ``` 18 | 19 | Here is a thumbnail of the image: 20 | 21 | ![Landsat image thumbail](https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/master/LC81070352015218LGN00.jpg) 22 | 23 | ### Creating a 3 band geotiff from the red, green and NIR bands masked with the QA band 24 | 25 | The code in `src/main/scala/tutorial/MaskBandsRandGandNIR.scala` will do this. 26 | 27 | ```console 28 | > ./sbt run 29 | ``` 30 | 31 | Select the `tutorial.MaskBandsRandGandNIR` to run. 32 | 33 | This will produce `data/r-g-nir.tif` 34 | 35 | ### Create a PNG of an NDVI of of our image. 36 | 37 | The code in `src/main/scala/tutorial/CreateNDVIPng.scala` will do this. 38 | 39 | ```console 40 | > ./sbt run 41 | ``` 42 | 43 | Select the `tutorial.CreateNDVIPng` to run. 44 | 45 | This will produce `data/ndvi.png` 46 | 47 | ### Create a PNG of an NDWI of of our image. 48 | 49 | The code in `src/main/scala/tutorial/CreateNDWIPng.scala` will do this. 50 | 51 | ```console 52 | > ./sbt run 53 | ``` 54 | 55 | Select the `tutorial.CreateNDWIPng` to run. 56 | 57 | This will produce `data/ndwi.png` 58 | 59 | ### Ingest the multiband geotiff into a GeoTrellis catalog. 60 | 61 | This step will ingest the multiband image we made a previous step into a indexed tile set that GeoTrellis can quickly read data out of. 62 | We'll ingest it as WebMercator tiles, where the tiles are cut according to the 63 | [Slippy Map](http://wiki.openstreetmap.org/wiki/Slippy_Map) tile coordinate representation, at multiple zoom levels. 64 | 65 | The code is in the `src/main/scala/tutorial/IngestImage.scala` file. 66 | 67 | ```console 68 | > ./sbt run 69 | ``` 70 | 71 | Select the `tutorial.IngestImage` to run. 72 | 73 | Tiles will be generated in the `data/catalog` directory. 74 | 75 | ### Serve out dynamically created NDVI/NDWI images using Spray 76 | 77 | This step will start a server that will serve out NDVI/NDWI images onto a web map, allowing users to toggle between layers. 78 | 79 | The code is located in the `src/main/scala/tutorial/Serve.scala` file. 80 | 81 | ```console 82 | > ./sbt run 83 | ``` 84 | 85 | Select the `tutorial.Serve` to run. 86 | 87 | You can now open `static/index.html` and see our NDVI/NDWI tiles on a web map. 88 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | name := "demo" 2 | version := "0.2.0" 3 | scalaVersion := "2.11.8" 4 | organization := "com.azavea" 5 | licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.html")) 6 | scalacOptions ++= Seq( 7 | "-deprecation", 8 | "-unchecked", 9 | "-Yinline-warnings", 10 | "-language:implicitConversions", 11 | "-language:reflectiveCalls", 12 | "-language:higherKinds", 13 | "-language:postfixOps", 14 | "-language:existentials", 15 | "-feature") 16 | publishMavenStyle := true 17 | publishArtifact in Test := false 18 | pomIncludeRepository := { _ => false } 19 | 20 | shellPrompt := { s => Project.extract(s).currentProject.id + " > " } 21 | 22 | // We need to bump up the memory for some of the examples working with the landsat image. 23 | javaOptions += "-Xmx4G" 24 | 25 | fork in run := true 26 | outputStrategy in run := Some(StdoutOutput) 27 | connectInput in run := true 28 | 29 | libraryDependencies ++= Seq( 30 | "org.locationtech.geotrellis" %% "geotrellis-spark" % "2.1.0", 31 | "org.apache.spark" %% "spark-core" % "2.3.1", 32 | "com.typesafe.akka" %% "akka-actor" % "2.4.3", 33 | "com.typesafe.akka" %% "akka-http" % "10.0.3", 34 | "com.typesafe.akka" %% "akka-http-spray-json" % "10.0.7", 35 | "org.scalatest" %% "scalatest" % "2.2.0" % "test" 36 | ) 37 | 38 | assemblyMergeStrategy in assembly := { 39 | case "reference.conf" => MergeStrategy.concat 40 | case "application.conf" => MergeStrategy.concat 41 | case "META-INF/MANIFEST.MF" => MergeStrategy.discard 42 | case "META-INF\\MANIFEST.MF" => MergeStrategy.discard 43 | case "META-INF/ECLIPSEF.RSA" => MergeStrategy.discard 44 | case "META-INF/ECLIPSEF.SF" => MergeStrategy.discard 45 | case _ => MergeStrategy.first 46 | } 47 | -------------------------------------------------------------------------------- /data/landsat/README.md: -------------------------------------------------------------------------------- 1 | Place the un-tarred GeoTiffs of the landsat image in this folder. 2 | Image can be found at https://s3.amazonaws.com/geotrellis-sample-datasets/landsat/LC80140322014139LGN00.tar.bz 3 | -------------------------------------------------------------------------------- /data/landsat/download-data.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | wget http://landsat-pds.s3.amazonaws.com/L8/107/035/LC81070352015218LGN00/LC81070352015218LGN00_B3.TIF 4 | wget http://landsat-pds.s3.amazonaws.com/L8/107/035/LC81070352015218LGN00/LC81070352015218LGN00_B4.TIF 5 | wget http://landsat-pds.s3.amazonaws.com/L8/107/035/LC81070352015218LGN00/LC81070352015218LGN00_B5.TIF 6 | wget http://landsat-pds.s3.amazonaws.com/L8/107/035/LC81070352015218LGN00/LC81070352015218LGN00_BQA.TIF 7 | wget http://landsat-pds.s3.amazonaws.com/L8/107/035/LC81070352015218LGN00/LC81070352015218LGN00_MTL.txt 8 | 9 | # https://s3.amazonaws.com/geotrellis-sample-datasets/landsat/LC80140322014139LGN00.tar.bz 10 | # tar xvfj LC80140322014139LGN00.tar.bz 11 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=1.2.0 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2") 2 | addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.8") -------------------------------------------------------------------------------- /sample-ndvi-thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/sample-ndvi-thumbnail.png -------------------------------------------------------------------------------- /sbt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # A more capable sbt runner, coincidentally also called sbt. 4 | # Author: Paul Phillips 5 | 6 | # todo - make this dynamic 7 | declare -r sbt_release_version="0.13.8" 8 | declare -r sbt_unreleased_version="0.13.9-M1" 9 | declare -r buildProps="project/build.properties" 10 | 11 | declare sbt_jar sbt_dir sbt_create sbt_version 12 | declare scala_version sbt_explicit_version 13 | declare verbose noshare batch trace_level log_level 14 | declare sbt_saved_stty debugUs 15 | 16 | echoerr () { echo >&2 "$@"; } 17 | vlog () { [[ -n "$verbose" ]] && echoerr "$@"; } 18 | 19 | # spaces are possible, e.g. sbt.version = 0.13.0 20 | build_props_sbt () { 21 | [[ -r "$buildProps" ]] && \ 22 | grep '^sbt\.version' "$buildProps" | tr '=\r' ' ' | awk '{ print $2; }' 23 | } 24 | 25 | update_build_props_sbt () { 26 | local ver="$1" 27 | local old="$(build_props_sbt)" 28 | 29 | [[ -r "$buildProps" ]] && [[ "$ver" != "$old" ]] && { 30 | perl -pi -e "s/^sbt\.version\b.*\$/sbt.version=${ver}/" "$buildProps" 31 | grep -q '^sbt.version[ =]' "$buildProps" || printf "\nsbt.version=%s\n" "$ver" >> "$buildProps" 32 | 33 | vlog "!!!" 34 | vlog "!!! Updated file $buildProps setting sbt.version to: $ver" 35 | vlog "!!! Previous value was: $old" 36 | vlog "!!!" 37 | } 38 | } 39 | 40 | set_sbt_version () { 41 | sbt_version="${sbt_explicit_version:-$(build_props_sbt)}" 42 | [[ -n "$sbt_version" ]] || sbt_version=$sbt_release_version 43 | export sbt_version 44 | } 45 | 46 | # restore stty settings (echo in particular) 47 | onSbtRunnerExit() { 48 | [[ -n "$sbt_saved_stty" ]] || return 49 | vlog "" 50 | vlog "restoring stty: $sbt_saved_stty" 51 | stty "$sbt_saved_stty" 52 | unset sbt_saved_stty 53 | } 54 | 55 | # save stty and trap exit, to ensure echo is reenabled if we are interrupted. 56 | trap onSbtRunnerExit EXIT 57 | sbt_saved_stty="$(stty -g 2>/dev/null)" 58 | vlog "Saved stty: $sbt_saved_stty" 59 | 60 | # this seems to cover the bases on OSX, and someone will 61 | # have to tell me about the others. 62 | get_script_path () { 63 | local path="$1" 64 | [[ -L "$path" ]] || { echo "$path" ; return; } 65 | 66 | local target="$(readlink "$path")" 67 | if [[ "${target:0:1}" == "/" ]]; then 68 | echo "$target" 69 | else 70 | echo "${path%/*}/$target" 71 | fi 72 | } 73 | 74 | die() { 75 | echo "Aborting: $@" 76 | exit 1 77 | } 78 | 79 | make_url () { 80 | version="$1" 81 | 82 | case "$version" in 83 | 0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;; 84 | 0.10.* ) echo "$sbt_launch_repo/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;; 85 | 0.11.[12]) echo "$sbt_launch_repo/org.scala-tools.sbt/sbt-launch/$version/sbt-launch.jar" ;; 86 | *) echo "$sbt_launch_repo/org.scala-sbt/sbt-launch/$version/sbt-launch.jar" ;; 87 | esac 88 | } 89 | 90 | init_default_option_file () { 91 | local overriding_var="${!1}" 92 | local default_file="$2" 93 | if [[ ! -r "$default_file" && "$overriding_var" =~ ^@(.*)$ ]]; then 94 | local envvar_file="${BASH_REMATCH[1]}" 95 | if [[ -r "$envvar_file" ]]; then 96 | default_file="$envvar_file" 97 | fi 98 | fi 99 | echo "$default_file" 100 | } 101 | 102 | declare -r cms_opts="-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC" 103 | declare -r jit_opts="-XX:ReservedCodeCacheSize=256m -XX:+TieredCompilation" 104 | declare -r default_jvm_opts_common="-Xms512m -Xmx1536m -Xss2m $jit_opts $cms_opts" 105 | declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" 106 | declare -r latest_28="2.8.2" 107 | declare -r latest_29="2.9.3" 108 | declare -r latest_210="2.10.5" 109 | declare -r latest_211="2.11.7" 110 | 111 | declare -r script_path="$(get_script_path "$BASH_SOURCE")" 112 | declare -r script_name="${script_path##*/}" 113 | 114 | # some non-read-onlies set with defaults 115 | declare java_cmd="java" 116 | declare sbt_opts_file="$(init_default_option_file SBT_OPTS .sbtopts)" 117 | declare jvm_opts_file="$(init_default_option_file JVM_OPTS .jvmopts)" 118 | declare sbt_launch_repo="https://dl.bintray.com/typesafe/ivy-releases" 119 | 120 | # pull -J and -D options to give to java. 121 | declare -a residual_args 122 | declare -a java_args 123 | declare -a scalac_args 124 | declare -a sbt_commands 125 | 126 | # args to jvm/sbt via files or environment variables 127 | declare -a extra_jvm_opts extra_sbt_opts 128 | 129 | addJava () { 130 | vlog "[addJava] arg = '$1'" 131 | java_args+=("$1") 132 | } 133 | addSbt () { 134 | vlog "[addSbt] arg = '$1'" 135 | sbt_commands+=("$1") 136 | } 137 | setThisBuild () { 138 | vlog "[addBuild] args = '$@'" 139 | local key="$1" && shift 140 | addSbt "set $key in ThisBuild := $@" 141 | } 142 | addScalac () { 143 | vlog "[addScalac] arg = '$1'" 144 | scalac_args+=("$1") 145 | } 146 | addResidual () { 147 | vlog "[residual] arg = '$1'" 148 | residual_args+=("$1") 149 | } 150 | addResolver () { 151 | addSbt "set resolvers += $1" 152 | } 153 | addDebugger () { 154 | addJava "-Xdebug" 155 | addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1" 156 | } 157 | setScalaVersion () { 158 | [[ "$1" == *"-SNAPSHOT" ]] && addResolver 'Resolver.sonatypeRepo("snapshots")' 159 | addSbt "++ $1" 160 | } 161 | setJavaHome () { 162 | java_cmd="$1/bin/java" 163 | setThisBuild javaHome "Some(file(\"$1\"))" 164 | export JAVA_HOME="$1" 165 | export JDK_HOME="$1" 166 | export PATH="$JAVA_HOME/bin:$PATH" 167 | } 168 | setJavaHomeQuietly () { 169 | addSbt warn 170 | setJavaHome "$1" 171 | addSbt info 172 | } 173 | 174 | # if set, use JDK_HOME/JAVA_HOME over java found in path 175 | if [[ -e "$JDK_HOME/lib/tools.jar" ]]; then 176 | setJavaHomeQuietly "$JDK_HOME" 177 | elif [[ -e "$JAVA_HOME/bin/java" ]]; then 178 | setJavaHomeQuietly "$JAVA_HOME" 179 | fi 180 | 181 | # directory to store sbt launchers 182 | declare sbt_launch_dir="$HOME/.sbt/launchers" 183 | [[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir" 184 | [[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers.XXXXXX)" 185 | 186 | java_version () { 187 | local version=$("$java_cmd" -version 2>&1 | grep -E -e '(java|openjdk) version' | awk '{ print $3 }' | tr -d \") 188 | vlog "Detected Java version: $version" 189 | echo "${version:2:1}" 190 | } 191 | 192 | # MaxPermSize critical on pre-8 jvms but incurs noisy warning on 8+ 193 | default_jvm_opts () { 194 | local v="$(java_version)" 195 | if [[ $v -ge 8 ]]; then 196 | echo "$default_jvm_opts_common" 197 | else 198 | echo "-XX:MaxPermSize=384m $default_jvm_opts_common" 199 | fi 200 | } 201 | 202 | build_props_scala () { 203 | if [[ -r "$buildProps" ]]; then 204 | versionLine="$(grep '^build.scala.versions' "$buildProps")" 205 | versionString="${versionLine##build.scala.versions=}" 206 | echo "${versionString%% .*}" 207 | fi 208 | } 209 | 210 | execRunner () { 211 | # print the arguments one to a line, quoting any containing spaces 212 | vlog "# Executing command line:" && { 213 | for arg; do 214 | if [[ -n "$arg" ]]; then 215 | if printf "%s\n" "$arg" | grep -q ' '; then 216 | printf >&2 "\"%s\"\n" "$arg" 217 | else 218 | printf >&2 "%s\n" "$arg" 219 | fi 220 | fi 221 | done 222 | vlog "" 223 | } 224 | 225 | [[ -n "$batch" ]] && exec /dev/null; then 247 | curl --fail --silent --location "$url" --output "$jar" 248 | elif which wget >/dev/null; then 249 | wget --quiet -O "$jar" "$url" 250 | fi 251 | } && [[ -r "$jar" ]] 252 | } 253 | 254 | acquire_sbt_jar () { 255 | sbt_url="$(jar_url "$sbt_version")" 256 | sbt_jar="$(jar_file "$sbt_version")" 257 | 258 | [[ -r "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar" 259 | } 260 | 261 | usage () { 262 | cat < display stack traces with a max of frames (default: -1, traces suppressed) 281 | -debug-inc enable debugging log for the incremental compiler 282 | -no-colors disable ANSI color codes 283 | -sbt-create start sbt even if current directory contains no sbt project 284 | -sbt-dir path to global settings/plugins directory (default: ~/.sbt/) 285 | -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11+) 286 | -ivy path to local Ivy repository (default: ~/.ivy2) 287 | -no-share use all local caches; no sharing 288 | -offline put sbt in offline mode 289 | -jvm-debug Turn on JVM debugging, open at the given port. 290 | -batch Disable interactive mode 291 | -prompt Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted 292 | 293 | # sbt version (default: sbt.version from $buildProps if present, otherwise $sbt_release_version) 294 | -sbt-force-latest force the use of the latest release of sbt: $sbt_release_version 295 | -sbt-version use the specified version of sbt (default: $sbt_release_version) 296 | -sbt-dev use the latest pre-release version of sbt: $sbt_unreleased_version 297 | -sbt-jar use the specified jar as the sbt launcher 298 | -sbt-launch-dir directory to hold sbt launchers (default: ~/.sbt/launchers) 299 | -sbt-launch-repo repo url for downloading sbt launcher jar (default: $sbt_launch_repo) 300 | 301 | # scala version (default: as chosen by sbt) 302 | -28 use $latest_28 303 | -29 use $latest_29 304 | -210 use $latest_210 305 | -211 use $latest_211 306 | -scala-home use the scala build at the specified directory 307 | -scala-version use the specified version of scala 308 | -binary-version use the specified scala version when searching for dependencies 309 | 310 | # java version (default: java from PATH, currently $(java -version 2>&1 | grep version)) 311 | -java-home alternate JAVA_HOME 312 | 313 | # passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution 314 | # The default set is used if JVM_OPTS is unset and no -jvm-opts file is found 315 | $(default_jvm_opts) 316 | JVM_OPTS environment variable holding either the jvm args directly, or 317 | the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts') 318 | Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument. 319 | -jvm-opts file containing jvm args (if not given, .jvmopts in project root is used if present) 320 | -Dkey=val pass -Dkey=val directly to the jvm 321 | -J-X pass option -X directly to the jvm (-J is stripped) 322 | 323 | # passing options to sbt, OR to this runner 324 | SBT_OPTS environment variable holding either the sbt args directly, or 325 | the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts') 326 | Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument. 327 | -sbt-opts file containing sbt args (if not given, .sbtopts in project root is used if present) 328 | -S-X add -X to sbt's scalacOptions (-S is stripped) 329 | EOM 330 | } 331 | 332 | process_args () 333 | { 334 | require_arg () { 335 | local type="$1" 336 | local opt="$2" 337 | local arg="$3" 338 | 339 | if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then 340 | die "$opt requires <$type> argument" 341 | fi 342 | } 343 | while [[ $# -gt 0 ]]; do 344 | case "$1" in 345 | -h|-help) usage; exit 1 ;; 346 | -v) verbose=true && shift ;; 347 | -d) addSbt "--debug" && addSbt debug && shift ;; 348 | -w) addSbt "--warn" && addSbt warn && shift ;; 349 | -q) addSbt "--error" && addSbt error && shift ;; 350 | -x) debugUs=true && shift ;; 351 | -trace) require_arg integer "$1" "$2" && trace_level="$2" && shift 2 ;; 352 | -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; 353 | -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; 354 | -no-share) noshare=true && shift ;; 355 | -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;; 356 | -sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;; 357 | -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;; 358 | -offline) addSbt "set offline := true" && shift ;; 359 | -jvm-debug) require_arg port "$1" "$2" && addDebugger "$2" && shift 2 ;; 360 | -batch) batch=true && shift ;; 361 | -prompt) require_arg "expr" "$1" "$2" && setThisBuild shellPrompt "(s => { val e = Project.extract(s) ; $2 })" && shift 2 ;; 362 | 363 | -sbt-create) sbt_create=true && shift ;; 364 | -sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;; 365 | -sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;; 366 | -sbt-force-latest) sbt_explicit_version="$sbt_release_version" && shift ;; 367 | -sbt-dev) sbt_explicit_version="$sbt_unreleased_version" && shift ;; 368 | -sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;; 369 | -sbt-launch-repo) require_arg path "$1" "$2" && sbt_launch_repo="$2" && shift 2 ;; 370 | -scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;; 371 | -binary-version) require_arg version "$1" "$2" && setThisBuild scalaBinaryVersion "\"$2\"" && shift 2 ;; 372 | -scala-home) require_arg path "$1" "$2" && setThisBuild scalaHome "Some(file(\"$2\"))" && shift 2 ;; 373 | -java-home) require_arg path "$1" "$2" && setJavaHome "$2" && shift 2 ;; 374 | -sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;; 375 | -jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;; 376 | 377 | -D*) addJava "$1" && shift ;; 378 | -J*) addJava "${1:2}" && shift ;; 379 | -S*) addScalac "${1:2}" && shift ;; 380 | -28) setScalaVersion "$latest_28" && shift ;; 381 | -29) setScalaVersion "$latest_29" && shift ;; 382 | -210) setScalaVersion "$latest_210" && shift ;; 383 | -211) setScalaVersion "$latest_211" && shift ;; 384 | 385 | --debug) addSbt debug && addResidual "$1" && shift ;; 386 | --warn) addSbt warn && addResidual "$1" && shift ;; 387 | --error) addSbt error && addResidual "$1" && shift ;; 388 | *) addResidual "$1" && shift ;; 389 | esac 390 | done 391 | } 392 | 393 | # process the direct command line arguments 394 | process_args "$@" 395 | 396 | # skip #-styled comments and blank lines 397 | readConfigFile() { 398 | while read line; do 399 | [[ $line =~ ^# ]] || [[ -z $line ]] || echo "$line" 400 | done < "$1" 401 | } 402 | 403 | # if there are file/environment sbt_opts, process again so we 404 | # can supply args to this runner 405 | if [[ -r "$sbt_opts_file" ]]; then 406 | vlog "Using sbt options defined in file $sbt_opts_file" 407 | while read opt; do extra_sbt_opts+=("$opt"); done < <(readConfigFile "$sbt_opts_file") 408 | elif [[ -n "$SBT_OPTS" && ! ("$SBT_OPTS" =~ ^@.*) ]]; then 409 | vlog "Using sbt options defined in variable \$SBT_OPTS" 410 | extra_sbt_opts=( $SBT_OPTS ) 411 | else 412 | vlog "No extra sbt options have been defined" 413 | fi 414 | 415 | [[ -n "${extra_sbt_opts[*]}" ]] && process_args "${extra_sbt_opts[@]}" 416 | 417 | # reset "$@" to the residual args 418 | set -- "${residual_args[@]}" 419 | argumentCount=$# 420 | 421 | # set sbt version 422 | set_sbt_version 423 | 424 | # only exists in 0.12+ 425 | setTraceLevel() { 426 | case "$sbt_version" in 427 | "0.7."* | "0.10."* | "0.11."* ) echoerr "Cannot set trace level in sbt version $sbt_version" ;; 428 | *) setThisBuild traceLevel $trace_level ;; 429 | esac 430 | } 431 | 432 | # set scalacOptions if we were given any -S opts 433 | [[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\"" 434 | 435 | # Update build.properties on disk to set explicit version - sbt gives us no choice 436 | [[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version" 437 | vlog "Detected sbt version $sbt_version" 438 | 439 | [[ -n "$scala_version" ]] && vlog "Overriding scala version to $scala_version" 440 | 441 | # no args - alert them there's stuff in here 442 | (( argumentCount > 0 )) || { 443 | vlog "Starting $script_name: invoke with -help for other options" 444 | residual_args=( shell ) 445 | } 446 | 447 | # verify this is an sbt dir or -create was given 448 | [[ -r ./build.sbt || -d ./project || -n "$sbt_create" ]] || { 449 | cat < 24 | Calculations.ndvi(r, ir); 25 | } 26 | } 27 | 28 | // Get color map from the application.conf settings file. 29 | val colorMap = ColorMap.fromStringDouble(ConfigFactory.load().getString("tutorial.ndviColormap")).get 30 | 31 | // Render this NDVI using the color breaks as a PNG, 32 | // and write the PNG to disk. 33 | println("Rendering PNG and saving to disk...") 34 | ndvi.renderPng(colorMap).write(ndviPath) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/scala/tutorial/CreateNDWIPng.scala: -------------------------------------------------------------------------------- 1 | package tutorial 2 | 3 | import geotrellis.raster._ 4 | import geotrellis.raster.io.geotiff._ 5 | import geotrellis.raster.render._ 6 | import com.typesafe.config.ConfigFactory 7 | 8 | 9 | /** 10 | * Created by FroehlingGallier on 10/13/16. 11 | */ 12 | object CreateNDWIPng { 13 | 14 | val maskedPath = "data/r-g-nir.tif" 15 | val ndwiPath = "data/ndwi.png" 16 | 17 | def main(args: Array[String]): Unit = { 18 | val ndwi = { 19 | // Convert the tile to type double values, 20 | // because we will be performing an operation that 21 | // produces floating point values. 22 | println("Reading in multiband image...") 23 | val tile = MultibandGeoTiff(maskedPath).tile.convert(DoubleConstantNoDataCellType) 24 | 25 | // Use the combineDouble method to map over the red and infrared values 26 | // and perform the NDVI calculation. 27 | println("Performing NDWI calculation...") 28 | tile.combineDouble(MaskBandsRandGandNIR.G_BAND, MaskBandsRandGandNIR.NIR_BAND) { (g: Double, ir: Double) => 29 | Calculations.ndwi(g, ir); 30 | } 31 | } 32 | 33 | // Get color map from the application.conf settings file. 34 | val colorMap = ColorMap.fromStringDouble(ConfigFactory.load().getString("tutorial.ndwiColormap")).get 35 | 36 | // Render this NDVI using the color breaks as a PNG, 37 | // and write the PNG to disk. 38 | println("Rendering PNG and saving to disk...") 39 | ndwi.renderPng(colorMap).write(ndwiPath) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/scala/tutorial/IngestImage.scala: -------------------------------------------------------------------------------- 1 | package tutorial 2 | 3 | import geotrellis.raster._ 4 | import geotrellis.raster.io.geotiff._ 5 | import geotrellis.raster.render._ 6 | import geotrellis.raster.resample._ 7 | import geotrellis.raster.reproject._ 8 | import geotrellis.proj4._ 9 | 10 | import geotrellis.spark._ 11 | import geotrellis.spark.io._ 12 | import geotrellis.spark.io.file._ 13 | import geotrellis.spark.io.hadoop._ 14 | import geotrellis.spark.io.index._ 15 | import geotrellis.spark.pyramid._ 16 | import geotrellis.spark.reproject._ 17 | import geotrellis.spark.tiling._ 18 | import geotrellis.spark.render._ 19 | 20 | import geotrellis.vector._ 21 | 22 | import org.apache.spark._ 23 | import org.apache.spark.rdd._ 24 | 25 | import scala.io.StdIn 26 | import java.io.File 27 | 28 | object IngestImage { 29 | val inputPath = "file://" + new File("data/r-g-nir.tif").getAbsolutePath 30 | val outputPath = "data/catalog" 31 | def main(args: Array[String]): Unit = { 32 | // Setup Spark to use Kryo serializer. 33 | val conf = 34 | new SparkConf() 35 | .setMaster("local[*]") 36 | .setAppName("Spark Tiler") 37 | .set("spark.serializer", "org.apache.spark.serializer.KryoSerializer") 38 | .set("spark.kryo.registrator", "geotrellis.spark.io.kryo.KryoRegistrator") 39 | 40 | val sc = new SparkContext(conf) 41 | try { 42 | run(sc) 43 | // Pause to wait to close the spark context, 44 | // so that you can check out the UI at http://localhost:4040 45 | println("Hit enter to exit.") 46 | StdIn.readLine() 47 | } finally { 48 | sc.stop() 49 | } 50 | } 51 | 52 | def fullPath(path: String) = new java.io.File(path).getAbsolutePath 53 | 54 | def run(implicit sc: SparkContext) = { 55 | // Read the geotiff in as a single image RDD, 56 | // using a method implicitly added to SparkContext by 57 | // an implicit class available via the 58 | // "import geotrellis.spark.io.hadoop._ " statement. 59 | val inputRdd: RDD[(ProjectedExtent, MultibandTile)] = 60 | sc.hadoopMultibandGeoTiffRDD(inputPath) 61 | 62 | // Use the "TileLayerMetadata.fromRdd" call to find the zoom 63 | // level that the closest match to the resolution of our source image, 64 | // and derive information such as the full bounding box and data type. 65 | val (_, rasterMetaData) = 66 | TileLayerMetadata.fromRDD(inputRdd, FloatingLayoutScheme(512)) 67 | 68 | // Use the Tiler to cut our tiles into tiles that are index to a floating layout scheme. 69 | // We'll repartition it so that there are more partitions to work with, since spark 70 | // likes to work with more, smaller partitions (to a point) over few and large partitions. 71 | val tiled: RDD[(SpatialKey, MultibandTile)] = 72 | inputRdd 73 | .tileToLayout(rasterMetaData.cellType, rasterMetaData.layout, Bilinear) 74 | .repartition(100) 75 | 76 | // We'll be tiling the images using a zoomed layout scheme 77 | // in the web mercator format (which fits the slippy map tile specification). 78 | // We'll be creating 256 x 256 tiles. 79 | val layoutScheme = ZoomedLayoutScheme(WebMercator, tileSize = 256) 80 | 81 | // We need to reproject the tiles to WebMercator 82 | val (zoom, reprojected): (Int, RDD[(SpatialKey, MultibandTile)] with Metadata[TileLayerMetadata[SpatialKey]]) = 83 | MultibandTileLayerRDD(tiled, rasterMetaData) 84 | .reproject(WebMercator, layoutScheme, Bilinear) 85 | 86 | // Create the attributes store that will tell us information about our catalog. 87 | val attributeStore = FileAttributeStore(outputPath) 88 | 89 | // Create the writer that we will use to store the tiles in the local catalog. 90 | val writer = FileLayerWriter(attributeStore) 91 | 92 | // Pyramiding up the zoom levels, write our tiles out to the local file system. 93 | Pyramid.upLevels(reprojected, layoutScheme, zoom, Bilinear) { (rdd, z) => 94 | val layerId = LayerId("landsat", z) 95 | // If the layer exists already, delete it out before writing 96 | if(attributeStore.layerExists(layerId)) { 97 | new FileLayerManager(attributeStore).delete(layerId) 98 | } 99 | writer.write(layerId, rdd, ZCurveKeyIndexMethod) 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/scala/tutorial/MaskBandsRandGandNIR.scala: -------------------------------------------------------------------------------- 1 | package tutorial 2 | 3 | import geotrellis.raster._ 4 | import geotrellis.raster.io.geotiff._ 5 | import geotrellis.raster.render._ 6 | import com.typesafe.config.ConfigFactory 7 | 8 | object MaskBandsRandGandNIR { 9 | val maskedPath = "data/r-g-nir.tif" 10 | //constants to differentiate which bands to use 11 | val R_BAND = 0 12 | val G_BAND = 1 13 | val NIR_BAND = 2 14 | // Path to our landsat band geotiffs. 15 | def bandPath(b: String) = s"data/landsat/LC81070352015218LGN00_${b}.TIF" 16 | 17 | def main(args: Array[String]): Unit = { 18 | // Read in the red band 19 | println("Reading in the red band...") 20 | val rGeoTiff = SinglebandGeoTiff(bandPath("B4")) 21 | 22 | // Read in the green band 23 | println("Reading in green band...") 24 | val gGeoTiff = SinglebandGeoTiff(bandPath("B3")) 25 | 26 | // Read in the near infrared band 27 | println("Reading in the NIR band...") 28 | val nirGeoTiff = SinglebandGeoTiff(bandPath("B5")) 29 | 30 | // Read in the QA band 31 | println("Reading in the QA band...") 32 | val qaGeoTiff = SinglebandGeoTiff(bandPath("BQA")) 33 | 34 | // GeoTiffs have more information we need; just grab the Tile out of them. 35 | val (rTile, gTile, nirTile, qaTile) = (rGeoTiff.tile, gGeoTiff.tile, nirGeoTiff.tile, qaGeoTiff.tile) 36 | 37 | // This function will set anything that is potentially a cloud to NODATA 38 | def maskClouds(tile: Tile): Tile = 39 | tile.combine(qaTile) { (v: Int, qa: Int) => 40 | val isCloud = qa & 0x8000 41 | val isCirrus = qa & 0x2000 42 | if(isCloud > 0 || isCirrus > 0) { NODATA } 43 | else { v } 44 | } 45 | 46 | // Mask our red, green and near infrared bands using the qa band 47 | println("Masking clouds in the red band...") 48 | val rMasked = maskClouds(rTile) 49 | println("Masking clouds in the green band...") 50 | val gMasked = maskClouds(gTile) 51 | println("Masking clouds in the NIR band...") 52 | val nirMasked = maskClouds(nirTile) 53 | 54 | // Create a multiband tile with our two masked red and infrared bands. 55 | val mb = ArrayMultibandTile(rMasked, gMasked, nirMasked).convert(IntConstantNoDataCellType) 56 | 57 | // Create a multiband geotiff from our tile, using the same extent and CRS as the original geotiffs. 58 | println("Writing out the multiband R + G + NIR tile...") 59 | MultibandGeoTiff(mb, rGeoTiff.extent, rGeoTiff.crs).write(maskedPath) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/scala/tutorial/Serve.scala: -------------------------------------------------------------------------------- 1 | package tutorial 2 | 3 | import geotrellis.raster._ 4 | import geotrellis.raster.render._ 5 | import geotrellis.spark._ 6 | import geotrellis.spark.io.{ValueReader, _} 7 | import geotrellis.vector._ 8 | import geotrellis.vector.io._ 9 | import geotrellis.vector.io.json._ 10 | import akka.actor._ 11 | import akka.event.{Logging, LoggingAdapter} 12 | import akka.http.scaladsl.Http 13 | import akka.http.scaladsl.model._ 14 | import akka.http.scaladsl.server.Directives._ 15 | import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ 16 | import spray.json._ 17 | import akka.stream.{ActorMaterializer, Materializer} 18 | import scala.concurrent._ 19 | import com.typesafe.config.ConfigFactory 20 | import MaskBandsRandGandNIR.{G_BAND, NIR_BAND, R_BAND} 21 | import geotrellis.proj4.{CRS, LatLng} 22 | 23 | object Serve extends App with Service { 24 | val catalogPath = new java.io.File("data/catalog").toURI 25 | // Create a readers that will read in the indexed tiles we produced in IngestImage. 26 | val attributeStore: AttributeStore = 27 | AttributeStore(catalogPath) 28 | 29 | val valueReader: ValueReader[LayerId] = 30 | ValueReader(attributeStore, catalogPath) 31 | 32 | val collectionReader: CollectionLayerReader[LayerId] = 33 | CollectionLayerReader(attributeStore, catalogPath) 34 | 35 | val ndviColorMap = 36 | ColorMap.fromStringDouble(ConfigFactory.load().getString("tutorial.ndviColormap")).get 37 | val ndwiColorMap = 38 | ColorMap.fromStringDouble(ConfigFactory.load().getString("tutorial.ndwiColormap")).get 39 | 40 | def colorMapForRender(render: String): ColorMap = render match { 41 | case "ndvi" => ndviColorMap 42 | case "ndwi" => ndwiColorMap 43 | case _ => ??? 44 | } 45 | 46 | /** raster transformation to perform at request time */ 47 | def rasterFunction(render: String): MultibandTile => Tile = render match { 48 | case "ndvi" => 49 | tile : MultibandTile => 50 | tile.convert(DoubleConstantNoDataCellType) 51 | .combineDouble(R_BAND, NIR_BAND) { (r, ir) => Calculations.ndvi(r, ir) } 52 | case "ndwi" => 53 | tile: MultibandTile => 54 | tile.convert(DoubleConstantNoDataCellType) 55 | .combineDouble(G_BAND, NIR_BAND) { (g, ir) => Calculations.ndwi(g, ir) } 56 | case _ => ??? 57 | } 58 | 59 | override implicit val system = ActorSystem("tutorial-system") 60 | override implicit val executor = system.dispatcher 61 | override implicit val materializer = ActorMaterializer() 62 | override val logger = Logging(system, getClass) 63 | 64 | Http().bindAndHandle(root, "0.0.0.0", 8080) 65 | } 66 | 67 | trait Service { 68 | implicit val system: ActorSystem 69 | implicit def executor: ExecutionContextExecutor 70 | implicit val materializer: Materializer 71 | val logger: LoggingAdapter 72 | 73 | def valueReader: ValueReader[LayerId] 74 | def collectionReader: CollectionLayerReader[LayerId] 75 | 76 | def pngAsHttpResponse(png: Png): HttpResponse = 77 | HttpResponse(entity = HttpEntity(ContentType(MediaTypes.`image/png`), png.bytes)) 78 | 79 | def root = 80 | pathPrefix(Segment / IntNumber ) { (render, zoom) => 81 | val fn: MultibandTile => Tile = Serve.rasterFunction(render) 82 | 83 | // ZXY route: 84 | pathPrefix(IntNumber / IntNumber) { (x, y) => 85 | complete { 86 | Future { 87 | // Read in the tile at the given z/x/y coordinates. 88 | val tileOpt: Option[MultibandTile] = 89 | try { 90 | val reader = Serve.valueReader.reader[SpatialKey, MultibandTile](LayerId("landsat", zoom)) 91 | Some(reader.read(x, y)) 92 | } catch { 93 | case _: ValueNotFoundError => 94 | None 95 | } 96 | 97 | for (tile <- tileOpt) yield { 98 | val product: Tile = fn(tile) 99 | val cm: ColorMap = Serve.colorMapForRender(render) 100 | val png: Png = product.renderPng(cm) 101 | pngAsHttpResponse(png) 102 | } 103 | } 104 | } 105 | } ~ 106 | // Polygonal summary route: 107 | pathPrefix("summary") { 108 | pathEndOrSingleSlash { 109 | post { 110 | entity(as[String]) { geoJson => 111 | val poly = geoJson.parseGeoJson[Polygon] 112 | val id: LayerId = LayerId("landsat", zoom) 113 | 114 | // Leaflet produces polygon in LatLng, we need to reproject it to layer CRS 115 | val layerMetadata = Serve.attributeStore.readMetadata[TileLayerMetadata[SpatialKey]](id) 116 | val queryPoly = poly.reproject(LatLng, layerMetadata.crs) 117 | 118 | // Query all tiles that intersect the polygon and build histogram 119 | val queryHist = collectionReader 120 | .query[SpatialKey, MultibandTile, TileLayerMetadata[SpatialKey]](id) 121 | .where(Intersects(queryPoly)) 122 | .result // all intersecting tiles have been fetched at this point 123 | .withContext(_.mapValues(fn)) 124 | .polygonalHistogramDouble(queryPoly) 125 | 126 | val result: (Double, Double) = 127 | queryHist.minMaxValues().getOrElse((Double.NaN, Double.NaN)) 128 | 129 | import spray.json.DefaultJsonProtocol._ 130 | complete(result) 131 | } 132 | } 133 | } 134 | } 135 | 136 | } ~ 137 | // Static content routes: 138 | pathEndOrSingleSlash { 139 | getFromFile("static/index.html") 140 | } ~ 141 | pathPrefix("") { 142 | getFromDirectory("static") 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /static/css/l.geosearch.css: -------------------------------------------------------------------------------- 1 | .displayNone { 2 | display: none; 3 | } 4 | 5 | .leaflet-control-geosearch { 6 | position: relative; 7 | } 8 | 9 | .leaflet-control-geosearch a { 10 | -webkit-border-radius: 4px; 11 | border-radius: 4px; 12 | border-bottom: none; 13 | } 14 | 15 | .leaflet-control-geosearch a.glass { 16 | background-image: url(../images/geosearch.png); 17 | background-size: 100% 100%; 18 | } 19 | 20 | .leaflet-control-geosearch a.spinner { 21 | background-image: url(../images/spinner.gif); 22 | background-position: 50% 50%; 23 | } 24 | 25 | .leaflet-control-geosearch a.alert { 26 | background-image: url(../images/alert.png); 27 | background-size: 64% 64%; 28 | } 29 | 30 | .leaflet-control-geosearch a:hover { 31 | border-bottom: none; 32 | } 33 | 34 | .leaflet-control-geosearch form { 35 | position: absolute; 36 | top: 0; 37 | left: 22px; 38 | box-shadow: 0 1px 7px rgba(0, 0, 0, 0.65); 39 | -webkit-border-radius: 4px; 40 | border-radius: 0px 4px 4px 0px; 41 | z-index: -1; 42 | background: #FFF; 43 | height: 26px; 44 | padding: 0 6px 0 6px; 45 | } 46 | 47 | .leaflet-control-geosearch form input { 48 | width: 200px; 49 | border: none; 50 | outline: none; 51 | margin: 0; 52 | padding: 0; 53 | font-size: 12px; 54 | margin-top: 5px; 55 | } 56 | 57 | .leaflet-control-geosearch .message { 58 | position: absolute; 59 | top: 26px; 60 | left: 0px; 61 | width: 226px; 62 | color: #FFF; 63 | background: rgb(40, 40, 40); 64 | padding: 4px 0 4px 8px; 65 | } 66 | -------------------------------------------------------------------------------- /static/images/alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/alert.png -------------------------------------------------------------------------------- /static/images/geosearch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/geosearch.png -------------------------------------------------------------------------------- /static/images/layers-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/layers-2x.png -------------------------------------------------------------------------------- /static/images/layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/layers.png -------------------------------------------------------------------------------- /static/images/marker-icon-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/marker-icon-2x.png -------------------------------------------------------------------------------- /static/images/marker-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/marker-icon.png -------------------------------------------------------------------------------- /static/images/marker-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/marker-shadow.png -------------------------------------------------------------------------------- /static/images/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/spinner.gif -------------------------------------------------------------------------------- /static/images/transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/geotrellis/geotrellis-landsat-tutorial/c2da612c193c549b5ad9229f9a81ea49c9e57db5/static/images/transparent.png -------------------------------------------------------------------------------- /static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /static/js/l.control.geosearch.js: -------------------------------------------------------------------------------- 1 | /* 2 | * L.Control.GeoSearch - search for an address and zoom to its location 3 | * https://github.com/smeijer/leaflet.control.geosearch 4 | */ 5 | 6 | L.GeoSearch = {}; 7 | L.GeoSearch.Provider = {}; 8 | 9 | L.GeoSearch.Result = function (x, y, label) { 10 | this.X = x; 11 | this.Y = y; 12 | this.Label = label; 13 | }; 14 | 15 | L.Control.GeoSearch = L.Control.extend({ 16 | options: { 17 | position: 'topleft' 18 | }, 19 | 20 | initialize: function (options) { 21 | this._config = {}; 22 | L.Util.extend(this.options, options); 23 | this.setConfig(options); 24 | }, 25 | 26 | setConfig: function (options) { 27 | this._config = { 28 | 'provider': options.provider, 29 | 'searchLabel': options.searchLabel || 'Enter address', 30 | 'notFoundMessage' : options.notFoundMessage || 'Sorry, that address could not be found.', 31 | 'zoomLevel': options.zoomLevel || 17, 32 | 'showMarker': typeof options.showMarker !== 'undefined' ? options.showMarker : true 33 | }; 34 | }, 35 | 36 | resetLink: function(extraClass) { 37 | var link = this._container.querySelector('a'); 38 | link.className = 'leaflet-bar-part leaflet-bar-part-single' + ' ' + extraClass; 39 | }, 40 | 41 | onAdd: function (map) { 42 | 43 | // create the container 44 | this._container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-geosearch'); 45 | 46 | // create the link - this will contain one of the icons 47 | var link = L.DomUtil.create('a', '', this._container); 48 | link.href = '#'; 49 | link.title = this._config.searchLabel; 50 | 51 | // set the link's icon to magnifying glass 52 | this.resetLink('glass'); 53 | 54 | var displayNoneClass = 'displayNone'; 55 | 56 | // create the form that will contain the input 57 | var form = L.DomUtil.create('form', displayNoneClass, this._container); 58 | 59 | // create the input, and set its placeholder ("Enter address") text 60 | var input = L.DomUtil.create('input', null, form); 61 | input.placeholder = 'Enter address'; 62 | 63 | // create the error message div 64 | var message = L.DomUtil.create('div', 'leaflet-bar message displayNone', this._container); 65 | 66 | L.DomEvent 67 | .on(link, 'click', L.DomEvent.stopPropagation) 68 | .on(link, 'click', L.DomEvent.preventDefault) 69 | .on(link, 'click', function() { 70 | 71 | if (L.DomUtil.hasClass(form, displayNoneClass)) { 72 | L.DomUtil.removeClass(form, 'displayNone'); // unhide form 73 | input.focus(); 74 | } else { 75 | L.DomUtil.addClass(form, 'displayNone'); // hide form 76 | } 77 | 78 | }) 79 | .on(link, 'dblclick', L.DomEvent.stopPropagation); 80 | 81 | L.DomEvent 82 | .on(input, 'keypress', this.onKeyPress, this) 83 | .on(input, 'keyup', this.onKeyUp, this) 84 | .on(input, 'input', this.onInput, this); 85 | 86 | return this._container; 87 | }, 88 | 89 | geosearch: function (qry) { 90 | try { 91 | var provider = this._config.provider; 92 | 93 | if(typeof provider.GetLocations == 'function') { 94 | var results = provider.GetLocations(qry, this._map, function(err, results) { 95 | if (err) { 96 | return this._printError(err); 97 | } 98 | 99 | this._processResults(results); 100 | }.bind(this)); 101 | } 102 | else { 103 | var url = provider.GetServiceUrl(qry); 104 | 105 | $.getJSON(url, function (data) { 106 | try { 107 | var results = provider.ParseJSON(data); 108 | this._processResults(results); 109 | } 110 | catch (error) { 111 | this._printError(error); 112 | } 113 | }.bind(this)); 114 | } 115 | } 116 | catch (error) { 117 | this._printError(error); 118 | } 119 | }, 120 | 121 | _processResults: function(results) { 122 | if (results.length === 0) 123 | throw this._config.notFoundMessage; 124 | 125 | this.cancelSearch(); 126 | this._showLocation(results[0]); 127 | }, 128 | 129 | _showLocation: function (location) { 130 | if (this._config.showMarker) { 131 | if (typeof this._positionMarker === 'undefined') 132 | this._positionMarker = L.marker([location.Y, location.X]).addTo(this._map); 133 | else 134 | this._positionMarker.setLatLng([location.Y, location.X]); 135 | } 136 | 137 | // this._map.setView([location.Y, location.X], this._config.zoomLevel, false); 138 | }, 139 | 140 | _isShowingError: false, 141 | 142 | _printError: function(error) { 143 | var message = this._container.querySelector('.message'); 144 | message.innerHTML = error; 145 | L.DomUtil.removeClass(message, 'displayNone'); 146 | 147 | // show alert icon 148 | this.resetLink('alert'); 149 | 150 | this._isShowingError = true; 151 | }, 152 | 153 | cancelSearch: function() { 154 | var form = this._container.querySelector('form'); 155 | L.DomUtil.addClass(form, 'displayNone'); // hide form 156 | 157 | var input = form.querySelector('input'); 158 | input.value = ''; // clear form 159 | 160 | // show glass icon 161 | this.resetLink('glass'); 162 | 163 | var message = this._container.querySelector('.message'); 164 | L.DomUtil.addClass(message, 'displayNone'); // hide message 165 | }, 166 | 167 | startSearch: function() { 168 | // show spinner icon 169 | this.resetLink('spinner'); 170 | 171 | var input = this._container.querySelector('input'); 172 | this.geosearch(input.value); 173 | }, 174 | 175 | onInput: function() { 176 | if (this._isShowingError) { 177 | // show glass icon 178 | this.resetLink('glass'); 179 | 180 | var message = this._container.querySelector('.message'); 181 | L.DomUtil.addClass(message, 'displayNone'); // hide message 182 | 183 | this._isShowingError = false; 184 | } 185 | }, 186 | 187 | onKeyPress: function (e) { 188 | var enterKey = 13; 189 | 190 | if (e.keyCode === enterKey) { 191 | L.DomEvent.preventDefault(e); // prevent default form submission 192 | 193 | this.startSearch(); 194 | } 195 | }, 196 | 197 | onKeyUp: function (e) { 198 | var escapeKey = 27; 199 | 200 | if (e.keyCode === escapeKey) { 201 | this.cancelSearch(); 202 | } 203 | } 204 | }); 205 | -------------------------------------------------------------------------------- /static/js/l.geosearch.provider.nominatim.js: -------------------------------------------------------------------------------- 1 | /** 2 | * L.Control.GeoSearch - search for an address and zoom to it's location 3 | * L.GeoSearch.Provider.OpenStreetMap uses openstreetmap geocoding service 4 | * https://github.com/smeijer/leaflet.control.geosearch 5 | */ 6 | 7 | L.GeoSearch.Provider.Nominatim = L.Class.extend({ 8 | options: { 9 | 10 | }, 11 | 12 | initialize: function(options) { 13 | options = L.Util.setOptions(this, options); 14 | }, 15 | 16 | GetLocations: function(query, map, callback) { 17 | callback = callback || function() {}; 18 | 19 | var url = this.GetServiceUrl(query); 20 | 21 | $.getJSON(url, function (data) { 22 | var results; 23 | 24 | try { 25 | results = this.ParseJSON(data); 26 | } catch (err) { 27 | return callback(err); 28 | } 29 | 30 | if (data.length > 0) { 31 | var bbox = data[0].boundingbox, 32 | viewport = [ 33 | [bbox[0], bbox[2]], 34 | [bbox[1], bbox[3]] 35 | ]; 36 | 37 | map.fitBounds(viewport, { 38 | maxZoom: 15 39 | }); 40 | } 41 | 42 | return callback(null, results); 43 | }.bind(this)); 44 | }, 45 | 46 | GetServiceUrl: function (qry) { 47 | var parameters = L.Util.extend({ 48 | q: qry, 49 | format: 'json' 50 | }, this.options); 51 | 52 | return 'http://nominatim.openstreetmap.org/search' 53 | + L.Util.getParamString(parameters); 54 | }, 55 | 56 | ParseJSON: function (data) { 57 | if (data.length == 0) 58 | return []; 59 | 60 | var results = []; 61 | for (var i = 0; i < data.length; i++) 62 | results.push(new L.GeoSearch.Result( 63 | data[i].lon, 64 | data[i].lat, 65 | data[i].display_name 66 | )); 67 | 68 | return results; 69 | } 70 | }); 71 | -------------------------------------------------------------------------------- /static/leaflet.css: -------------------------------------------------------------------------------- 1 | /* required styles */ 2 | 3 | .leaflet-map-pane, 4 | .leaflet-tile, 5 | .leaflet-marker-icon, 6 | .leaflet-marker-shadow, 7 | .leaflet-tile-pane, 8 | .leaflet-tile-container, 9 | .leaflet-overlay-pane, 10 | .leaflet-shadow-pane, 11 | .leaflet-marker-pane, 12 | .leaflet-popup-pane, 13 | .leaflet-overlay-pane svg, 14 | .leaflet-zoom-box, 15 | .leaflet-image-layer, 16 | .leaflet-layer { 17 | position: absolute; 18 | left: 0; 19 | top: 0; 20 | } 21 | .leaflet-container { 22 | overflow: hidden; 23 | -ms-touch-action: none; 24 | touch-action: none; 25 | } 26 | .leaflet-tile, 27 | .leaflet-marker-icon, 28 | .leaflet-marker-shadow { 29 | -webkit-user-select: none; 30 | -moz-user-select: none; 31 | user-select: none; 32 | -webkit-user-drag: none; 33 | } 34 | .leaflet-marker-icon, 35 | .leaflet-marker-shadow { 36 | display: block; 37 | } 38 | /* map is broken in FF if you have max-width: 100% on tiles */ 39 | .leaflet-container img { 40 | max-width: none !important; 41 | } 42 | /* stupid Android 2 doesn't understand "max-width: none" properly */ 43 | .leaflet-container img.leaflet-image-layer { 44 | max-width: 15000px !important; 45 | } 46 | .leaflet-tile { 47 | filter: inherit; 48 | visibility: hidden; 49 | } 50 | .leaflet-tile-loaded { 51 | visibility: inherit; 52 | } 53 | .leaflet-zoom-box { 54 | width: 0; 55 | height: 0; 56 | } 57 | /* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */ 58 | .leaflet-overlay-pane svg { 59 | -moz-user-select: none; 60 | } 61 | 62 | .leaflet-tile-pane { z-index: 2; } 63 | .leaflet-objects-pane { z-index: 3; } 64 | .leaflet-overlay-pane { z-index: 4; } 65 | .leaflet-shadow-pane { z-index: 5; } 66 | .leaflet-marker-pane { z-index: 6; } 67 | .leaflet-popup-pane { z-index: 7; } 68 | 69 | .leaflet-vml-shape { 70 | width: 1px; 71 | height: 1px; 72 | } 73 | .lvml { 74 | behavior: url(#default#VML); 75 | display: inline-block; 76 | position: absolute; 77 | } 78 | 79 | 80 | /* control positioning */ 81 | 82 | .leaflet-control { 83 | position: relative; 84 | z-index: 7; 85 | pointer-events: auto; 86 | } 87 | .leaflet-top, 88 | .leaflet-bottom { 89 | position: absolute; 90 | z-index: 1000; 91 | pointer-events: none; 92 | } 93 | .leaflet-top { 94 | top: 0; 95 | } 96 | .leaflet-right { 97 | right: 0; 98 | } 99 | .leaflet-bottom { 100 | bottom: 0; 101 | } 102 | .leaflet-left { 103 | left: 0; 104 | } 105 | .leaflet-control { 106 | float: left; 107 | clear: both; 108 | } 109 | .leaflet-right .leaflet-control { 110 | float: right; 111 | } 112 | .leaflet-top .leaflet-control { 113 | margin-top: 10px; 114 | } 115 | .leaflet-bottom .leaflet-control { 116 | margin-bottom: 10px; 117 | } 118 | .leaflet-left .leaflet-control { 119 | margin-left: 10px; 120 | } 121 | .leaflet-right .leaflet-control { 122 | margin-right: 10px; 123 | } 124 | 125 | 126 | /* zoom and fade animations */ 127 | 128 | .leaflet-fade-anim .leaflet-tile, 129 | .leaflet-fade-anim .leaflet-popup { 130 | opacity: 0; 131 | -webkit-transition: opacity 0.2s linear; 132 | -moz-transition: opacity 0.2s linear; 133 | -o-transition: opacity 0.2s linear; 134 | transition: opacity 0.2s linear; 135 | } 136 | .leaflet-fade-anim .leaflet-tile-loaded, 137 | .leaflet-fade-anim .leaflet-map-pane .leaflet-popup { 138 | opacity: 1; 139 | } 140 | 141 | .leaflet-zoom-anim .leaflet-zoom-animated { 142 | -webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1); 143 | -moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1); 144 | -o-transition: -o-transform 0.25s cubic-bezier(0,0,0.25,1); 145 | transition: transform 0.25s cubic-bezier(0,0,0.25,1); 146 | } 147 | .leaflet-zoom-anim .leaflet-tile, 148 | .leaflet-pan-anim .leaflet-tile, 149 | .leaflet-touching .leaflet-zoom-animated { 150 | -webkit-transition: none; 151 | -moz-transition: none; 152 | -o-transition: none; 153 | transition: none; 154 | } 155 | 156 | .leaflet-zoom-anim .leaflet-zoom-hide { 157 | visibility: hidden; 158 | } 159 | 160 | 161 | /* cursors */ 162 | 163 | .leaflet-clickable { 164 | cursor: pointer; 165 | } 166 | .leaflet-container { 167 | cursor: -webkit-grab; 168 | cursor: -moz-grab; 169 | } 170 | .leaflet-popup-pane, 171 | .leaflet-control { 172 | cursor: auto; 173 | } 174 | .leaflet-dragging .leaflet-container, 175 | .leaflet-dragging .leaflet-clickable { 176 | cursor: move; 177 | cursor: -webkit-grabbing; 178 | cursor: -moz-grabbing; 179 | } 180 | 181 | 182 | /* visual tweaks */ 183 | 184 | .leaflet-container { 185 | background: #ddd; 186 | outline: 0; 187 | } 188 | .leaflet-container a { 189 | color: #0078A8; 190 | } 191 | .leaflet-container a.leaflet-active { 192 | outline: 2px solid orange; 193 | } 194 | .leaflet-zoom-box { 195 | border: 2px dotted #38f; 196 | background: rgba(255,255,255,0.5); 197 | } 198 | 199 | 200 | /* general typography */ 201 | .leaflet-container { 202 | font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif; 203 | } 204 | 205 | 206 | /* general toolbar styles */ 207 | 208 | .leaflet-bar { 209 | box-shadow: 0 1px 5px rgba(0,0,0,0.65); 210 | border-radius: 4px; 211 | } 212 | .leaflet-bar a, 213 | .leaflet-bar a:hover { 214 | background-color: #fff; 215 | border-bottom: 1px solid #ccc; 216 | width: 26px; 217 | height: 26px; 218 | line-height: 26px; 219 | display: block; 220 | text-align: center; 221 | text-decoration: none; 222 | color: black; 223 | } 224 | .leaflet-bar a, 225 | .leaflet-control-layers-toggle { 226 | background-position: 50% 50%; 227 | background-repeat: no-repeat; 228 | display: block; 229 | } 230 | .leaflet-bar a:hover { 231 | background-color: #f4f4f4; 232 | } 233 | .leaflet-bar a:first-child { 234 | border-top-left-radius: 4px; 235 | border-top-right-radius: 4px; 236 | } 237 | .leaflet-bar a:last-child { 238 | border-bottom-left-radius: 4px; 239 | border-bottom-right-radius: 4px; 240 | border-bottom: none; 241 | } 242 | .leaflet-bar a.leaflet-disabled { 243 | cursor: default; 244 | background-color: #f4f4f4; 245 | color: #bbb; 246 | } 247 | 248 | .leaflet-touch .leaflet-bar a { 249 | width: 30px; 250 | height: 30px; 251 | line-height: 30px; 252 | } 253 | 254 | 255 | /* zoom control */ 256 | 257 | .leaflet-control-zoom-in, 258 | .leaflet-control-zoom-out { 259 | font: bold 18px 'Lucida Console', Monaco, monospace; 260 | text-indent: 1px; 261 | } 262 | .leaflet-control-zoom-out { 263 | font-size: 20px; 264 | } 265 | 266 | .leaflet-touch .leaflet-control-zoom-in { 267 | font-size: 22px; 268 | } 269 | .leaflet-touch .leaflet-control-zoom-out { 270 | font-size: 24px; 271 | } 272 | 273 | 274 | /* layers control */ 275 | 276 | .leaflet-control-layers { 277 | box-shadow: 0 1px 5px rgba(0,0,0,0.4); 278 | background: #fff; 279 | border-radius: 5px; 280 | } 281 | .leaflet-control-layers-toggle { 282 | background-image: url(images/layers.png); 283 | width: 36px; 284 | height: 36px; 285 | } 286 | .leaflet-retina .leaflet-control-layers-toggle { 287 | background-image: url(images/layers-2x.png); 288 | background-size: 26px 26px; 289 | } 290 | .leaflet-touch .leaflet-control-layers-toggle { 291 | width: 44px; 292 | height: 44px; 293 | } 294 | .leaflet-control-layers .leaflet-control-layers-list, 295 | .leaflet-control-layers-expanded .leaflet-control-layers-toggle { 296 | display: none; 297 | } 298 | .leaflet-control-layers-expanded .leaflet-control-layers-list { 299 | display: block; 300 | position: relative; 301 | } 302 | .leaflet-control-layers-expanded { 303 | padding: 6px 10px 6px 6px; 304 | color: #333; 305 | background: #fff; 306 | } 307 | .leaflet-control-layers-selector { 308 | margin-top: 2px; 309 | position: relative; 310 | top: 1px; 311 | } 312 | .leaflet-control-layers label { 313 | display: block; 314 | } 315 | .leaflet-control-layers-separator { 316 | height: 0; 317 | border-top: 1px solid #ddd; 318 | margin: 5px -10px 5px -6px; 319 | } 320 | 321 | 322 | /* attribution and scale controls */ 323 | 324 | .leaflet-container .leaflet-control-attribution { 325 | background: #fff; 326 | background: rgba(255, 255, 255, 0.7); 327 | margin: 0; 328 | } 329 | .leaflet-control-attribution, 330 | .leaflet-control-scale-line { 331 | padding: 0 5px; 332 | color: #333; 333 | } 334 | .leaflet-control-attribution a { 335 | text-decoration: none; 336 | } 337 | .leaflet-control-attribution a:hover { 338 | text-decoration: underline; 339 | } 340 | .leaflet-container .leaflet-control-attribution, 341 | .leaflet-container .leaflet-control-scale { 342 | font-size: 11px; 343 | } 344 | .leaflet-left .leaflet-control-scale { 345 | margin-left: 5px; 346 | } 347 | .leaflet-bottom .leaflet-control-scale { 348 | margin-bottom: 5px; 349 | } 350 | .leaflet-control-scale-line { 351 | border: 2px solid #777; 352 | border-top: none; 353 | line-height: 1.1; 354 | padding: 2px 5px 1px; 355 | font-size: 11px; 356 | white-space: nowrap; 357 | overflow: hidden; 358 | -moz-box-sizing: content-box; 359 | box-sizing: content-box; 360 | 361 | background: #fff; 362 | background: rgba(255, 255, 255, 0.5); 363 | } 364 | .leaflet-control-scale-line:not(:first-child) { 365 | border-top: 2px solid #777; 366 | border-bottom: none; 367 | margin-top: -2px; 368 | } 369 | .leaflet-control-scale-line:not(:first-child):not(:last-child) { 370 | border-bottom: 2px solid #777; 371 | } 372 | 373 | .leaflet-touch .leaflet-control-attribution, 374 | .leaflet-touch .leaflet-control-layers, 375 | .leaflet-touch .leaflet-bar { 376 | box-shadow: none; 377 | } 378 | .leaflet-touch .leaflet-control-layers, 379 | .leaflet-touch .leaflet-bar { 380 | border: 2px solid rgba(0,0,0,0.2); 381 | background-clip: padding-box; 382 | } 383 | 384 | 385 | /* popup */ 386 | 387 | .leaflet-popup { 388 | position: absolute; 389 | text-align: center; 390 | } 391 | .leaflet-popup-content-wrapper { 392 | padding: 1px; 393 | text-align: left; 394 | border-radius: 12px; 395 | } 396 | .leaflet-popup-content { 397 | margin: 13px 19px; 398 | line-height: 1.4; 399 | } 400 | .leaflet-popup-content p { 401 | margin: 18px 0; 402 | } 403 | .leaflet-popup-tip-container { 404 | margin: 0 auto; 405 | width: 40px; 406 | height: 20px; 407 | position: relative; 408 | overflow: hidden; 409 | } 410 | .leaflet-popup-tip { 411 | width: 17px; 412 | height: 17px; 413 | padding: 1px; 414 | 415 | margin: -10px auto 0; 416 | 417 | -webkit-transform: rotate(45deg); 418 | -moz-transform: rotate(45deg); 419 | -ms-transform: rotate(45deg); 420 | -o-transform: rotate(45deg); 421 | transform: rotate(45deg); 422 | } 423 | .leaflet-popup-content-wrapper, 424 | .leaflet-popup-tip { 425 | background: white; 426 | 427 | box-shadow: 0 3px 14px rgba(0,0,0,0.4); 428 | } 429 | .leaflet-container a.leaflet-popup-close-button { 430 | position: absolute; 431 | top: 0; 432 | right: 0; 433 | padding: 4px 4px 0 0; 434 | text-align: center; 435 | width: 18px; 436 | height: 14px; 437 | font: 16px/14px Tahoma, Verdana, sans-serif; 438 | color: #c3c3c3; 439 | text-decoration: none; 440 | font-weight: bold; 441 | background: transparent; 442 | } 443 | .leaflet-container a.leaflet-popup-close-button:hover { 444 | color: #999; 445 | } 446 | .leaflet-popup-scrolled { 447 | overflow: auto; 448 | border-bottom: 1px solid #ddd; 449 | border-top: 1px solid #ddd; 450 | } 451 | 452 | .leaflet-oldie .leaflet-popup-content-wrapper { 453 | zoom: 1; 454 | } 455 | .leaflet-oldie .leaflet-popup-tip { 456 | width: 24px; 457 | margin: 0 auto; 458 | 459 | -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678)"; 460 | filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678); 461 | } 462 | .leaflet-oldie .leaflet-popup-tip-container { 463 | margin-top: -1px; 464 | } 465 | 466 | .leaflet-oldie .leaflet-control-zoom, 467 | .leaflet-oldie .leaflet-control-layers, 468 | .leaflet-oldie .leaflet-popup-content-wrapper, 469 | .leaflet-oldie .leaflet-popup-tip { 470 | border: 1px solid #999; 471 | } 472 | 473 | 474 | /* div icon */ 475 | 476 | .leaflet-div-icon { 477 | background: #fff; 478 | border: 1px solid #666; 479 | } 480 | --------------------------------------------------------------------------------