I have a data frame with latitude, longitude and annual consumption data. I am trying to plot the annual consumption data using GeoPandas with a quantile scheme by making a polygon column. I followed the following tutorial.
enter link description here
I used the latitude and longitude data to make polygon shapes using the following code.
full_dataframe["geometry"] = Polygon(list(zip(full_dataframe["long"], full_dataframe["lat"])))
merged2 = GeoDataFrame(full_dataframe)
merged2.plot(column='annual_consume', scheme='quantiles', k=4, edgecolor='k',
cmap='OrRd', legend=True,
legend_kwds={'loc': 'center left', 'bbox_to_anchor':(1,0.5)})
My data frame looks like below
The issue is, when I plot it, it looks like a big mess of interconnecting points. The boundaries are not seperated.
I want a similar boundary separation like the tutorial based on longitude and latitude data.
Related
I am working with a dataset that features chemical analyses from different locations within a cave, with each analysis ordered by a site number and that sites latitude and longitude. This first image is what I had done originally simply using ggplot.
Concentrations mapped by color over map
But what I want to do is use the shapefile of the cave system from which the data is sourced from and do something similar by plotting the points over the system and then coloring them by concentration. This below is the shapefile that I uploaded
Cave system shapefile
So basically I want to be able to map the chemical data from my dataset used to map the first figure, but on the map of the shapefile. Initially it kept on saying that it could not plot on top of it. So I figured I had to convert the latitude and longitude into spatial coordinates that could then be mapped on the shapefile.
Master_Cave_data <- Master_cave_data %>%
st_as_sf(MastMaster_cave_data, agr = "identity", coord = Lat_DD)
This was what I had thought to use in order to convert the numerical Latitude cooridnates into spatial data.
I have a raster r, one polygon shapefile regions and a point shapefile cities. I need to plot all three into one map layout. In addition to this I need to label point file with names of cities (cities$city$Town.Name) and their temperature and precipitation value (assigned as cities$labels). So I have used the following code with packages 'raster' and 'rasterVis'.
p1<-levelplot(regions.r,par.settings=mytheme,scales=list(draw=FALSE),xlab="",ylab="",margin=F)+
layer(sp.polygons(regions))+
layer(sp.points(cities,pch=20,cex=1.5,col="black"))
p1+
layer(sp.text(coordinates(cities), txt = cities$city$Town.Name, pos = 3,col="black",font=list(face="bold"),cex=0.8))+
layer(sp.text(coordinates(cities),txt = cities$label,
pos = 1,cex=0.6,col="black"))#Add shapefile labels
This works fine when area has scattered cities distribution (see figure below).
However, if the cities are concentrated in one part I experience overlap of labels (see figure below). Is there a way to avoid the label overlap?
I have a dataset with dimensions 360x180x720 (lon x lat x time). I would like to change its resolution from 1 deg to 0.25 deg using the disaggregate function that's part of R's raster package. I haven't been able to figure out how to create a raster object from this dataset. I think I need to do something involving stacking the data corresponding to each time step in layers, but I what I've tried so far has been unsuccessful. I apologize if this is a trivial question, but most of the online guidance I've seen has been directed towards data formatted spreadsheet style in (lat, lon) pairs (rather than a gridded dataset).
I appreciate any suggestions!
I have a long list (around 900 thousand) of latitude and longitude (please note that these coordinates vary up to 13th decimal places) with category of crime done in this coordinates.
This is snapshot of data
Problem: I want to plot a heat map irrespective of type of crime done using only latitude and longitude. something like this
This is what I have tried using googleVis
M1 <- gvisMap(df_latlong, "LatLong" , "Category",
options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE,
mapType='hybrid', useMapTypeControl=TRUE,
width=800,height=600))
plot(M1)
But this is something else and it is ignoring most of the data. I have no clue how to do it.
Thanks a lot!
I would like to be able to create an elevation plot from contour lines in R. I am very new to using shape files
At the moment I have downloaded data from here
which provides .shp files for all of the UK.
It also provides the contour lines, summarising the topology of the UK.
For the elevation plot I would like a data.frame or data.table of evenly spaced points (100m apart from each other) to produce a data output giving an x, y and z value. Where x and y represent the latitude and longitude (or Eastings and Northings), and z represent the height (in meters above sea-level).
I think there are probably some tools that will automatically carry out the interpolation for you, but am unsure how it would work with geo-spatial data.
This is my basic start...
require(maptools)
xx <- readShapeSpatial("HP40_line.shp")
Choose "ASCII Grid and GML (Grid)" as download format for the "OS Terrain 50" product, and download the file. This will give you a zip file containing many directories of zip files, each of which contains portions of a 50 m elevation grid of the UK (the portion I looked at had 200 x 200 cells, meaning 10 km x 10 km). I went into the directory data/su, unzipped the zip file there, and did
library(raster)
r = raster("SU99.asc")
plot(r)
to aggregate this to a 100 m grid, I did
r100 = aggregate(r) # default is factor 2: 50 -> 100 m
As mentioned above, the advice is to work on the grids as contour lines are derived from grids, working the other way around is a painful and a great loss of information.
Getting grid values in longitude latitude as a data.frame can be done in two ways:
df = as.data.frame(projectRaster(r, crs = CRS("+proj=longlat")), xy = TRUE)
unprojects the grid to a new grid in longitude / latitude. As these grids cannot coincide, it minimally moves points (see ?projectRaster).
The second option is to convert the grid to points, and unproject these to longitude latitude, by
df2 = as.data.frame(spTransform(as(r, "SpatialPointsDataFrame"), CRS("+proj=longlat")))
This does not move points, and as a consequence does not result in a grid.