1

Currently I am working with spatial data points. These data points are defined with (long, lat) coordinates and contain information of plastic concentrations in a water system. Since I am interested in the influence of wind direction on the spatial distribution of the plastics in the water system, I want to create polygons for different (wind) directions (e.g. North, north-east, east, etc). Afterwards I want couple the earlier mentioned data points to the polygons of the wind directions. For the latter part I already have an idea on how to fix it.

My current problem is that I am not sure how to create the spatial polygons for the (wind)directions. For sure it is possible to draw the polygons by hand, but the quality of this is questionable. Is there maybe an easier way to create these polygons>

library("sf")
library("raster")
library("sp")
library("spData")
library("spDataLarge")
library(tmap)    # for static and interactive maps
library(leaflet) # for interactive maps
library(ggplot2) # tidyverse data visualization package
install.packages("rgdal") #importing KML files
library("rgdal")

(rgdal_show_exportToProj4_warnings="none")

library(dplyr)
library(stringr) # for working with strings (pattern matching)
library(tidyr)

#Load data for segments
Meet3 <- read.csv2("Weeklydata/Data Week 1/DataWeek1.csv", header = TRUE)
Lengte <- read.csv2("Weeklydata/Length.csv", header = TRUE)
segmenttest <- st_read("R maps/polygons/PolygonsLeiden.kml")
Meet3$Segments <- c("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","0")
PlasticData =Meet3[c(-30),]


PolOnly <- segmenttest[ ,1,3]
PolOnly$Segments <- c("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")
PolOnly$area  <- st_area(PolOnly) #calculation of area
PolOnly$Length <- c(Lengte$Length)
#Combine data
PlasticMap = left_join(PlasticData, PolOnly)
PlasticMap = st_as_sf(PlasticMap, crs=st_crs(PolOnly))
PlasticMap$width <- c(PlasticMap$area/PlasticMap$Length)
PlasticMap$SegmentWidth <- c(PlasticMap$area/PlasticMap$Length)

#geometry
Plane <- st_centroid(PlasticMap$geometry)
PlasticMap$dir <- Plane

#map with total plastic in points
ap1 = tm_shape(PlasticMap, name = "dir") + tm_dots(size = "total.per.segment", col = blues9)
print(ap1)





Visualization of question

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
  • Hi Jelmer, welcome to Stack Overflow! It will be extremely challenging to answer your question without **1)** the code you've tried thus far and **2)** at least a sample of your data. Indeed, this can be challenging for sp data, but many files are available publicly and thus you could provided a link. See [How to make a great R reproducible example](https://stackoverflow.com/a/5963610/) for more. – Ian Campbell Dec 09 '20 at 18:32
  • @IanCampbell I added my script. My data frame is too big to upload here, but most important fact is that the points are in long-lat format. (I am new with programming in R) – Jelmer Visser Dec 09 '20 at 19:56
  • When you say you want a polygon for wind direction, do you mean an arrow pointing in the direction of the wind bearing [0, 360) or a different shape for each Cardinal and Ordinal direction? If the latter you really don't need a polygon, just drop some text (N, SE, what-have-you) on top of your `Leaflet` using `addLabelOnlyMarkers()`. – J Thompson Dec 09 '20 at 20:09
  • @JThompson I am striving towards different polygons for different (wind) direction on the map. My goal is to investigate whether for example significant more plastic can be found in the east or any other direction. This will be done by extracting the data points per polygons. – Jelmer Visser Dec 09 '20 at 20:17
  • It would be helpful to know what the wind direction data looks like. Is it defined by a (lon, lat) with wind information all in one nice data frame? Its helpful if you can post a few rows of the different data you're working with, doesn't need to be all of it. – J Thompson Dec 09 '20 at 20:25
  • I agree with J Thompson, I think we need to be able to see a few rows of each data source to be able to help. Moreover, if you could take a screenshot of what you have currently along with annotations from mspaint or Preview.app that explains exactly what you hope to accomplish, that would go a long way. – Ian Campbell Dec 09 '20 at 22:18
  • About the wind data: Since the area of interest is small, the wind data is not spatial but a data frame containing wind direction (degrees) and time. It will not be coupled to the spatial data but the average wind direction will be used in order to explain the location of the plastic. Furthermore I added a visualization of what i want to achieve. If necesarry i can try to extract part of the data frame (PlasticMap). – Jelmer Visser Dec 10 '20 at 11:23

0 Answers0