  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # How to generate spatial points with a pattern  » r » How to generate spatial points with a pattern

By : Malcolm Tompson
Date : November 22 2020, 09:00 AM
may help you . I only know how to do this using the spatstat package. With the function rpoint You can use any function of the coordinates x,y to define your uneven density of points. Here I define the function to have the value 0 at the West end of the region and grow linearly with slope 100 towards the East: code :
``````library(maptools)
library(spatstat)
nc <- as.owin(nc)
west0 <- nc\$xrange
f <- function(x, y, ...){ 100 * (x - west0) }
pts <- rpoint(1000, f, win = nc)
plot(pts)
`````` ## How to create cohesive Spatial Pixels from Spatial Points Dataset

By : Kyro
Date : March 29 2020, 07:55 AM
To fix this issue If you have a polygon that defines the boundary of your region of interest, (which you should), then it is straight forward. One approach is to use the polygrid function from geoR, which itself is just a wrapper for SpatialPoints, expand.grid and overlay
Lets assume that you have a polygon that defines your region of interest called called ROI
code :
`````` data(meuse.grid)
coordinates(meuse.grid) = ~x+y
x <- chull(meuse.grid@coords)
borders <- meuse.grid@coords[c(x,x),]

ROI <- SpatialPolygons(list(Polygons(list(Polygon(borders)), ID = 'border')))
``````
``````# get the bounding box for ROI an convert to a list
bboxROI <- apply(bbox(ROI), 1, as.list)
# create a sequence from min(x) to max(x) in each dimension
seqs <- lapply(bboxROI, function(x) seq(x\$min, x\$max, by= 10))

# rename to xgrid and ygrid
names(seqs) <- c('xgrid','ygrid')

thegrid <- do.call(polygrid,c(seqs, borders = list(ROI@polygons[]@Polygons[]@coords)))
`````` ## Analyze data for spatial join (points to grid) and generate new dataset in R

By : user2467009
Date : March 29 2020, 07:55 AM
it helps some times You can use the over(...) function in package sp for this. You don't need package raster at all, as far as I can see.
code :
``````require(sp)

frame  <- data.frame(x = c(7.5, 8.2, 8.3), y = c(1,4,4.5), z = c(10,15,30))
points <- SpatialPoints(frame)
proj4string(points) <-  CRS("+proj=longlat")

grid  <- GridTopology(cellcentre.offset= c(0,0), cellsize = c(2,2), cells.dim = c(5,5))
sg    <- SpatialGrid(grid)
poly  <- as.SpatialPolygons.GridTopology(grid)
proj4string(poly) <-  CRS("+proj=longlat")

# identify grids...
result <- data.frame(frame,grid=over(points,poly))
# calculate means...
result <- merge(result,aggregate(z~grid,result,mean),by="grid")
# rename and reorder columns to make it look like your result
colnames(result) <- c("grid","x","y","z","grid_mean")
result <- result[,c(2,3,4,1,5)]
result
#     x   y  z grid grid_mean
# 1 8.2 4.0 15   15      22.5
# 2 8.3 4.5 30   15      22.5
# 3 7.5 1.0 10   25      10.0
`````` ## Generate coordinate points with circle pattern points in Octave

By : Irfan Qureshi
Date : March 29 2020, 07:55 AM
this will help As suggested by Luis Mendo, you can use the typical rand function of matlab to generate random points in polar coordinates as follows:
code :
``````figure
hold on

red = sampleCircle([1.4 1.6], 300);
plot(red(:, 1), red(:, 2), 'r*');

blue = sampleCircle([0 0.5], 300);
plot(blue(:, 1), blue(:, 2), 'b*');

function X = sampleCircle(rangeR, n)
r = rand(n, 1) * diff(rangeR) + rangeR(1);
theta = rand(n, 1) * 2*pi;

X = r .* [cos(theta) sin(theta)];
end
`````` ## Appending Spatial Points Attributes to Spatial Lines Data Frame by Line ID

By : user3185026
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I think I cracked it. The key is to use sp::merge to ensure that attributes get written back to points. Then invoke the @data element. then it is just like a regular merge.
code :
``````Points<-snapPointsToLines(Clipped_Points, Clipped_Street, maxDist=0.1, withAttrs = TRUE, idField="identifier")

Points_agg<-Points@data %>% group_by( nearest_line_id) %>% tally()

Clipped_Street@data<-sp::merge(Clipped_Street@data,Points_agg,by.x="identifier",by.y="nearest_line_id", all.x=TRUE )
`````` ## In R, how to average spatial points data over spatial grid squares

By : Ilya Koks
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Your description is vague at best. Please try to ask more specific answers preferably, with code illustrating what you have already tried. Averaging a single value in your point data or a single raster cell makes absolutely no sense.
The best guess at an answer I can provide is to use raster extract() to assign the raster values to a sp point object and then use tapply() to aggregate the values to your grouping values in the points. You can use the coordinates of the points to identify cell location or alternately, the cellnumbers returned from extract (per below example). 