19

If you do not need to merge topology, but just add new polygons, you can simply use: ab <- rbind(a,b) If you get a "non-unique Polygons ID slot values" error it means that the rownames of the objects are the same. To fix this you can use spChFIDs to change the rownames and associated slot relationships. Since the slots in the object use the rownames to ...


19

Super easy solution provided by @mdsumner: library(sp) library(raster) library(rgeos) library(spatstat) library(rgdal) library(maptools) setwd("C:/...") a<-readOGR(dsn=getwd(), layer="pol.a") b<- readOGR(dsn=getwd(), layer="pol.b") # use union in {raster} package ?raster::union ab<-union(a, b) resulted in : class(ab) [1] "...


9

Robin Lovelace has provided a nice little function to download a ggmap object and convert it to a raster. Using this you could do: library(ggmap) library(raster) library(rgdal) # courtesy R Lovelace ggmap_rast <- function(map){ map_bbox <- attr(map, 'bb') .extent <- extent(as.numeric(map_bbox[c(2,4,1,3)])) my_map <- raster(.extent, nrow= ...


5

This can be done using QGIS tools that you can enable programmatically. That is, there is no need to reinvent the wheel. Namely, you need to: Click on the Enable Topological Editing button in the Snapping toolbar. Start the edit session on both your point and line layers. Click on Vertex Tool (All layers). This enables a tool that you can use to move a ...


5

The warning message is quite clear here: 1: In RGEOSDistanceFunc(spgeom1, spgeom2, byid, "rgeos_distance") : Spatial object 1 is not projected; GEOS expects planar coordinates It requires planar (Cartesian) coordinates, i.e. in meters, miles, etc. You however use polar reference system (WGS-1984). You should re-project your SpatialPointDataFrame to a ...


5

