maptools

Merge polygons and plot using spplot()

故事扮演 提交于 2019-12-13 05:25:33
问题 I would like to merge some regions in gadm data and then plot the map. So far I have the following: #install.packages("sp",dependencies=TRUE) #install.packages("RColorBrewer",dependencies=TRUE) #install.packages("maptools",dependencies=TRUE) library(sp) library(maptools) #library(RColorBrewer) # get spatial data con <- url("http://gadm.org/data/rda/CZE_adm2.RData") print(load(con)) close(con) IDs <- gadm$ID_2 IDs[IDs %in% c(11500:11521)] <- "11500" gadm_new <- unionSpatialPolygons(gadm, IDs)

Invalid `.internal.selfref` warning, column not updated working with `SpatialPolygonsDataFrame`

主宰稳场 提交于 2019-12-12 00:31:58
问题 I'm trying to do some geospatial analysis in R which will involve adding attributes to SpatialPolygonsDataFrame s for coloring, etc. during plotting. For organization, I'd like to add these attributes to my SpatialPolygonsDataFrame s through a merge & update, but I keep getting the "Invalid .internal.selfref " warning & the columns won't be added. Poking around the questions and answers here, it seems to be related to the fact that the data for a SpatialPolygonsDataFrame object is stored in a

Drawing thicker state borders and thiner county borders for US map using GADM shapefile

这一生的挚爱 提交于 2019-12-11 14:59:31
问题 I have an earlier post here on drawing US maps using shape file from GADM while at the same time removing color mapping onto the Great Lakes region. The issue was solved following suggestion by @Majid. Now, I further want thicker state boders and thinner county borders. I did so by plotting county-level choropleth map first and then add additional lays of non-filled state/nation-level border: library(sf) library(tidyverse) library(RColorBrewer) #for some nice color palettes # US map

Merging Polygons in Shape Files with Common Tag IDs: unionSpatialPolygons

我怕爱的太早我们不能终老 提交于 2019-12-08 15:58:19
问题 I am trying to read from a shape file and merge the polygons with a common tag ID. library(rgdal) library(maptools) if (!require(gpclib)) install.packages("gpclib", type="source") gpclibPermit() usa <- readOGR(dsn = "./path_to_data/", layer="the_name_of_shape_file") usaIDs <- usa$segment_ID isTRUE(gpclibPermitStatus()) usaUnion <- unionSpatialPolygons(usa, usaIDs) When I try to plot the merged polygons: for(i in c(1:length(names(usaUnion)))){ print(i) myPol <- usaUnion@polygons[[i]]@Polygons[

Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?

不羁岁月 提交于 2019-12-08 06:40:39
问题 TL;DR What is the best way in R to handle SpatialPolygons intersecting/overlapping the anti meridian at +/-180° of latitude and cut them into two sections along that meridian? Preface This is going to be a long one, but only because I'm going to include a lot of code and figures for illustration. I'll show you what my goal is and how I normally achieve that and then demonstrate how it all breaks together in a literal edge case. As the title suggests, I already found one possible solution to

Downloading png from Shiny (R) pt. 2

你说的曾经没有我的故事 提交于 2019-12-08 05:34:25
问题 This relates to a question I have asked previously at: Downloading png from Shiny (R) I have now created multiple shiny plots and downloaded them, but for a plot using the maptools package, I just get an empty png back. Is this a bug in Shiny or is something wrong with my code here? Here are the relevant excerpts from my server file: plotInput2 <- function(){ my.data<-DataInput() sub <- subset(DataInput(), as.character(DataInput()[,2])==input$var1) a = which(names(sub)==input$var2) x_lab <-

mapping by ggplot2 geom_polygon goes crazy after merging data

自古美人都是妖i 提交于 2019-12-08 02:37:52
问题 I am trying to make a grid containing maps of megaregions in the us. I create a SpatialPolygonDataframe from a shape file. then convert it into a data.frame to use ggplot2. as soon as I add the data into the frame, the polygon plots. the file containing SpatialPolygon and the data frame are here: https://drive.google.com/open?id=1kGPZ3CENJbHva0s558vWU24-erbqWUGo the code is as follow: load("./data.rda") prop.test <- proptest.result[which(proptest.result$variable=="Upward N"),] #transforming

SpatialPolygonDataFrame plotting using ggplot

你。 提交于 2019-12-07 16:15:17
问题 I am having a shape file for the greater London area. I use the readShapePoly function from the maptools package to load it in R as a SpatialPolygonDataFrame . I want to the plot those polygons .. Which I have already done by using the basic of plot function in R. The output looks as shown in this image: Now, I am trying to plot the same shape file using ggplot2 but it doesn't work with me. I am getting some weird lines in the graph as shown blew: The code I used was : london.wards <-

Geographical CRS given to non-conformant data in R

爷,独闯天下 提交于 2019-12-07 14:20:23
问题 sorry for bothering you for this, but it is maybe 5 hours I am getting mad on this issue and I don't manage to sort it out. I have a dataset of about 37,000 entries. Each of them has its own Lon and Lat coordinate values. Checking the overall values, they range respectively as follow: Latitude (-54.4871,70.66344) and Longitude (-177.375, 178.4419). This is absolutely reasonable. I created a shapefile with these 37 thousands points using ArcGIS: everything works fine. I need then to process

Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?

試著忘記壹切 提交于 2019-12-06 14:55:16
TL;DR What is the best way in R to handle SpatialPolygons intersecting/overlapping the anti meridian at +/-180° of latitude and cut them into two sections along that meridian? Preface This is going to be a long one, but only because I'm going to include a lot of code and figures for illustration. I'll show you what my goal is and how I normally achieve that and then demonstrate how it all breaks together in a literal edge case. As the title suggests, I already found one possible solution to my problem, so I'll include that too. But it is not 100% clean and I'd like to see if somebody can come