Applied open source GIS
2019-05-14
Chapter 1 Prerequisites
library(giscourse)
conn<-connect()
## Loading required package: DBI
## Loading required package: sp
## Checking rgeos availability: TRUE
## Linking to GEOS 3.5.1, GDAL 2.1.2, PROJ 4.9.3
## Loading required package: leaflet
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
##
## intersect, select, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#dbListFields(conn,"nat_earth_countries_hi")
query1<-"select * from nat_earth_countries_hi where name ilike '%roatia%'"
query2<-"select * from fires"
query<-sprintf("select f.* from (%s) c, (%s) f where st_intersects(f.geom,c.geometry)",query1,query2)
query
## [1] "select f.* from (select * from nat_earth_countries_hi where name ilike '%roatia%') c, (select * from fires) f where st_intersects(f.geom,c.geometry)"
st_read(conn,query=query) -> croatia_fires
query1<-"select * from nat_earth_countries_hi where name ilike '%united%ingdom%'"
query2<-"select * from fires"
query<-sprintf("select f.* from (%s) c, (%s) f where st_intersects(f.geom,c.geometry)",query1,query2)
query
## [1] "select f.* from (select * from nat_earth_countries_hi where name ilike '%united%ingdom%') c, (select * from fires) f where st_intersects(f.geom,c.geometry)"
st_read(conn,query=query) -> uk_fires
mapview(uk_fires)