Looks like maptools:::getMidpoint, which underpins maptools::SpatialLinesMidPoints, can be applied to a LINESTRING geometry set without too much modification, e.g. st_line_midpoints <- function(sf_lines = NULL) { g <- st_geometry(sf_lines) g_mids <- lapply(g, function(x) { coords <- as.matrix(x) # this is just a copypaste of View(...


5

Use the rgdal package. If the shapefiles have a projection defined rgdal::readOGR() is recommended. This package provides bindings to the GDAL library (Geospatial Data Abstraction Library) and access to projection/transformation operations from the PROJ.4 library. This supersedes the shapefile read/write functionality in maptools.


4

Without your original data, I can't be sure this will work, but I thought it might help you out. I didn't bring it all the way there, this solution still likely needs some level of automation, but might give you a general way forward First, I create some spatial polygons polypoints1 <- matrix(c(1,2,2,1,1,2,2,1,1,2),ncol=2) polypoints2 <- matrix(c(1,3,...


4

Load libraries and example data # Load libraries library('raster') library('geosphere') library('mapview') # incredible interactive map visualization in R # Get SpatialPolygonsDataFrame object example polygons <- getData('GADM', country = 'URY', level = 1) Plot example data # Plot Polygons mapview(polygons) # Get polygons centroids centroids <- as....


3

One issue with trying to get the name of the tool is that not all tools have a name to begin with. For example, when using the Select Feature(s) tool, it's tool name is: iface.mapCanvas().mapTool().toolName() >>> u'Select features' But when using the Select Features by Polygon: iface.mapCanvas().mapTool().toolName() >>> u'' Some tools ...


3

It's difficult to tell exactly without the full code, but I noticed you're calling self.selectionList_dlg.show() I suspect this should be self.selectionList_dlg.exec_() As exec_ will wait till the dialog is closed, but show will not.


3

E.g. with gUnaryUnion from the rgeos package: library("rgeos") plot(gUnaryUnion(xx), col = "red", axes = TRUE) plot(gUnaryUnion(xx[c(9, 31, 82), ]), col = "blue", add = TRUE)


3

Sounds like cleaning the geometry up will get you on the road to your non-raster solution ... herewith something of a kludge which does help with fixing bad geometry: # Load the library and problematic data library(rgeos) load("oneImage2_spdf.Rdata") >gIsValid(polysData, reason = T) Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, "...


3

Provided I understood your question correctly, here is a suggestion. I made up some data for population, so if those are different for you the aggregate function call might need to be adapted. library(rgdal) library(sp) # shapefile tmpdir <- tempdir() download.file("http://www.abs.gov.au/ausstats/subscriber.nsf/log?openagent&...


2

Your code has too many brackets for one thing. I count three ( and two ). Fix that, and using file.choose() should work if the user chooses the .shp file. Note that: file.choose() only produces a dialog on Windows (I think) - on Linux its a text prompt. I don't know if it works in RStudio... The maptools functions readShape* usually fail to read ...


2

Convert your map to a SpatialPolygons object and then use gIntersection from the rgeos package. This clips your blue polygons exactly to the state boundaries. Inspired by this answer. library(rgeos) library(maps) library(maptools) mmap <- map('state', regions=c('maryland', 'virginia', 'delaware'), fill=TRUE) IDs <- sapply(strsplit(mmap$names, ":"), ...


2

Per @Jeffrey Evans advice, should set your working directory and then use proper relative path to your shapefile. Like: setwd("C:/Users/R") library(maptools) mn.map.shp = readShapeSpatial("./folder1/folder2/minnesota.shp") However readOGR is always prefered than maptools because the maptools functions neither read nor write projection information: library(...


2

The NA-values are present in your quadrature scheme due the way you are defining your observation window (owin). The owin for your events (X) was defined as the whole extent of the raster. Remember that any raster, by default is a structure or matrix of NxN rows and columns. In your example, the cells with population density had a value ranging from 0 to 41, ...


2

Sample code. Given a world map (e.g. lat: 80 ~ -80, lon: -160 ~ 160) was downloaded as PNG ("Downloaded_Image.png"). library(png) Downloaded_Image <- readPNG("Downloaded_Image.png") library(ggplot2) ggplot(data= data, aes(x= lon, y= lat)) + annotation_raster(Downloaded_Image, xmin= -160, xmax= 160, ymin= 80, ymax= -80, ...


2

Applying a buffer with width=0 can be risky for some polygons, e.g. cases of bowtie polygons, altering a lot source geometries. You can try to use the cleangeo package which aims to fix spatial objects. You can install it from Github or from CRAN. You can use this simple code to correct your spatial object: library(cleangeo) polysData.clean <- ...


1

You've done this: breaks <- classIntervals(EU_NUTS@data$X2012._Y20.64_T, n = 5, style = "fisher", unique = TRUE)$brks which is trying to get a column called "X2012._Y20.64_T". Does that exist? > "X2012._Y20.64_T" %in% names(EU_NUTS) [1] FALSE No. There's something similar: > "X2012_Y20.64_T" %in% names(EU_NUTS) [1] TRUE You've put an ...


1

The best explanation I could suggest looking into is similar to this response I found in a different forum, Warning message: points were rejected as lying outside the specified window. These points are rejected because they lie outside the window that you have specified. If you want them not to be deemed "rejects" you have change your window. Or ...


1

i have found a solution in my application i have a raster, and i want to pan the raster here is the code i have void CMyQgsMapCanvas::mousePressEvent(QMouseEvent* pevent) { mMouseEvent = new QMouseEvent(pevent->type() , pevent->pos(), pevent->globalPos(), pevent->button(),pevent->buttons(), pevent->modifiers() ); mClickTimer....


1

Everything should be ordered so, it is probably as simple as coercing back to a SpatialPolygonsDataFrame object. Say y is the original data and x is the new SpatialPolygons object you could try: new <- SpatialPolygonsDataFrame(x, y@data)


1

Here is a short example. I assume that by overlay you are looking for intersects; namely to dissolve all polygons that intersect from both layers. library(sp) library(rgeos) # Create a dataset poly <- SpatialPolygons(list( Polygons(list(Polygon(coords = matrix(c(1, 1, 4, 3, 4, 2, 1, 1), ncol = 2, byrow = TRUE))), ID = "1"), Polygons(list(Polygon(...


1

library(sp) data(meuse) plot(meuse) slotNames(meuse) #".Data" "names" "row.names" ".S3Class" coordinates(meuse) <- ~x+y #Add "ID" column to "meuse" slotNames(meuse) #[1] "data" "coords.nrs" "coords" "bbox" "proj4string" class(meuse) #[1] "SpatialPointsDataFrame" names(meuse@data) #[1] "cadmium" "copper" "lead" "zinc" "...


1

Use the function nowrapSpatialPolygons at the anti-meridian of your central longitude. This doesn't work with wrld_simpl from maptools, but it does work with countriesLow from rworldmap. library(rworldmap) data(countriesLow) library(maptools) prj <- "+proj=robin +lon_0=-198 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs" x0 <- ...


1

I have been able to replicate your problem using the provided shapefile (original). I've opened original.shp in R using both maptools and rgdal and have successfully plotted it. I've also been able to open this unedited file in QGIS 2.8 and ArcMap 10.1. In all cases the Japanese characters in the attribute table displayed correctly. However, when I edited ...


Only top voted, non community-wiki answers of a minimum length are eligible