Tag Info

Hot answers tagged

5

To read your shapefile, i recommend you to use rgdal package and its readOGR function, or eventually use readShapeLines from maptools package. These packages rely on the sp package as concerning how the geospatial data is structured in R. You can do easily this to convert your shapefile into data.frame (ie extract the attributes of the shapefile) ...


5

I use QGIS 2.2 so what I post may differ in certain areas. You can install the Processing plugin via: Plugins > Manage and Install Plugins... Once installed, you should see the Processing menu in your toolbar. Select Options and Configuration: Select the Providers list, find R scripts, check the Activate box and set the path of the R folders: Next ...


4

This is not an R solution, but Quantum GIS (QGIS) is a great way to achieve what you want. You can simply load the .osm file (Add Vector tool), right-click it in the Table of Contents and Save As ESRI Shapefile. QGIS may crash with such a large extract, so to avoid this you can uses OSM Tools like the OverPass API to download only what you need using ...


4

I think that the script is expecting to read in a set of regularly spaced points, with deviations less than the minimum tolerance. Your set of points is actually quite irregularly spaced: You can see that there are large missing areas. Also, if you zoom in closer, you'll see that even at the fine scale, the points are not regularly spaced on a grid ...


3

You appear to be looking at a suite of software options. A way of doing it in ArcMap model builder using off the shelf tools could be: point to raster (ensure snap to raster environment is set.) Expand (by 1 pixel to create your block of nine) Extract by mask. This method assumes that your points are not so close that their masks overlap. If overlap is ...


3

The problem is that col.regions expects a vector with values or names for colors and you are giving it factors. When you build your dataframe your string vectors are (by default) turned into factors and the levels of the factors are (by default) ordered, in this case alphabetically. This is the reason why the mapping of the colors to the categories is off. ...


3

Here is a suggestion using GridTopology from R. library(sp) library(rgeos) # coordinates of some points x <- c(44, 66, 88, 22, 44, 66, 44, 66) y <- c(64, 64, 64, 48, 48, 48, 32, 32) sp <- SpatialPoints(cbind (x,y)) # dimensions of grid topleftCorner <- bbox(sp)[,1] columns <- length(unique(x)) rows <- length(unique(y)) cellWidth <- 22 ...


2

The problem is that the data was never in UTM to begin with, and so by having a UTM projection, the file was ultimately being told to be something it wasn't. (Such is life) :) Reprojecting it doesn't fix the problem, because the transformation math is based on coordinates that don't match the assigned projection. To fix this I deleted the .prj file, and ...


2

I'd convert the output to a raster object. Then: require(spatstat) require(sp) require(raster) set.seed(1985) x <- runif(20) y <- runif(20) p <- SpatialPoints(coords = matrix(c(x, y), ncol = 2)) plot(p) Then compute densities: pp = ppp(x,y) # all points in a (0,1) default window d <- density.ppp(pp, sigma = 0.1) dp <- density.ppp(pp, sigma ...


2

Try colorkey=list(space="bottom"): f <- system.file("external/test.grd", package="raster") r <- raster(f) levelplot(r, margin=FALSE, colorkey=list(space="bottom"))


2

The above code looks more like you just clone shp into shputm and then assign the output of crs(shp) to shputm without performing an actual reprojection. Anyway, if you import both the shapefile and the NDVI raster, and then reproject shp using spTransform, subsequent data extraction should work out fine. Also, the output of extent(shp_utm) roughly agrees ...


2

