README.md

floodshp

The goal of floodshp is to enable reading flood risk from ESRI Shapefile by geocoordinates and visualize flood risk in a given area & exact point.

It can be found very useful i.e. in insurance industry, where flood risk data often takes the form of a shapefile.

Shapefiles containing flood risk sometimes can weigh even a few Gb! Searching a single geographical point can take lots of time & memory.

The main advantage of using floodshp package is short time of reading data from shapefile. The solution used to reach that goal is based on division of the main shapefile containing flood risk into N smaller parts using the second shapefile containing i.e. borough borders of city.

In comparsion to the reading risk of geo point over whole shapefile, method with division can be even 30 times faster! (Time difference of 0.9326711 secs vs Time difference of 0.03687096 secs)

Installation

You can install the released version of floodshp from my github repo github with:

devtools::install_github()

Example of using floodshp package:

This is a basic example which shows you how to solve a common problem:

library(floodshp)

## Loading two shapefiles (with flood risk data & with administrative boundaries)
shapefile <- loadPrepareShpFile("path/to/shapefile.shp")
shapefile_bounds <- loadPrepareShpFile("path/to/shapefile_bounds.shp")

## You can load sample data for flood risk in London by below lines:
# load("~/floodshp/data/shapefile.rda")
# load("~/floodshp/data/shapefile_bounds.rda")

## Check the Attribute data of shapefile_bounds object and find out, which column name provides names of i.e. boroughs
View(head(shapefile_bounds@data))
## The name of proper column should be a region_col_name argument in other functions

## Generate the list of SpatialPolygonsDataFrames, which will be used to read the flood risk
shapefile_divided <- divideNChunks(shapefile = shapefile, shapefile_bounds = shapefile_bounds, region_col_name = "NAME")

## Check the Attribute data of shapefile object and find out, which column name provides values of flood risk
View(head(shapefile@data))
## The name of proper column should be a risk_col_name argument in generateFloodRiskMap function

## Generate interactive map with risk for geograpical point
flood_risk_map <- generateFloodRiskMap(long = -0.08189974, lat = 51.31244, region_col_name = "NAME",
                                         risk_col_name = "PROJ_4BAND",
                                         shapefile = shapefile,
                                         shapefile_divided = shapefile_divided,
                                         shapefile_bounds = shapefile_bounds)

Function generateFloodRiskMap provides a nice, interactive leaflet map showing the flood risk both for shapefile and for particular geographical point:



mur4mat/floodshp documentation built on Dec. 16, 2019, 12:37 a.m.