Area estimation using image in R - r

So i'm looking for a way to estimate the area of a region, using only the image of the map. The reason i'm doing this is I want to calculate the area that would be lost upon a certain increase in sea level and I can't find any kind of meta data for that only the maps (in image formats). Here is the link to such a map:
(source: cresis.ku.edu)
So what i have in mind is to convert this image to a gray scale image using EBimage package and then using the pixel intensity as a criteria to count the number of pixels that represent potentially threaten area.
My question is it possible? How can we you the pixel intensity as a criteria? And if there are any other approach to solve this issue?
Also if there are way to gain access to the meta data used to plot such map that I'm not aware of please tell me.
Thank you everyone.
Edit:
Thank to hrbrmstr I was able to read the grid data int R using rgdal packages. So in order to calculate the area I tried to used the rgeos package, but the dataset from CRESIS doesn't have the shape file. So how can we define the polygon and calculate the area?
Sorry if this question seems silly. This is the first time I've ever dealt with spatial data and analysis

The data is in the ESRI files:
library(rgdal)
grid_file_1m <- new("GDALReadOnlyDataset", "/full/path/to/inund1/w001001.adf")
grid_1m <- asSGDF_GROD(grid_file_1m, output.dim=c(1000, 1000))
plot(grid_1m, bg="black")
grid_1m_df <- as.data.frame(grid_1m)
str(grid_1m_df)
## 'data.frame': 2081 obs. of 3 variables:
## $ band1: int 1 1 1 1 1 1 1 1 1 1 ...
## $ x : num -77.2 -76.9 -76.5 -76.1 -75.8 ...
## $ y : num 83.1 83.1 83.1 83.1 83.1 ...

Related

Map with GEOID in R

I have a small file with GEOIDs. (Not lat/long.) I produced this file myself. I have a hard time figuring out how I can plot this. My file has GEOIDs and a column I want to plot in R (called "y" in example below). The data looks something like this;
GEOID
y
36061015700
0.598
36061014900
0.522
36061013900
0.370
36061013300
0.407
Etc. I estimated this model in Manhattan only. (y represents Census tract cummulative log real estate returns between 2006 -- 2019 in case you are interested.) I want to plot the returns, where a darker colour would represent a higher value and vice verse.
Looking around the web, almost all explanations are with existing data, not with your own data. The current format is a data.frame, which I understand is already an issue. Is there no simple package that can plot this? Bonus points if it doesn't involve tidyverse.
Kind regards,
Alex

How to set the factor in disaggregate function

I have a question regarding the aggregation of rasters/pixels.
I have a rasterstack with spatial resolution of 25km x 25km and I want to change it to 500m x 500m and preserve its values.
I believe that I must use the disaggregate function but I do not understand from the help page how to set the factor.
You want to go from 25 km to 500 m resolution. In that case, the factor is 25000 / 500 = 50
If you want to change the resolution with a factor that is not an integer, you can use resample instead.

Find centre location coordinates in R - geospatial analysis

I am trying to find the centre coordinates of high-density areas in R.
The dataset I have has about 1.5million rows and looks like this (dummy data)
LATITUDE LONGITUDE val
1 35.83111 -90.64639 359.1
2 42.40630 -90.31810 74.5
3 40.07806 -83.07806 115.4
4 40.53210 -90.14730 112.0
5 42.76310 -84.76220 118.4
6 39.29750 -87.97460 134.4 ...
...
After plotting it using ggmap and ggplot using the command
ggmap(UK_Map) +
geom_density2d(data=processedSubsetData,aes(x=processedSubsetData$Longitude,y=processedSubsetData$Latitude), bins=5) +
stat_density2d(data=processedSubsetData,aes(x=processedSubsetData$Longitude,y=processedSubsetData$Latitude,fill=..level.., alpha=..level..), geom='polygon')
I have the visualization which looks like below image.
As you can see from the image, there some high-density areas. I need to find the local centre coordinates of these high-density areas in the map.
I have tried calculating distance between the points and also rounding the coordinates to group them. But I am not able to make it work and is stuck.
Thanks