In R, you can used the sp package and over function to do this. I adapted an example data set and the solution from this post by Roger Bivand. library(sp) library(rgeos) library(rworldmap) box <- readWKT("POLYGON((-180 90, 180 90, 180 -90, -180 -90, -180 90))") proj4string(box) <- CRS("+proj=cea +datum=WGS84") set.seed(1) pts <- spsample(box, ...


2

They are the values in the file. How they correspond to measurements is unknown, and would have to be specified in external metadata. A GeoTIFF can easily store decimal numbers in bands, and you can get the range simply enough. Here I read in a 3 band raster using stack and check the first band: > dd = stack("d.tif") > range(values(dd)[,1]) [1] ...


2

I've updated the original code given here http://stackoverflow.com/questions/26087772/create-polygon-from-set-of-points-distributed/26089377#26089377 Instead of Bezier-based smoothing, you can used the smoothing suggested here http://gis.stackexchange.com/a/24929/8104 with the function spline.poly (as suggested by @aaron) which gives accurate results.


2

Here is how I would consider doing this if I absolutely had to have every neighborhood value (which is what it sounds like). First create 2 fields for the point geometry (one for x and one for y) and calculate the geometry for the x field and y field. I would be sure my point file was in a projected coordinate system like UTM Meters or State Plane Feet. ...


2

@jazzurro, you perfectly can do this with R, just look up osmar package! Read the osmar documentation (osmar.r-forge.r-project.org/RJpreprint.pdf). At pages 11 pp. you can find a detailed example for extracting roads/highways by the according tags for munich.osm! After pulling and extracting the data from a planet file for Australia you can convert to any ...


2

If the rasters have the same basis (extent, resolution etc) then you just get the values and plot them. Something like: plot(values(r1), values(r2)) I'm not sure exactly what the "correlation of determination" is, but the simple "correlation" can be computed by: cor(values(r1), values(r2)) Note these are both dependent on the rasters having identical ...


2

I am fairly sure that the error is associated with the FUN argument. R is case sensitive and the argument in extract is lowercase "fun". To understand how this works I would break down the components of the analysis rather than letting the extract function do all the heavy lifting. Understanding the specific components, in particular the resulting list ...


2

rasterImage draws a raster image at a given location and size. Below is a very rough example, which you can hopefully adjust to your needs. (I made up some location points, you would obviously have to use yours.) library(rgdal) library(png) # load icons in PNG format iconfile1 <- ...


2

The legend is a summary of the raster values. Therefore, you will need to extract the pertinent raster values. This should do it: library(raster) data(volcano) r = raster(volcano) min = minValue(r) max = maxValue(r) l = c(min:max) result = l[l %% 20 == 0] > result [1] 100 120 140 160 180


1

Use a smaller evaluation, e.g.: bz <- bezier(px, py, evaluation=50) It's because the const <- (1 - z)^(n - 1) part of bezier evaluates to zero near the end of the evaluation points. It doesn't look like a particularly stable function, but I can't say that I know the Bézier curve algorithms. Consider notifying the maintainer of Hmisc of this ...


1

Possible duplicate with How to open a Shapefile in R? There are many packages to read shapefiles: rgdal with readOGR (examples) and Read and write ESRI Shapefiles with R, pointed out by Joseph maptools with ReadShapePoint, readShapeLines,readShapePoly and readShapeSpatial as Tumbledown show ( and Read and write ESRI Shapefiles with R) PBSmapping with ...


1

readShapeSpatial in the maptools package is my go-to function: library("maptools") readShapeSpatial("c:\\Temp\\My_Shapefile.shp") Nice tutorial here: http://www.kevjohnson.org/making-maps-in-r/


1

R projects sp objects using proj4 strings. After some googleing, I got the impression that interrupted projections are not easily accomplished via proj4 arguments. Sounds like the mapproj package doesn't support interrupted projections either. I bet there is a solution, but probably not an easy one (e.g. check out this R-sig-Geo answer: ...


1

The reprojection might fail for points that are located at the backside of the globe. Best solution is to clip the data to the visible hemisphere. I have given some advice on that here: Where did the polygons go after projecting a map in QGIS? and in the questions in the Linked section of that topic.


1

Please read the sp vignette on spatial classes and methods. vignette(package="sp")[4] vignette("intro_sp") Since there is a slot (@data) that holds a data.frame related to the sp object, no coercion is required. class(foo@data) str(foo@data) ( df <- foo@data ) However, it is good practice to operate directly on the @data slot rather than pulling ...


1

If you would check help for as.im() you would notice that raster data type is not supported. We should thank @mdsumner for bringing up my old question (I do not remember the occasion that forced me to ask it - suppose it was just some testing and I wouldn't recall that question by myself). I used there a geostatsp package that provides needed functionality. ...


1

You can use the raster package and its functionalities regarding netCDF files to address your problem. Make sure the ncdf package is available. # Required packages library(raster) library(ncdf) library(RColorBrewer) You can manually retrieve some information about the netCDF file you are dealing with using open.ncdf(). This step is important for ...


1

To figure out which file has a problematic projection and get additional clues about how to fix it, you can plot the maps on an ArcGIS basemap. This will get the shapefiles to appear on the same screen so you can see which is problematic. In this case you can quickly see that the SourceA file is plotted off in the Atlantic Ocean far from it's proper ...


1

I've analysed the geometry issues in the attached data, and it seems it does not ONLY have orphaned holes but also geometry validity issues. It's true that an orphaned hole is somehow a geometry validity issue, but rgeos does not handle it in the same way, as for orphaned holes, an error is raised, instead of a simple warning. As you indicate, they are hints ...



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