[R-sig-eco] create point grid within polygon

Mauricio Zambrano-Bigiarini mauricio.zambrano at jrc.ec.europa.eu
Wed Jul 24 09:03:18 CEST 2013


On 07/23/2013 07:29 PM, David García Callejas wrote:
> Hi all,
>
> is it possible to create an object of class
> SpatialPoint/SpatialPointDataFrame, with a given resolution, constrained to
> a certain SpatialPolygon?

Hi David,

Have a look to:

?sp::spsample

--------- START example--------
library(sp)

# irregular polygon
data(meuse.riv)
meuse.sr = SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), "x")))

# points within polygon
mypoints <- spsample(meuse.sr, n = 00, "regular")

class(mypoints)
#"SpatialPoints"


# Plotting
plot(meuse.sr)
points(mypoints, pch = 3)
--------- END example--------

IHTH,

Mauricio Zambrano-Bigiarini, Ph.D

-- 
=================================================
Water Resources Unit
Institute for Environment and Sustainability (IES)
Joint Research Centre (JRC), European Commission
TP 261, Via Enrico Fermi 2749, 21027 Ispra (VA), IT
webinfo    : http://floods.jrc.ec.europa.eu/
=================================================
DISCLAIMER:
"The views expressed are purely those of the writer
and may not in any circumstances be regarded as sta-
ting an official position of the European Commission"
=================================================
"The journey is the reward"  (Steve Jobs)

>
> In QGis, for example, I can create a rectangular layer of points and then
> clip it to the extent of a polygon. The ideal solution in R would be to
> create the point layer directly within the polygon boundaries, to avoid the
> computational cost of clipping it afterwards (I am expecting a very large
> (~10^5) number of points)
>
> Thanks,
>
> David
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



More information about the R-sig-ecology mailing list