This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(tidyverse)
Registered S3 method overwritten by 'dplyr':
method from
print.rowwise_df
[30m-- [1mAttaching packages[22m --------------------------------------- tidyverse 1.2.1 --[39m
[30m[32mv[30m [34mggplot2[30m 3.2.1 [32mv[30m [34mpurrr [30m 0.3.2
[32mv[30m [34mtibble [30m 2.1.3 [32mv[30m [34mdplyr [30m 0.8.3
[32mv[30m [34mtidyr [30m 1.0.0 [32mv[30m [34mstringr[30m 1.4.0
[32mv[30m [34mreadr [30m 1.3.1 [32mv[30m [34mforcats[30m 0.4.0[39m
[30m-- [1mConflicts[22m ------------------------------------------ tidyverse_conflicts() --
[31mx[30m [34mdplyr[30m::[32mfilter()[30m masks [34mstats[30m::filter()
[31mx[30m [34mdplyr[30m::[32mlag()[30m masks [34mstats[30m::lag()[39m
library(sf)
Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(GADMTools)
Loading required package: sp
Loading required package: classInt
Loading required package: rgdal
rgdal: version: 1.4-4, (SVN revision 833)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/usuagro/Documents/R/win-library/3.6/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/usuagro/Documents/R/win-library/3.6/rgdal/proj
Linking to sp version: 1.3-1
Attaching package: 㤼㸱GADMTools㤼㸲
The following object is masked from 㤼㸱package:utils㤼㸲:
vignette
system.file("gpkg/nc.gpkg",package = "sf") %>%
read_sf()%>%
st_transform(32119)%>%
select(BIR74) %>%
plot(gratitude=TRUE,axes=TRUE)
(read_sf(system.file("gpkg/nc.gpkg",package = "sf")))
Simple feature collection with 100 features and 14 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
epsg (SRID): 4267
proj4string: +proj=longlat +datum=NAD27 +no_defs
(COL<-gadm_sf.loadCountries(c("COL"), level=0,
basefile="/"))
$basename
[1] "/"
$sf
Simple feature collection with 1 feature and 2 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -81.84153 ymin: -4.228429 xmax: -66.87033 ymax: 15.91247
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
ISO NAME_0 geometry
1 COL Colombia MULTIPOLYGON (((-78.97958 1...
$level
[1] 0
$hasBGND
[1] FALSE
attr(,"class")
[1] "gadm_sf"
gadm_plot(COL)
plotear colombia
plot(cars)
(DEPTOS<-gadm_sf.loadCountries(c("COL"), level=1,
basefile="/"))
$basename
[1] "/"
$sf
Simple feature collection with 32 features and 5 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -81.84153 ymin: -4.228429 xmax: -66.87033 ymax: 15.91247
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 10 features:
ISO NAME_0 NAME_1 TYPE_1 ENGTYPE_1 geometry
1 COL Colombia Amazonas Comisaría Commissiary MULTIPOLYGON (((-69.43138 -...
12 COL Colombia Antioquia Departamento Department MULTIPOLYGON (((-76.99986 8...
23 COL Colombia Arauca Intendencia Intendancy MULTIPOLYGON (((-69.92316 6...
27 COL Colombia Atlántico Departamento Department MULTIPOLYGON (((-74.8816 10...
28 COL Colombia Bolívar Departamento Department MULTIPOLYGON (((-75.79681 1...
29 COL Colombia Boyacá Departamento Department MULTIPOLYGON (((-74.2158 5....
30 COL Colombia Caldas Departamento Department MULTIPOLYGON (((-75.3569 4....
31 COL Colombia Caquetá Intendencia Intendancy MULTIPOLYGON (((-73.88365 -...
32 COL Colombia Casanare Intendencia Intendancy MULTIPOLYGON (((-72.6363 4....
2 COL Colombia Cauca Departamento Department MULTIPOLYGON (((-77.97681 2...
$level
[1] 1
$hasBGND
[1] FALSE
attr(,"class")
[1] "gadm_sf"
gadm_plot(DEPTOS)
(MUNI<-gadm_sf.loadCountries(c("COL"), level=2,
basefile="/"))
$basename
[1] "/"
$sf
Simple feature collection with 1065 features and 6 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -81.84153 ymin: -4.228429 xmax: -66.87033 ymax: 15.91247
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 10 features:
ISO NAME_0 NAME_1 NAME_2 TYPE_2 ENGTYPE_2
15629 COL Colombia Amazonas El Encanto Corregimiento Departamento Corregimiento Departamento
15634 COL Colombia Amazonas La Chorrera Corregimiento Departamento Corregimiento Departamento
15699 COL Colombia Amazonas La Pedrera Corregimiento Departamento Corregimiento Departamento
16578 COL Colombia Amazonas Leticia Municipio Municipality
15505 COL Colombia Amazonas Mirití-Paraná Corregimiento Departamento Corregimiento Departamento
16577 COL Colombia Amazonas Puerto Nariño Municipio Municipality
15494 COL Colombia Amazonas Puerto Santander Corregimiento Departamento Corregimiento Departamento
16055 COL Colombia Amazonas Tarapacá Corregimiento Departamento Corregimiento Departamento
14570 COL Colombia Antioquia Abejorral Municipio Municipality
14343 COL Colombia Antioquia Abriaquí Municipio Municipality
geometry
15629 MULTIPOLYGON (((-73.43552 -...
15634 MULTIPOLYGON (((-71.9802 -1...
15699 MULTIPOLYGON (((-72.61586 -...
16578 MULTIPOLYGON (((-70.0579 -4...
15505 MULTIPOLYGON (((-70.2188 -0...
16577 MULTIPOLYGON (((-70.28952 -...
15494 MULTIPOLYGON (((-71.4002 -0...
16055 MULTIPOLYGON (((-70.1296 -3...
14570 MULTIPOLYGON (((-75.5753 5....
14343 MULTIPOLYGON (((-76.0697 6....
$level
[1] 2
$hasBGND
[1] FALSE
attr(,"class")
[1] "gadm_sf"
gadm_plot(MUNI)
###EXTRACCION DEPARTAMENTO
CAS<-gadm_subset(DEPTOS,level = 1,regions ="Casanare")
gadm_plot(CAS)%>%gadm_showNorth("tl")%>% gadm_showScale('bl')
(sbox<-gadm_getBbox(CAS))
xmin ymin xmax ymax
-73.098900 4.246699 -69.847870 6.250501
str(sbox)
'bbox' Named num [1:4] -73.1 4.25 -69.85 6.25
- attr(*, "names")= chr [1:4] "xmin" "ymin" "xmax" "ymax"
- attr(*, "crs")=List of 2
..$ epsg : int 4326
..$ proj4string: chr "+proj=longlat +datum=WGS84 +no_defs"
..- attr(*, "class")= chr "crs"
(STUDY_AREA<-gadm_crop(DEPTOS,xmin =-74 ,ymin = 5 ,xmax = -70 ,ymax =6.5 ))
although coordinates are longitude/latitude, st_intersection assumes that they are planar
attribute variables are assumed to be spatially constant throughout all geometries
$basename
[1] "/"
$sf
Simple feature collection with 6 features and 5 fields
geometry type: GEOMETRY
dimension: XY
bbox: xmin: -74 ymin: 5 xmax: -70 ymax: 6.5
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
ISO NAME_0 NAME_1 TYPE_1 ENGTYPE_1 geometry
23 COL Colombia Arauca Intendencia Intendancy POLYGON ((-70 6.1102, -70.0...
29 COL Colombia Boyacá Departamento Department POLYGON ((-74 5.722835, -73...
32 COL Colombia Casanare Intendencia Intendancy POLYGON ((-72.95068 5, -72....
6 COL Colombia Cundinamarca Departamento Department POLYGON ((-74 5.39434, -73....
20 COL Colombia Santander Departamento Department MULTIPOLYGON (((-72.6433 6....
26 COL Colombia Vichada Comisaría Commissiary POLYGON ((-70.99905 5, -70....
$level
[1] 1
$hasBGND
[1] FALSE
attr(,"class")
[1] "gadm_sf"
gadm_plot(STUDY_AREA)
DEPTOS$sf
Simple feature collection with 32 features and 5 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -81.84153 ymin: -4.228429 xmax: -66.87033 ymax: 15.91247
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 10 features:
ISO NAME_0 NAME_1 TYPE_1 ENGTYPE_1 geometry
1 COL Colombia Amazonas Comisaría Commissiary MULTIPOLYGON (((-69.43138 -...
12 COL Colombia Antioquia Departamento Department MULTIPOLYGON (((-76.99986 8...
23 COL Colombia Arauca Intendencia Intendancy MULTIPOLYGON (((-69.92316 6...
27 COL Colombia Atlántico Departamento Department MULTIPOLYGON (((-74.8816 10...
28 COL Colombia Bolívar Departamento Department MULTIPOLYGON (((-75.79681 1...
29 COL Colombia Boyacá Departamento Department MULTIPOLYGON (((-74.2158 5....
30 COL Colombia Caldas Departamento Department MULTIPOLYGON (((-75.3569 4....
31 COL Colombia Caquetá Intendencia Intendancy MULTIPOLYGON (((-73.88365 -...
32 COL Colombia Casanare Intendencia Intendancy MULTIPOLYGON (((-72.6363 4....
2 COL Colombia Cauca Departamento Department MULTIPOLYGON (((-77.97681 2...
install.packages("mapview")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
https://cran.rstudio.com/bin/windows/Rtools/
Installing package into 㤼㸱C:/Users/usuagro/Documents/R/win-library/3.6㤼㸲
(as 㤼㸱lib㤼㸲 is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/mapview_2.7.0.zip'
Content type 'application/zip' length 2947906 bytes (2.8 MB)
downloaded 2.8 MB
package ‘mapview’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\usuagro\AppData\Local\Temp\RtmpecPacY\downloaded_packages
suppressPackageStartupMessages(library(mapview))
DEPTOS$sf%>%mapview(zcol="NAME_1",legend=TRUE,col.regions=sf.colors)
CAS_MUN<-gadm_subset(MUNI,level = 1,regions ="Casanare")
gadm_plot(CAS_MUN)%>%gadm_showNorth("tl")%>% gadm_showScale('bl')
CAS_MUN$sf%>%mapview(zcol="NAME_1",legend=TRUE,col.regions=sf.colors)
class(CAS_MUN)
[1] "gadm_sf"
CAS_MUN$sf
Simple feature collection with 19 features and 6 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.0989 ymin: 4.246699 xmax: -69.84787 ymax: 6.250501
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
First 10 features:
ISO NAME_0 NAME_1 NAME_2 TYPE_2 ENGTYPE_2 geometry
14752 COL Colombia Casanare Aguazul Municipio Municipality MULTIPOLYGON (((-72.5075 4....
14757 COL Colombia Casanare Chámeza Municipio Municipality MULTIPOLYGON (((-72.7872 5....
14472 COL Colombia Casanare Hato Corozal Municipio Municipality MULTIPOLYGON (((-72.0873 6....
14477 COL Colombia Casanare La Salina Municipio Municipality MULTIPOLYGON (((-72.4195 6....
14835 COL Colombia Casanare Maní Municipio Municipality MULTIPOLYGON (((-72.2622 4....
14849 COL Colombia Casanare Monterrey Municipio Municipality MULTIPOLYGON (((-72.93552 5...
14658 COL Colombia Casanare Nunchía Municipio Municipality MULTIPOLYGON (((-72.0023 5....
14798 COL Colombia Casanare Orocué Municipio Municipality MULTIPOLYGON (((-71.0854 4....
14517 COL Colombia Casanare Paz de Ariporo Municipio Municipality MULTIPOLYGON (((-69.84787 6...
14612 COL Colombia Casanare Pore Municipio Municipality MULTIPOLYGON (((-71.9291 5....
class(CAS_MUN$sf)
[1] "sf" "data.frame"
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.