# idw360: Inverse Distance Weighting with Directional Data In aire.zmvm: Download Mexico City Pollution, Wind, and Temperature Data

## Description

Function for inverse distance weighted interpolation with directional data. Useful for when you are working with data whose unit of measurement is degrees (i.e. the average of 35 degrees and 355 degrees should be 15 degrees). It works by finding the shortest distance between two degree marks on a circle.

## Usage

 `1` ```idw360(values, coords, grid, idp = 2) ```

## Arguments

 `values` the dependent variable `coords` the spatial data locations where the values were measured. First column x/longitude, second y/latitude `grid` data frame or Spatial object with the locations to predict. First column x/longitude, second y/latitude `idp` The inverse distance weighting power

## Value

data.frame with the interpolated values for each of the grid points

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53``` ```library("sp") library("ggplot2") ## Could be wind direction values in degrees values <- c(55, 355) ## Location of sensors. First column x/longitud, second y/latitude locations <- data.frame(lon = c(1, 2), lat = c(1, 2)) coordinates(locations) <- ~lon+lat ## The grid for which to extrapolate values grid <- data.frame(lon = c(1, 2, 1, 2), lat = c(1, 2, 2, 1)) coordinates(grid) <- ~lon+lat ## Perform the inverse distance weighted interpolation res <- idw360(values, locations, grid) head(res) ## Not run: df <- cbind(res, as.data.frame(grid)) ## The wind direction compass starts where the 90 degree mark is located ggplot(df, aes(lon, lat)) + geom_point() + geom_spoke(aes(angle = ((90 - pred) %% 360) * pi / 180), radius = 1, arrow=arrow(length = unit(0.2, "npc"))) library("mapproj") ## Random values in each of the measuring stations locations <- stations[, c("lon", "lat")] coordinates(locations) <- ~lon+lat crs_string <- "+proj=longlat +ellps=WGS84 +no_defs +towgs84=0,0,0" proj4string(locations) <- CRS(crs_string) values <- runif(length(locations), 0, 360) pixels <- 10 grid <- expand.grid(lon = seq((min(coordinates(locations)[, 1]) - .1), (max(coordinates(locations)[, 1]) + .1), length.out = pixels), lat = seq((min(coordinates(locations)[, 2]) - .1), (max(coordinates(locations)[, 2]) + .1), length.out = pixels)) grid <- SpatialPoints(grid) proj4string(grid) <- CRS(crs_string) ## bind the extrapolated values for plotting df <- cbind(idw360(values, locations, grid), as.data.frame(grid)) ggplot(df, aes(lon, lat)) + geom_point(size = .1) + geom_spoke(aes(angle = ((90 - pred) %% 360) * pi / 180), radius = .07, arrow=arrow(length = unit(0.2,"cm"))) + coord_map() ## End(Not run) ```

### Example output  ```  pred
1   55
2  355
3   25
4   25
Loading required package: maps
Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded datum Unknown based on WGS84 ellipsoid in CRS definition
Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded datum Unknown based on WGS84 ellipsoid in CRS definition
```

aire.zmvm documentation built on May 2, 2019, 2:07 a.m.