├── .gitignore ├── LICENSE ├── README.md ├── colorado_lakes_grid.png ├── colorado_lakes_grid_rstudio.png ├── denver_to_berlin.R ├── deps.edn ├── nj_lakes.R ├── packages_to_install.R ├── resources ├── data_files │ ├── RMNP │ │ ├── Rocky_Mountain_National_Park__Boundary_Polygon.cpg │ │ ├── Rocky_Mountain_National_Park__Boundary_Polygon.dbf │ │ ├── Rocky_Mountain_National_Park__Boundary_Polygon.prj │ │ ├── Rocky_Mountain_National_Park__Boundary_Polygon.shp │ │ ├── Rocky_Mountain_National_Park__Boundary_Polygon.shx │ │ ├── Rocky_Mountain_National_Park__Boundary_Polygon.zip │ │ ├── Rocky_Mountain_National_Park__Trails.cpg │ │ ├── Rocky_Mountain_National_Park__Trails.dbf │ │ ├── Rocky_Mountain_National_Park__Trails.prj │ │ ├── Rocky_Mountain_National_Park__Trails.shp │ │ ├── Rocky_Mountain_National_Park__Trails.shx │ │ └── Rocky_Mountain_National_Park__Trails.zip │ ├── black-canyon-output1.tif │ ├── black-canyon-texture4.tif │ ├── lakes │ │ ├── geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.dbf │ │ ├── geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.prj │ │ ├── geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shp │ │ └── geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shx │ ├── new_jersey │ │ ├── NHDWaterbody_2002_shapefile.zip │ │ └── NHDWaterbody_2002_shapefile │ │ │ └── .gitkeep │ └── rmnp_dem.tif └── output │ └── germany-test.pdf ├── rserve_commands.R └── src └── clojure_map_examples ├── black_canyon.clj ├── core.clj ├── denver_berlin.clj ├── lakes_and_rivers.clj ├── raster_examples.clj └── shapefile_example.clj /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /classes 3 | /checkouts 4 | profiles.clj 5 | pom.xml 6 | pom.xml.asc 7 | *.jar 8 | *.class 9 | /.lein-* 10 | /.nrepl-port 11 | .hgignore 12 | .hg/ 13 | .cpcache 14 | resources/output 15 | resources/data_files/new_jersey/NHDWaterbody_2002_shapefile 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 2.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 4 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION 5 | OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial content 12 | Distributed under this Agreement, and 13 | 14 | b) in the case of each subsequent Contributor: 15 | i) changes to the Program, and 16 | ii) additions to the Program; 17 | where such changes and/or additions to the Program originate from 18 | and are Distributed by that particular Contributor. A Contribution 19 | "originates" from a Contributor if it was added to the Program by 20 | such Contributor itself or anyone acting on such Contributor's behalf. 21 | Contributions do not include changes or additions to the Program that 22 | are not Modified Works. 23 | 24 | "Contributor" means any person or entity that Distributes the Program. 25 | 26 | "Licensed Patents" mean patent claims licensable by a Contributor which 27 | are necessarily infringed by the use or sale of its Contribution alone 28 | or when combined with the Program. 29 | 30 | "Program" means the Contributions Distributed in accordance with this 31 | Agreement. 32 | 33 | "Recipient" means anyone who receives the Program under this Agreement 34 | or any Secondary License (as applicable), including Contributors. 35 | 36 | "Derivative Works" shall mean any work, whether in Source Code or other 37 | form, that is based on (or derived from) the Program and for which the 38 | editorial revisions, annotations, elaborations, or other modifications 39 | represent, as a whole, an original work of authorship. 40 | 41 | "Modified Works" shall mean any work in Source Code or other form that 42 | results from an addition to, deletion from, or modification of the 43 | contents of the Program, including, for purposes of clarity any new file 44 | in Source Code form that contains any contents of the Program. Modified 45 | Works shall not include works that contain only declarations, 46 | interfaces, types, classes, structures, or files of the Program solely 47 | in each case in order to link to, bind by name, or subclass the Program 48 | or Modified Works thereof. 49 | 50 | "Distribute" means the acts of a) distributing or b) making available 51 | in any manner that enables the transfer of a copy. 52 | 53 | "Source Code" means the form of a Program preferred for making 54 | modifications, including but not limited to software source code, 55 | documentation source, and configuration files. 56 | 57 | "Secondary License" means either the GNU General Public License, 58 | Version 2.0, or any later versions of that license, including any 59 | exceptions or additional permissions as identified by the initial 60 | Contributor. 61 | 62 | 2. GRANT OF RIGHTS 63 | 64 | a) Subject to the terms of this Agreement, each Contributor hereby 65 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 66 | license to reproduce, prepare Derivative Works of, publicly display, 67 | publicly perform, Distribute and sublicense the Contribution of such 68 | Contributor, if any, and such Derivative Works. 69 | 70 | b) Subject to the terms of this Agreement, each Contributor hereby 71 | grants Recipient a non-exclusive, worldwide, royalty-free patent 72 | license under Licensed Patents to make, use, sell, offer to sell, 73 | import and otherwise transfer the Contribution of such Contributor, 74 | if any, in Source Code or other form. This patent license shall 75 | apply to the combination of the Contribution and the Program if, at 76 | the time the Contribution is added by the Contributor, such addition 77 | of the Contribution causes such combination to be covered by the 78 | Licensed Patents. The patent license shall not apply to any other 79 | combinations which include the Contribution. No hardware per se is 80 | licensed hereunder. 81 | 82 | c) Recipient understands that although each Contributor grants the 83 | licenses to its Contributions set forth herein, no assurances are 84 | provided by any Contributor that the Program does not infringe the 85 | patent or other intellectual property rights of any other entity. 86 | Each Contributor disclaims any liability to Recipient for claims 87 | brought by any other entity based on infringement of intellectual 88 | property rights or otherwise. As a condition to exercising the 89 | rights and licenses granted hereunder, each Recipient hereby 90 | assumes sole responsibility to secure any other intellectual 91 | property rights needed, if any. For example, if a third party 92 | patent license is required to allow Recipient to Distribute the 93 | Program, it is Recipient's responsibility to acquire that license 94 | before distributing the Program. 95 | 96 | d) Each Contributor represents that to its knowledge it has 97 | sufficient copyright rights in its Contribution, if any, to grant 98 | the copyright license set forth in this Agreement. 99 | 100 | e) Notwithstanding the terms of any Secondary License, no 101 | Contributor makes additional grants to any Recipient (other than 102 | those set forth in this Agreement) as a result of such Recipient's 103 | receipt of the Program under the terms of a Secondary License 104 | (if permitted under the terms of Section 3). 105 | 106 | 3. REQUIREMENTS 107 | 108 | 3.1 If a Contributor Distributes the Program in any form, then: 109 | 110 | a) the Program must also be made available as Source Code, in 111 | accordance with section 3.2, and the Contributor must accompany 112 | the Program with a statement that the Source Code for the Program 113 | is available under this Agreement, and informs Recipients how to 114 | obtain it in a reasonable manner on or through a medium customarily 115 | used for software exchange; and 116 | 117 | b) the Contributor may Distribute the Program under a license 118 | different than this Agreement, provided that such license: 119 | i) effectively disclaims on behalf of all other Contributors all 120 | warranties and conditions, express and implied, including 121 | warranties or conditions of title and non-infringement, and 122 | implied warranties or conditions of merchantability and fitness 123 | for a particular purpose; 124 | 125 | ii) effectively excludes on behalf of all other Contributors all 126 | liability for damages, including direct, indirect, special, 127 | incidental and consequential damages, such as lost profits; 128 | 129 | iii) does not attempt to limit or alter the recipients' rights 130 | in the Source Code under section 3.2; and 131 | 132 | iv) requires any subsequent distribution of the Program by any 133 | party to be under a license that satisfies the requirements 134 | of this section 3. 135 | 136 | 3.2 When the Program is Distributed as Source Code: 137 | 138 | a) it must be made available under this Agreement, or if the 139 | Program (i) is combined with other material in a separate file or 140 | files made available under a Secondary License, and (ii) the initial 141 | Contributor attached to the Source Code the notice described in 142 | Exhibit A of this Agreement, then the Program may be made available 143 | under the terms of such Secondary Licenses, and 144 | 145 | b) a copy of this Agreement must be included with each copy of 146 | the Program. 147 | 148 | 3.3 Contributors may not remove or alter any copyright, patent, 149 | trademark, attribution notices, disclaimers of warranty, or limitations 150 | of liability ("notices") contained within the Program from any copy of 151 | the Program which they Distribute, provided that Contributors may add 152 | their own appropriate notices. 153 | 154 | 4. COMMERCIAL DISTRIBUTION 155 | 156 | Commercial distributors of software may accept certain responsibilities 157 | with respect to end users, business partners and the like. While this 158 | license is intended to facilitate the commercial use of the Program, 159 | the Contributor who includes the Program in a commercial product 160 | offering should do so in a manner which does not create potential 161 | liability for other Contributors. Therefore, if a Contributor includes 162 | the Program in a commercial product offering, such Contributor 163 | ("Commercial Contributor") hereby agrees to defend and indemnify every 164 | other Contributor ("Indemnified Contributor") against any losses, 165 | damages and costs (collectively "Losses") arising from claims, lawsuits 166 | and other legal actions brought by a third party against the Indemnified 167 | Contributor to the extent caused by the acts or omissions of such 168 | Commercial Contributor in connection with its distribution of the Program 169 | in a commercial product offering. The obligations in this section do not 170 | apply to any claims or Losses relating to any actual or alleged 171 | intellectual property infringement. In order to qualify, an Indemnified 172 | Contributor must: a) promptly notify the Commercial Contributor in 173 | writing of such claim, and b) allow the Commercial Contributor to control, 174 | and cooperate with the Commercial Contributor in, the defense and any 175 | related settlement negotiations. The Indemnified Contributor may 176 | participate in any such claim at its own expense. 177 | 178 | For example, a Contributor might include the Program in a commercial 179 | product offering, Product X. That Contributor is then a Commercial 180 | Contributor. If that Commercial Contributor then makes performance 181 | claims, or offers warranties related to Product X, those performance 182 | claims and warranties are such Commercial Contributor's responsibility 183 | alone. Under this section, the Commercial Contributor would have to 184 | defend claims against the other Contributors related to those performance 185 | claims and warranties, and if a court requires any other Contributor to 186 | pay any damages as a result, the Commercial Contributor must pay 187 | those damages. 188 | 189 | 5. NO WARRANTY 190 | 191 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 192 | PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" 193 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 194 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF 195 | TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 196 | PURPOSE. Each Recipient is solely responsible for determining the 197 | appropriateness of using and distributing the Program and assumes all 198 | risks associated with its exercise of rights under this Agreement, 199 | including but not limited to the risks and costs of program errors, 200 | compliance with applicable laws, damage to or loss of data, programs 201 | or equipment, and unavailability or interruption of operations. 202 | 203 | 6. DISCLAIMER OF LIABILITY 204 | 205 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 206 | PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS 207 | SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 208 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST 209 | PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 210 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 211 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 212 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE 213 | POSSIBILITY OF SUCH DAMAGES. 214 | 215 | 7. GENERAL 216 | 217 | If any provision of this Agreement is invalid or unenforceable under 218 | applicable law, it shall not affect the validity or enforceability of 219 | the remainder of the terms of this Agreement, and without further 220 | action by the parties hereto, such provision shall be reformed to the 221 | minimum extent necessary to make such provision valid and enforceable. 222 | 223 | If Recipient institutes patent litigation against any entity 224 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 225 | Program itself (excluding combinations of the Program with other software 226 | or hardware) infringes such Recipient's patent(s), then such Recipient's 227 | rights granted under Section 2(b) shall terminate as of the date such 228 | litigation is filed. 229 | 230 | All Recipient's rights under this Agreement shall terminate if it 231 | fails to comply with any of the material terms or conditions of this 232 | Agreement and does not cure such failure in a reasonable period of 233 | time after becoming aware of such noncompliance. If all Recipient's 234 | rights under this Agreement terminate, Recipient agrees to cease use 235 | and distribution of the Program as soon as reasonably practicable. 236 | However, Recipient's obligations under this Agreement and any licenses 237 | granted by Recipient relating to the Program shall continue and survive. 238 | 239 | Everyone is permitted to copy and distribute copies of this Agreement, 240 | but in order to avoid inconsistency the Agreement is copyrighted and 241 | may only be modified in the following manner. The Agreement Steward 242 | reserves the right to publish new versions (including revisions) of 243 | this Agreement from time to time. No one other than the Agreement 244 | Steward has the right to modify this Agreement. The Eclipse Foundation 245 | is the initial Agreement Steward. The Eclipse Foundation may assign the 246 | responsibility to serve as the Agreement Steward to a suitable separate 247 | entity. Each new version of the Agreement will be given a distinguishing 248 | version number. The Program (including Contributions) may always be 249 | Distributed subject to the version of the Agreement under which it was 250 | received. In addition, after a new version of the Agreement is published, 251 | Contributor may elect to Distribute the Program (including its 252 | Contributions) under the new version. 253 | 254 | Except as expressly stated in Sections 2(a) and 2(b) above, Recipient 255 | receives no rights or licenses to the intellectual property of any 256 | Contributor under this Agreement, whether expressly, by implication, 257 | estoppel or otherwise. All rights in the Program not expressly granted 258 | under this Agreement are reserved. Nothing in this Agreement is intended 259 | to be enforceable by any entity that is not a Contributor or Recipient. 260 | No third-party beneficiary rights are created under this Agreement. 261 | 262 | Exhibit A - Form of Secondary Licenses Notice 263 | 264 | "This Source Code may also be made available under the following 265 | Secondary Licenses when the conditions for such availability set forth 266 | in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), 267 | version(s), and exceptions or additional permissions here}." 268 | 269 | Simply including a copy of this Agreement, including this Exhibit A 270 | is not sufficient to license the Source Code under Secondary Licenses. 271 | 272 | If it is not possible or desirable to put the notice in a particular 273 | file, then You may include the notice in a location (such as a LICENSE 274 | file in a relevant directory) where a recipient would be likely to 275 | look for such a notice. 276 | 277 | You may add additional accurate notices of copyright ownership. 278 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # clojure-map-examples 2 | 3 | Examples from "Making Geographic Maps with Clojure" talk. 4 | 5 | ## Installation 6 | 7 | * Install [GDAL](https://gdal.org/download.html) 8 | * Install [R](https://www.r-project.org/) 9 | * Install required R packages in "packages_to_install.R" 10 | 11 | 12 | ## Usage 13 | 14 | * After you install R, run `rserve_commands.R` 15 | * Start the REPL and start running `src/clojure_map_examples/shapefile_example.clj` or `raster_example.clj` 16 | 17 | ## Other links 18 | * [Rayshader Intro](https://github.com/tylermorganwall/MusaMasterclass) 19 | 20 | ## Data sources 21 | 22 | * Worldwide Elevation Raster files http://viewfinderpanoramas.org/dem3.html#nam 23 | 24 | ### Bugs 25 | 26 | Please contact me ([@joannecheng](https://twitter.com/joannecheng)) if you have any issues with this project. 27 | 28 | ### Any Other Sections 29 | ### That You Think 30 | ### Might be Useful 31 | 32 | ## License 33 | 34 | Copyright © 2020 FIXME 35 | 36 | This program and the accompanying materials are made available under the 37 | terms of the Eclipse Public License 2.0 which is available at 38 | http://www.eclipse.org/legal/epl-2.0. 39 | 40 | This Source Code may also be made available under the following Secondary 41 | Licenses when the conditions for such availability set forth in the Eclipse 42 | Public License, v. 2.0 are satisfied: GNU General Public License as published by 43 | the Free Software Foundation, either version 2 of the License, or (at your 44 | option) any later version, with the GNU Classpath Exception which is available 45 | at https://www.gnu.org/software/classpath/license.html. 46 | -------------------------------------------------------------------------------- /colorado_lakes_grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/colorado_lakes_grid.png -------------------------------------------------------------------------------- /colorado_lakes_grid_rstudio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/colorado_lakes_grid_rstudio.png -------------------------------------------------------------------------------- /denver_to_berlin.R: -------------------------------------------------------------------------------- 1 | library(maps) 2 | library(geosphere) 3 | 4 | getGreatCircle <- function(userLL,relationLL){ 5 | tmpCircle = greatCircle(userLL,relationLL, n=200) 6 | start = which.min(abs(tmpCircle[,1] - data.frame(userLL)[1,1])) 7 | end = which.min(abs(tmpCircle[,1] - relationLL[1])) 8 | greatC = tmpCircle[start:end,] 9 | return(greatC) 10 | } 11 | 12 | # No margin 13 | par(mar=c(0,0,0,0)) 14 | 15 | denver <- c(-104.9903, 39.7392) 16 | berlin <- c(13.4050, 52.5200) 17 | 18 | great <- getGreatCircle(denver, berlin) 19 | 20 | # World map 21 | map('world', 22 | col="#d2d2d2", fill=TRUE, bg="white", lwd=0.05, 23 | mar=rep(0,4),border=0, ylim=c(-20,80), xlim=c(-140, 40)) 24 | lines(great, col="#c05137", lwd=3) 25 | -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | { 2 | :paths ["src", "resources"] 3 | :deps {org.clojure/clojure {:mvn/version "1.10.0"} 4 | scicloj/clojisr {:mvn/version "1.0.0-BETA10"}} 5 | } 6 | -------------------------------------------------------------------------------- /nj_lakes.R: -------------------------------------------------------------------------------- 1 | dloc = "/home/joannecheng/dev/viz/clojure-map-examples/resources/data_files/new_jersey/NHDWaterbody_2002_shapefile" 2 | lakes_sf = paste(dloc, 3 | "/NHDWaterbody_2002.shp", 4 | sep="") 5 | nj_water <- sf::st_read(lakes_sf) 6 | 7 | colnames(nj_lakes) 8 | 9 | library(ggplot2) 10 | library(maps) 11 | library(sf) 12 | library(raster) 13 | library(rgdal) 14 | library(rmapshaper) 15 | 16 | nj <- map_data("state", region="new jersey") 17 | raster::crs(nj_water) 18 | njcrs <- raster::crs("+proj=tmerc +lat_0=38.8333333333333 +lon_0=-74.5 +k=0.9999 +x_0=150000 +y_0=0 +datum=NAD83 +units=us-ft +no_defs") 19 | sp::spTransform(nj_lakes, njcrs) 20 | 21 | ggplot() + 22 | geom_polygon(data= nj, aes(x=long, y=lat), fill="#ffffff", color="#333333") + 23 | geom_sf(data=nj_water[1:200,], aes(geometry=geometry)) + 24 | coord_sf() 25 | 26 | raster::crs(map_data("state", region="new jersey")) 27 | 28 | smoothr::smooth(nj_water, method="ksmooth") 29 | 30 | library(smoothr) 31 | nj_water 32 | 33 | nj_simplified<-rmapshaper::ms_simplify(nj_water, keep=0.001) 34 | 35 | ggplot() + 36 | geom_polygon(data= nj, aes(x=long, y=lat), fill="#ffffff", color="#333333") + 37 | geom_sf(data=nj_simplified[1:1000,], aes(geometry=geometry)) + 38 | coord_sf() 39 | 40 | nj_ordered <- nj_simplified[order(-nj_simplified$SHAPE_Area),] 41 | -------------------------------------------------------------------------------- /packages_to_install.R: -------------------------------------------------------------------------------- 1 | # Must be at least version 1.8 or else you won't be able to run any examples 2 | # See clojisr docs: https://github.com/scicloj/clojisr#usage-requirements 3 | install.packages("Rserve", "https://www.rforge.net/") 4 | 5 | # If you run into problems installing tidyverse on ubuntu, check out the following blog post 6 | # https://blog.zenggyu.com/en/post/2018-01-29/installing-r-r-packages-e-g-tidyverse-and-rstudio-on-ubuntu-linux/ 7 | # "the tidyverse package requires the following non-R packages" 8 | # libcurl4-openssl-dev, libssl-dev, libxml2-dev. 9 | install.packages("tidyverse", dependencies=TRUE) 10 | 11 | # This was required to use "sf" 12 | # make sure you install libudunits2 before installing the R package 13 | # in ubuntu: `sudo apt-get install libudunits2-dev` 14 | install.packages("udunits2") 15 | 16 | # Make sure you have GDAL installed! 17 | # Mac osx: https://trac.osgeo.org/gdal/wiki/BuildingOnMac 18 | # Ubuntu: https://mothergeo-py.readthedocs.io/en/latest/development/how-to/gdal-ubuntu-pkg.html 19 | install.packages("rgdal") 20 | install.packages("sf") 21 | install.packages("maps") 22 | install.packages("raster") 23 | 24 | install.packages("devtools") 25 | devtools::install_github("tylermorganwall/rayshader") 26 | 27 | 28 | install.packages("svglite") 29 | install.packages("geosphere") 30 | install.packages("av") 31 | -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.dbf: -------------------------------------------------------------------------------- 1 | _!N OBJECTIDN 2 | UNIT_CODECPGIS_NotesCSUNIT_NAMECPDATE_EDITCPSTATECPREGIONCPGNIS_IDCPUNIT_TYPECPCREATED_BYCPMETADATACPPARKNAMECPPUBLICDISPCPDATAACCESSCPUNITCODECPUNITNAMECPGROUPCODECPGROUPNAMECPREGIONCODECPCREATEDATECPCREATEUSERCPEDITDATECPEDITUSERCPMAPMETHODCPMAPSOURCECPSOURCEDATECPXYACCURACYCPGEOMETRYIDCPNOTESCPGlobalIDCPShape__AreNShape__LenN 1ROMO Lands - http://landsnet.nps.gov/tractsnet/documents/ROMO/METADATA/romo_metadata.xmlRocky Mountain National Park 2018-03-27T00:00:00.000Z CO IM 204948 National Park Lands https://irma.nps.gov/App/Reference/Profile/2209626#Rocky Mountain National Park Rocky Mountain Public Map Display Unrestricted ROMO Rocky Mountain National Park N/A N/A IMR 2018-03-31T00:00:00.000Z NPS 2018-04-12T21:08:44.000Z AKONKOWSKI Unknown Unknown Unknown {3A23FAEB-1A49-4AFF-AFF0-3092D45FF010} d431af93-e6b7-40c5-baeb-3848ee1e35b3 1079899504.8736600875854 224833.156231094006216 -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.shp -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.shx -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.zip -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.cpg: -------------------------------------------------------------------------------- 1 | UTF-8 -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.dbf -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.shp -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.shx -------------------------------------------------------------------------------- /resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/RMNP/Rocky_Mountain_National_Park__Trails.zip -------------------------------------------------------------------------------- /resources/data_files/black-canyon-output1.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/black-canyon-output1.tif -------------------------------------------------------------------------------- /resources/data_files/black-canyon-texture4.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/black-canyon-texture4.tif -------------------------------------------------------------------------------- /resources/data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.dbf -------------------------------------------------------------------------------- /resources/data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["WGS84(DD)", DATUM["WGS84", SPHEROID["WGS84", 6378137.0, 298.257223563]], PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH]] -------------------------------------------------------------------------------- /resources/data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shp -------------------------------------------------------------------------------- /resources/data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shx -------------------------------------------------------------------------------- /resources/data_files/new_jersey/NHDWaterbody_2002_shapefile.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/new_jersey/NHDWaterbody_2002_shapefile.zip -------------------------------------------------------------------------------- /resources/data_files/new_jersey/NHDWaterbody_2002_shapefile/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/new_jersey/NHDWaterbody_2002_shapefile/.gitkeep -------------------------------------------------------------------------------- /resources/data_files/rmnp_dem.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/data_files/rmnp_dem.tif -------------------------------------------------------------------------------- /resources/output/germany-test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joannecheng/clojure-map-examples/78227920635bbeb4b2e399c0ff7fb6f66a1bea46/resources/output/germany-test.pdf -------------------------------------------------------------------------------- /rserve_commands.R: -------------------------------------------------------------------------------- 1 | # Load Rserve 2 | library(Rserve) 3 | Rserve(args="--no-save") -------------------------------------------------------------------------------- /src/clojure_map_examples/black_canyon.clj: -------------------------------------------------------------------------------- 1 | (ns clojure-map-examples.black-canyon 2 | (:require [clojisr.v1.r :as r] 3 | [clojisr.v1.require :refer [require-r]] 4 | [clojisr.v1.rserve :as rserve] 5 | [clojure.java.io :as io])) 6 | 7 | (rserve/set-as-default!) 8 | (r/discard-all-sessions) 9 | 10 | (require-r '[rayshader :refer [raster_to_matrix reduce_matrix_size 11 | render_camera render_depth 12 | ray_shade sphere_shade lamb_shade ambient_shade ;; shaders 13 | plot_map plot_3d ;; plotting functions 14 | add_shadow add_overlay 15 | add_water detect_water]] 16 | '[base :refer [summary]] 17 | '[tiff :refer [readTIFF]] 18 | '[raster :refer [extract raster]]) 19 | 20 | (def load-raster (r/r "function(f) raster(f)")) 21 | (def clear-rgl (r/r "rgl::rgl.clear")) 22 | (def rgl-snapshot (r/r "rgl::rgl.snapshot")) 23 | 24 | (def output-location (str (System/getProperty "user.dir") "/resources/output")) 25 | 26 | (def black-canyon-dem 27 | (load-raster (-> (io/resource "data_files/black-canyon-output1.tif") io/file str))) 28 | 29 | ;; (def black-canyon-texture (readTIFF (-> (io/resource "data_files/black-canyon-output1.tif") io/file str))) 30 | ;; FIXME: overlay/texture isn't working now 31 | 32 | (def bc-dem-matrix 33 | (-> black-canyon-dem 34 | (raster_to_matrix) 35 | (reduce_matrix_size 0.5))) 36 | 37 | (clear-rgl) 38 | (def ambientshadows (ambient_shade bc-dem-matrix)) 39 | (-> bc-dem-matrix 40 | (sphere_shade :texture "desert") 41 | (add_water (detect_water bc-dem-matrix :min_area 270) :color "steelblue") 42 | (add_shadow (ray_shade bc-dem-matrix :sunangle 200 :sunaltitude 5 :zscale 33 :lambert false) :max_darken 0.5) 43 | (add_shadow (lamb_shade bc-dem-matrix :sunangle 190 :sunaltitude 7 :zscale 33) :max_darken 0.7) 44 | (add_shadow ambientshadows :max_darken 0.2) 45 | (plot_3d bc-dem-matrix :zscale 30 :windowsize 1200)) 46 | 47 | (render_camera :theta 29 :phi 30 :zoom 0.8) 48 | 49 | (for [x (range 0 360 5)] 50 | (do 51 | (render_camera :theta x :phi 30) 52 | (rgl-snapshot (str output-location "/theta-" (format "%03d" x) ".png") :fmt "png" :top true))) 53 | (rgl-snapshot :filename "/home/joannecheng/blackcanyon.png") 54 | -------------------------------------------------------------------------------- /src/clojure_map_examples/core.clj: -------------------------------------------------------------------------------- 1 | (ns clojure-map-examples.core 2 | (:gen-class)) 3 | 4 | (defn -main 5 | [& args] 6 | "This does nothing") 7 | -------------------------------------------------------------------------------- /src/clojure_map_examples/denver_berlin.clj: -------------------------------------------------------------------------------- 1 | (ns clojure-map-examples.denver-berlin 2 | (:require [clojisr.v1.r :as r] 3 | [clojisr.v1.require :refer [require-r]])) 4 | 5 | (require-r '[maps :as maps] 6 | '[geosphere :as geosphere :refer [greatCircle]]) 7 | 8 | ;; rewriting this so we don't override clojure's very very important 9 | ;; "map" function 10 | 11 | (defn great-circle [loc1, loc2] 12 | ((r/r "function(userLL,relationLL){ 13 | tmpCircle = greatCircle(userLL,relationLL, n=200) 14 | start = which.min(abs(tmpCircle[,1] - data.frame(userLL)[1,1])) 15 | end = which.min(abs(tmpCircle[,1] - relationLL[1])) 16 | greatC = tmpCircle[start:end,] 17 | return(greatC)}") 18 | loc1 loc2)) 19 | 20 | (def world-map (r/r "maps::map")) 21 | (def berlin [13.4050 52.5200]) 22 | (def denver [-104.9903 39.7392]) 23 | 24 | (world-map "world" :col "#d2d2d2" :fill true :bg "white" 25 | :lwd 0.05 :ylim [-20 80] :xlim [-140 40]) 26 | ((r/r "lines") (great-circle denver berlin) :col "#c05137" :lwd 3) 27 | 28 | ;;# No margin 29 | ;;par(mar=c(0,0,0,0)) 30 | -------------------------------------------------------------------------------- /src/clojure_map_examples/lakes_and_rivers.clj: -------------------------------------------------------------------------------- 1 | (ns clojure-map-examples.lakes-and-rivers 2 | (:require [clojisr.v1.r :as r] 3 | [clojisr.v1.require :refer [require-r]] 4 | [clojisr.v1.rserve :as rserve] 5 | [clojure.java.io :as io])) 6 | 7 | (require-r '[sf :as sf :refer [st_read]] 8 | '[ggplot2 :as ggplot2 :refer [ggplot aes geom_polygon theme_void 9 | coord_sf ;; takes a projection from the first shapefile in plot and applies it to the map 10 | geom_sf]] 11 | '[utils :as utils] 12 | '[rmapshaper :as rmapshaper] 13 | '[base :as base :refer [$ summary]]) 14 | 15 | (defn read-shapefile-resource [sf-resource] 16 | (-> sf-resource 17 | io/file 18 | str 19 | st_read)) 20 | 21 | (def colorado-water 22 | (-> "data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shp" 23 | io/resource 24 | read-shapefile-resource)) 25 | 26 | (defn water-with-names [df] 27 | (r/bra 28 | df 29 | (base/! (base/is-na ($ df 'name))) 30 | nil)) 31 | 32 | (defn water-without-names [df] 33 | ;; Think of ($ dataframe 'col-name) as 34 | ;; (get map-object :key-name) 35 | (r/bra df (base/is-na ($ df 'name)) nil)) 36 | 37 | (defn state-basemap [state] 38 | (geom_polygon :data (ggplot2/map_data "state" :region state) 39 | (aes :x 'long :y 'lat :group 'group) 40 | :fill "#F7F5F088" :color "#333333" :size 0.2)) 41 | 42 | #_(r/r "X11()") 43 | (r/r "X11(display=\"\", width=12, height=10)") 44 | (r/r "dev.off()") 45 | 46 | (-> (ggplot) 47 | (r/r+ (state-basemap "colorado") 48 | (geom_sf :data (water-with-names colorado-water) (aes :geometry 'geometry) 49 | :fill "#72bfcf" :size 0.1) 50 | (geom_sf :data (water-without-names colorado-water) (aes :geometry 'geometry) 51 | :fill "#333333" :size 0.1 52 | :color "#274a51") 53 | 54 | (coord_sf) 55 | (theme_void))) 56 | 57 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 58 | ;; New Jersey 59 | 60 | ;; Open this file in QGIS to get a good overview 61 | 62 | ; Load water data 63 | (def new-jersey-water 64 | (-> "data_files/new_jersey/NHDWaterbody_2002_shapefile/NHDWaterbody_2002.shp" 65 | io/resource 66 | read-shapefile-resource)) 67 | 68 | ; What are the columns of data we can find here? 69 | (base/colnames new-jersey-water) 70 | ;; Sometimes i think it's easier to deal with clojure types 71 | ;; so I can interact with the repl easier 72 | (r/r->clj (base/colnames new-jersey-water)) 73 | ;; [defun to comment] 74 | ;; => ["COMID" 75 | ;; "PERMANENT_" 76 | ;; "FDATE" 77 | ;; "RESOLUTION" 78 | ;; "GNIS_ID" 79 | ;; "GNIS_NAME" 80 | ;; "AREASQKM" 81 | ;; "ELEVATION" 82 | ;; "REACHCODE" 83 | ;; "FTYPE" 84 | ;; "FCODE" 85 | ;; "FTYPE_DESC" 86 | ;; "FCODE_DESC" 87 | ;; "SHAPE_Leng" 88 | ;; "SHAPE_Area" 89 | ;; "geometry"] 90 | 91 | ;; FTYPE_DESC is the column we want 92 | 93 | ;; What are the types of water? 94 | (-> ($ new-jersey-water 'FTYPE_DESC) 95 | r/r->clj 96 | distinct) 97 | ;; => ("Canal/Ditch" 98 | ;; "Stream/River" 99 | ;; "Sea/Ocean" 100 | ;; "Spillway" 101 | ;; "Lake/Pond" 102 | ;; "Reservoir" 103 | ;; "Estuary") 104 | 105 | (defn filter-by-ftype [df ftype] 106 | (r/bra df 107 | (r/r== ($ df 'FTYPE_DESC) ftype) 108 | nil)) 109 | 110 | ;; Draw basemap 111 | (-> (ggplot) 112 | (r/r+ #_(state-basemap "new jersey") 113 | (geom_polygon :data (ggplot2/map_data "state" :region "new jersey") 114 | (aes :x 'long :y 'lat :group 'group) 115 | :fill "#F7F5F088" :color "#333333" :size 0.2) 116 | (theme_void) 117 | (ggplot2/coord_map))) 118 | 119 | ;; Draw lakes 120 | (-> (ggplot) 121 | (r/r+ (state-basemap "new jersey") 122 | ; draw by "adding layers" to the plot 123 | (geom_sf :data (filter-by-ftype new-jersey-water "Lake/Pond") 124 | (aes :geometry 'geometry) 125 | :fill "#72bfcf" :size 0.1) 126 | (coord_sf) 127 | (theme_void))) 128 | ;; Notice the basemap isn't showing up 129 | 130 | ;; Let's look at the projections 131 | (sf/st_crs new-jersey-water) 132 | 133 | (sf/st_crs colorado-water) 134 | ;; CRS arguments: +proj=longlat +ellps=WGS84 +no_defs 135 | 136 | ;; transform new-jersey-water to use the same crs as the 137 | ;; colorado lakes shapefile 138 | (def nj-water-transformed 139 | (sf/st_transform new-jersey-water (sf/st_crs colorado-water))) 140 | 141 | ;; Fix issue 142 | (-> (ggplot) 143 | (r/r+ (state-basemap "new jersey") 144 | ; draw by "adding layers" to the plot 145 | (geom_sf :data (filter-by-ftype nj-water-transformed "Lake/Pond") 146 | (aes :geometry 'geometry) 147 | :fill "#72bfcf" :size 0.05) 148 | (coord_sf) 149 | (theme_void))) 150 | 151 | ;; Let's plot all this water and see the output in a pdf 152 | (def water-plot 153 | (-> (ggplot) 154 | (r/r+ (state-basemap "new jersey") 155 | ; draw by "adding layers" to the plot 156 | (geom_sf :data (filter-by-ftype nj-water-transformed "Lake/Pond") 157 | (aes :geometry 'geometry) 158 | ;:color "NA" 159 | :fill "#72bfcf" :size 0.05) 160 | 161 | (geom_sf :data (filter-by-ftype nj-water-transformed "Canal/Ditch") 162 | (aes :geometry 'geometry) 163 | ;:color "NA" 164 | :fill "#72bfcf" :size 0.05) 165 | 166 | (geom_sf :data (filter-by-ftype nj-water-transformed "Stream/River") 167 | (aes :geometry 'geometry) 168 | ;:color "NA" 169 | :fill "#72bfcf" :size 0.05) 170 | (coord_sf) 171 | (theme_void)))) 172 | water-plot 173 | 174 | (def output-location (str (System/getProperty "user.dir") "/resources/output")) 175 | (ggplot2/ggsave (str output-location "/nj_water.pdf") :plot water-plot :device "pdf") 176 | 177 | ;; Examine pdf 178 | 179 | 180 | ;; Let's look at lakes again 181 | 182 | ;; Can we simplify the shapes, since we lose a lot of detail anyway? 183 | (def nj-water-simplified (rmapshaper/ms_simplify nj-water-transformed :keep 0.1)) 184 | ;; THIS WILL TAKE A WHILE 185 | 186 | (def simplified-plot 187 | (-> (ggplot) 188 | (r/r+ (state-basemap "new jersey") 189 | ; draw by "adding layers" to the plot 190 | (geom_sf :data (filter-by-ftype nj-water-simplified "Lake/Pond") 191 | (aes :geometry 'geometry) 192 | :color "NA" 193 | :fill "#72bfcf" :size 0.05) 194 | (+ 1 1) 195 | 196 | (geom_sf :data (filter-by-ftype nj-water-simplified "Canal/Ditch") 197 | (aes :geometry 'geometry) 198 | :color "NA" 199 | :fill "#72bfcf" :size 0.05) 200 | 201 | (geom_sf :data (filter-by-ftype nj-water-simplified "Stream/River") 202 | (aes :geometry 'geometry) 203 | :color "NA" 204 | :fill "#72bfcf" :size 0.05) 205 | (coord_sf) 206 | (theme_void)))) 207 | 208 | (ggplot2/ggsave (str output-location "/nj_water_simplified.pdf") :plot simplified-plot :device "pdf") 209 | 210 | ;; This is where things start getting... weird? 211 | 212 | ;; Smoothing out lines 213 | ;; https://github.com/ateucher/rmapshaper 214 | 215 | ;; Look at original vintage map 216 | ;; Can we lay these out this into a grid? 217 | 218 | ;; With the magic of R, we can! 219 | ;; TODO: show image of small multiples 220 | ;; We need to get the center of each lake 221 | 222 | ;; 223 | 224 | (r/r->clj (base/colnames new-jersey-water)) 225 | 226 | (def order-by-shape-area (r/r "function(df) { df[order(-df$SHAPE_Area),] }")) 227 | ;; I used raw R code because it took me a while to figure out how 228 | ;; to get `order` to work. I should have asked for help sorry! 229 | 230 | (def nj-lakes-ordered 231 | (-> (filter-by-ftype nj-water-transformed "Lake/Pond") 232 | ;; nj_water_ordered <- nj_water[order(-nj_water$shape_area),] 233 | order-by-shape-area 234 | (r/bra (r/colon 0 10) nil))) 235 | 236 | ($ nj-lakes-ordered 'SHAPE_Area) 237 | 238 | 239 | ;; Original code 240 | ;;lakes$centroid <- 241 | ;;sf::st_centroid(test_lakes$geometry) %>% 242 | ;;sf::st_geometry() 243 | ;; 244 | ;;padding <- 0.2 245 | ;;par(mar = c(0, 0, 0, 0)) 246 | ;;lake_grid_fn <- function(x) { 247 | ;; ggplot(test_lakes[x,]) + 248 | ;; geom_sf(size=0.1, color="#1D150f", fill="#c1d7d3y") + 249 | ;; ggtitle(test_lakes$name[x]) + 250 | ;; theme_void() + 251 | ;; theme(plot.title = element_text(size=5, hjust=0.5)) + 252 | ;; coord_sf( 253 | ;; xlim = c(test_lakes$centroid[[x]][1]-0.13, 254 | ;; test_lakes$centroid[[x]][1]+0.13), 255 | ;; ylim = c(test_lakes$centroid[[x]][2]-0.08, 256 | ;; test_lakes$centroid[[x]][2]+0.08), 257 | ;; expand = FALSE 258 | ;; ) 259 | ;; } 260 | ;; 261 | ;;plot_list <- lapply(X=1:nrow(test_lakes), FUN=lake_grid_fn) 262 | ;;g <- cowplot::plot_grid(plotlist = plot_list, ncol=4) 263 | ;;g 264 | 265 | (require-r '[cowplot :as cowplot]) 266 | 267 | ;; find centroids 268 | ($ nj-lakes-ordered 'centroid) 269 | (def centroids 270 | (-> nj-lakes-ordered 271 | (sf/st_centroid) 272 | (sf/st_geometry))) 273 | (r/r->clj centroids) 274 | 275 | ;; save this to a new dataframe 276 | (def nj-lakes-centroids 277 | (base/data-frame :geometry ($ nj-lakes-ordered 'geometry) 278 | :name ($ nj-lakes-ordered 'GNIS_NAME) 279 | 280 | ;; BUG: can't save this output to the centroid col 281 | :centroid (-> nj-lakes-ordered 282 | (sf/st_centroid) 283 | (sf/st_geometry)))) 284 | 285 | ;; BUG: this returns null 286 | ($ nj-lakes-centroids 'centroid) 287 | 288 | (def lake_grid_fn (r/r "function(df, centroids) { 289 | function(x) { 290 | ggplot(df[x,]) + 291 | ggtitle(df$GNIS_NAME[x]) + 292 | 293 | coord_sf( 294 | xlim=c(centroids[[x]][1]-0.13, centroids[[x]][1]+0.13), 295 | ylim=c(centroids[[x]][2]-0.08, centroids[[x]][2]+0.08), 296 | expand=FALSE 297 | ) 298 | 299 | } 300 | } 301 | ")) 302 | 303 | (def plot-list (base/lapply 304 | :X (r/colon 1 10) 305 | :FUN (lake_grid_fn nj-lakes-ordered centroids))) 306 | 307 | (cowplot/plot_grid :plotlist plot-list :ncol 4) 308 | -------------------------------------------------------------------------------- /src/clojure_map_examples/raster_examples.clj: -------------------------------------------------------------------------------- 1 | (ns clojure-map-examples.raster-examples 2 | (:require [clojisr.v1.r :as r] 3 | [clojisr.v1.require :refer [require-r]] 4 | [clojisr.v1.rserve :as rserve] 5 | [clojure.java.io :as io])) 6 | 7 | (rserve/set-as-default!) 8 | (r/discard-all-sessions) 9 | 10 | (require-r '[rayshader :refer [raster_to_matrix reduce_matrix_size 11 | render_camera render_depth 12 | ray_shade sphere_shade lamb_shade ambient_shade ;; shaders 13 | plot_map plot_3d ;; plotting functions 14 | add_shadow 15 | add_water detect_water]] 16 | '[base :refer [summary]] 17 | '[raster :refer [extract raster]]) 18 | 19 | ;; http://viewfinderpanoramas.org/dem3.html#nam 20 | 21 | ; TODO: extract elevation values (in meters) from a raster file 22 | ;; Extract raster data 23 | 24 | (def output-location (str (System/getProperty "user.dir") "/resources/output")) 25 | (def load-raster (r/r "function(f) raster(f)")) 26 | (def clear-rgl (r/r "rgl::rgl.clear")) 27 | (def rgl-snapshot (r/r "rgl::rgl.snapshot")) 28 | 29 | (def rmnp_dem 30 | (load-raster (-> (io/resource "data_files/rmnp_dem.tif") io/file str))) 31 | 32 | (def rmnp-dem-matrix 33 | (-> rmnp_dem 34 | (raster_to_matrix) 35 | #_(reduce_matrix_size 0.5))) 36 | 37 | ;; simple example 38 | (-> rmnp-dem-matrix 39 | (sphere_shade) 40 | plot_map) 41 | 42 | ;; 'add water' 43 | (-> rmnp-dem-matrix 44 | sphere_shade 45 | (add_water (detect_water rmnp-dem-matrix :min_area 250) :color "steelblue") 46 | plot_map) 47 | 48 | ;; 'add water' 49 | (-> rmnp-dem-matrix 50 | (sphere_shade :texture "imhof4") 51 | (add_water (detect_water rmnp-dem-matrix :min_area 250) :color "steelblue") 52 | plot_map) 53 | 54 | ;; using lamb_shade 55 | (-> rmnp-dem-matrix 56 | (lamb_shade :zscale 33) 57 | plot_map) 58 | 59 | ;; adding shadow 60 | (-> rmnp-dem-matrix 61 | sphere_shade 62 | (add_shadow (ray_shade rmnp-dem-matrix :zscale 23 :sunaltitude 3 :lambert false) :max_darken 0.5) 63 | (add_shadow (lamb_shade rmnp-dem-matrix :zscale 23 :sunaltitude 3) :max_darken 0.5) 64 | plot_map) 65 | 66 | ;; Render 3D 67 | (-> rmnp-dem-matrix 68 | sphere_shade 69 | (plot_3d rmnp-dem-matrix :zscale 10)) 70 | 71 | ;; Render 3D with lots of fancy options to focus on lakes 72 | (clear-rgl) 73 | (def ambientshadows (ambient_shade rmnp-dem-matrix)) 74 | (-> rmnp-dem-matrix 75 | sphere_shade 76 | (add_water (detect_water rmnp-dem-matrix :min_area 270) :color "steelblue") 77 | (add_shadow (ray_shade rmnp-dem-matrix :sunangle 200 :sunaltitude 5 :zscale 33 :lambert false) :max_darken 0.5) 78 | (add_shadow (lamb_shade rmnp-dem-matrix :sunangle 190 :sunaltitude 3 :zscale 33) :max_darken 0.7) 79 | (add_shadow ambientshadows :max_darken 0.2) 80 | (plot_3d rmnp-dem-matrix :zscale 15)) 81 | 82 | (render_camera :theta 315 :zoom 0.8 :phi 30) 83 | (render_camera :theta 315 :phi 60 :zoom 0.99) 84 | 85 | (render_depth :focus 0.19 :focallength 40 :filename "test-3d.png") 86 | 87 | ;; Focus longs peak 88 | (render_camera :theta 35 :zoom 0.15 :phi 8) 89 | (render_depth :focus 0.31 :focallength 40 :filename (str output-location "/test-3d.png")) 90 | 91 | (for [x (range 10 100 5)] 92 | (render_depth :focus 0.19 :focallength x :filename (str output-location "/focal-" x ".png"))) 93 | 94 | (for [x (range 0.1 0.8 0.02)] 95 | (render_depth :focus x :focallength 30 :filename (str output-location "/focus-" (format "%.2f" x) ".png"))) 96 | 97 | (for [x (range 0 360 5)] 98 | (do 99 | (render_camera :theta x :phi 30) 100 | (rgl-snapshot (str output-location "/theta-" (format "%03d" x) ".png") :fmt "png" :top true))) 101 | 102 | (for [x (range 0 90 5)] 103 | (do 104 | (render_camera :phi x) 105 | (rgl-snapshot (str output-location "/phi-" (format "%02d" x) ".png") :fmt "png" :top true))) 106 | 107 | 108 | ;; add_water(detect_water(rmnp_mat), color = "lightblue") %>% 109 | ;; add_shadow(ray_shade(rmnp_mat, sunangle = 190, sunaltitude = 3, zscale = 33, lambert = FALSE), max_darken = 0.5) %>% 110 | ;; add_shadow(lamb_shade(rmnp_mat, sunangle = 190, sunaltitude = 3, zscale = 33), max_darken = 0.5) %>% 111 | ;; render_camera(theta = 315, phi = 8, zoom = 0.1, fov = 90) 112 | ;; render_depth(focus = 0.56, focallength = 100) 113 | -------------------------------------------------------------------------------- /src/clojure_map_examples/shapefile_example.clj: -------------------------------------------------------------------------------- 1 | (ns clojure-map-examples.shapefile-example 2 | (:require [clojisr.v1.r :as r] 3 | [clojisr.v1.require :refer [require-r]] 4 | [clojure.java.io :as io])) 5 | 6 | (require-r '[ggplot2 :as ggplot2 :refer [ggplot aes theme_void ;; general plotting 7 | map_data ;; get base map for area (ex: Colorado, Germany) 8 | coord_sf ;; takes a projection from the first shapefile in plot and applies it to the map 9 | coord_map ;; set map projection 10 | ggsave ;; save plot 11 | geom_sf geom_polygon]] ;; plotting data 12 | '[base :as base :refer [$ summary]] 13 | '[sf :refer [st_bbox st_crop st_read]]) 14 | 15 | (defn read-shapefile-resource [sf-resource] 16 | (-> sf-resource 17 | io/file 18 | str 19 | st_read)) 20 | 21 | (def output-location (str (System/getProperty "user.dir") "/resources/output")) 22 | 23 | (require-r '[ggplot2 :refer [map_data]]) 24 | (def colorado-base (map_data "state" :region "Colorado")) 25 | (summary colorado-base) 26 | 27 | (def germany-base (map_data "world" :region "Germany")) 28 | 29 | ;; Plot Germany 30 | (def germany-plot 31 | (-> (ggplot) 32 | (r/r+ (geom_polygon :data germany-base (aes :x 'long :y 'lat :group 'group) 33 | :fill "#90EE90" :color "#000000" :size 0.4) 34 | (coord_map) ;; projection 35 | (theme_void)))) 36 | germany-plot 37 | (r/r "X11()") 38 | 39 | \;; Plot Colorado 40 | (-> (ggplot) ;; initializes a 'ggplot' object, the 'base' of the graph 41 | (r/r+ (geom_polygon :data colorado-base 42 | ;; passing in the data (collection of lat/long coordinates) 43 | ;; A reminder - colorado-base is a dataframe 44 | 45 | (aes :x 'long :y 'lat :group 'group) 46 | ;; 'aesthetic mapping' - describes how the 47 | ;; incoming data is mapped to visual properties 48 | ;; in this case, the 'long' column is mapped to the x axis, 49 | ;; the 'lat' column is mapped to the y axis 50 | 51 | :fill "#eeeeee" :color "#000000" :size 0.2) ;; styling 52 | (coord_map) ;; Sets the projection. Default is mercator 53 | (theme_void))) ;; removes axis lines from the chart 54 | 55 | (def colorado-water (-> "data_files/lakes/geo_export_1d691995-66a3-4b66-8aa2-4ae94088e589.shp" 56 | io/resource 57 | read-shapefile-resource)) 58 | 59 | ;; Quick summary of colorado-water 60 | (summary colorado-water) 61 | ;; Get a column of a dataframe 62 | ($ colorado-water 'name) 63 | ;; turn it into a clojure list for easier inspection 64 | (r/r->clj ($ colorado-water 'name)) 65 | 66 | ;; Filter bodies of water with names 67 | (def colorado-water-with-names 68 | (r/bra ;; basically [] 69 | colorado-water 70 | (base/! (base/is-na ($ colorado-water 'name))) 71 | r/empty-symbol)) ;; , 72 | 73 | ;;(def lake-blue "#3e98ed") 74 | (def lake-blue "#3187b1") 75 | (def grey "#555555") 76 | (def map-base "#f6f6f5") 77 | 78 | ;; Plot all colorado water 79 | (defn colorado-water-plot [] 80 | (-> (ggplot) 81 | (r/r+ (geom_polygon :data colorado-base (aes :x 'long :y 'lat :group 'group) 82 | :color "#000000" :fill map-base :size 0.2) 83 | (geom_sf :data colorado-water :size 0.1 :color "#111111" :fill lake-blue (aes :geometry 'geometry)) 84 | ;;geom_sf(data=colorado-water_with_names, aes(geometry=geometry), color=NA, fill="#2c7bb6") + 85 | (coord_sf) 86 | (theme_void)))) 87 | (colorado-water-plot) 88 | 89 | (defn colorado-filtered [] 90 | (-> (ggplot) 91 | (r/r+ (geom_polygon :data colorado-base (aes :x 'long :y 'lat :group 'group) 92 | :color "#000000" :fill map-base :size 0.2) 93 | (geom_sf :data colorado-water :size 0.05 :color "#111111cc" :fill "#cccccccc" (aes :geometry 'geometry)) 94 | (geom_sf :data colorado-water-with-names (aes :geometry 'geometry) :color "#111111" :fill lake-blue 95 | :size 0.05) 96 | (coord_sf) 97 | (theme_void)))) 98 | (colorado-filtered) 99 | 100 | ;; Save to file 101 | (ggsave :plot (colorado-filtered) 102 | :file (str output-location "/colorado-water-filtered-output.png") 103 | :height 12 :width 16) 104 | 105 | 106 | ;; Get RMNP shapefile 107 | (def rmnp-sf-file (io/resource "data_files/RMNP/Rocky_Mountain_National_Park__Boundary_Polygon.shp")) 108 | (def rmnp-trails-sf-file (io/resource "data_files/RMNP/Rocky_Mountain_National_Park__Trails.shp")) 109 | (def rmnp-sf (read-shapefile-resource rmnp-sf-file)) 110 | (def rmnp-trails-sf (read-shapefile-resource rmnp-trails-sf-file)) 111 | 112 | ;; Filter by Area 113 | ;; Get BBox 114 | (def rmnp-bbox 115 | (interleave 116 | [:xmin :ymin :xmax :ymax] 117 | (r/r->clj 118 | (st_bbox rmnp-sf)))) 119 | 120 | (def rmnp-colorado-water (apply st_crop colorado-water rmnp-bbox)) 121 | 122 | ;; Adding More shapefiles - trails, park boundary 123 | (def park-green "#a7b996aa") 124 | (-> (ggplot) 125 | (r/r+ (geom_sf :data rmnp-sf (aes :geometry 'geometry) :size 0.1 :fill park-green) 126 | (geom_sf :data rmnp-colorado-water (aes :geometry 'geometry) :size 0.1 :fill lake-blue) 127 | (geom_sf :data rmnp-trails-sf (aes :geometry 'geometry) :size 0.2) 128 | (theme_void))) 129 | --------------------------------------------------------------------------------