Plotting of coordinates in R

I have a number of coordinates and I want to plot them in a gridded interface by using R.
The problem is that the relative distance between observations is large. Coordinates are in a geographic coordinate system and the study area is Switzerland. Moreover, id of the points is required to be plotted.
The problem is that two clusters of the points are dense and some other points are separated with a large distance. How I can plot them in a proper way to have readable presentation? Any suggestion for plotting the data?
Preferably, do not use ggplot as I used it before and it did not present proper results.
Data:
id x y
2 7.1735 45.86880001
3 7.17254 45.86887001
4 7.171636 45.86923601
5 7.18018 45.87158001
6 7.17807 45.87014001
7 7.177229 45.86923001
8 7.17524 45.86808001
9 7.181409 45.87177001
10 7.179299 45.87020001
11 7.178359 45.87070001
12 7.175189 45.86974001
13 7.179379 45.87081001
14 7.175509 45.86932001
15 7.176839 45.86939001
17 7.18099 45.87262001
18 7.18015 45.87248001
19 7.18122 45.87355001
20 7.17491 45.86922001
25 7.15497 45.87058001
28 7.153399 45.86954001
29 7.152649 45.86992001
31 7.154419 45.87004001
32 7.156099 45.86983001
GSBi_1 7.184 45.896
GSBi__1 7.36 45.901
GSBj__1 7.268 45.961
GSBj_1 7.276 45.836
GSB 7.272 45.899
GSB_r 7.166667 45.866667
Location of points:
As you can see in the plot, the points' ids are not readable both for the dense parts and others.
Practically, it is not always possible to ensure that all points are visually separable on the screen when plotting a set of points that contains very close and very far points at the same time.
Think of a 1000x800 pixel screen. Let's say we have three points A, B and C that are located respectively on the same horizontal line such that: the distance between A and B is 1 unit and the distance between A and C is 4000 unit.
If you map this maximum distance (4000 unit) to the width of the screen (1000px). Then a pixel will correspond to 4 units in horizontal. That means A and B will fit into one pixel since the distance between them is only 1 unit. So, they will not be visually separable on the screen.
Your points are far too close to really do too much with, but an idea might be spread.labels from plotrix:
opar <- par()
par(xpd=TRUE)
plot(dat$x, dat$y)
spread.labels(dat$x,dat$y,dat$id)
par(opar)
You may want to consider omitting all the numerical labels and placing them in a different graph.

convert loess to spatial data

I am completely at loss on how to convert from atomic vectors, lists, etc. to spatial data.
I want to work with data in polygons on a map (nxm matrix). Specifically the output from functions such as loess and akima. For example from loess I get:
List of 3
$ x: num [1:112] 656977 657024 657071 657118 657165 ...
$ y: num [1:82] 661500 661544 661587 661631 661675 ...
$ z: num [1:112, 1:82] -725 -724 -720 -715 -707 ...
where x and y a State Plane Coordinates, and z is a combination of land surface and bathymetry elevations. The bathymetry is inside a polygon and some of the loess results spill outside of the polygon onto the matrix. I want to zero out everything out side of the polygon. I believe I can do that with over, but the data needs to be a spatial coordinates.
How do I do that? I have been searching and trying things out for weeks.
Thanks in advance...
It's a pretty broad question so here are hints and pointers rather than specifics.
R has many types of spatial classes, but things over the past few years have converged to the Spatial___DataFrame classes of library sp.
The Bivand Applied Spatial Analysis with R book has a detailed set of examples and examination of the internals, including how to create them and how to convert between various spatial classes.
There's also a Spatial vignette to help gt you started.
Assuming you could do a traditional loess with a single predictor and plot it...
A two way interaction can be thought of as occurring on a two dimensional plane. Therefore, simply providing x and y as interaction terms you should be able to plot your loess function using some three dimensional system, even if it is just as the predicted z-values being levels in a heat plot.

Resources