Rasterize point process using specific rule

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Rasterize point process using specific rule

R-sig-geo mailing list
Dear members,

I've like to create a raster using my event coordinates and information
about the size in this coordinates as a rule for my raster creation.
First, I make:

library(raster)
library(spatstat)

#Points coordinates in UTM
xp<-c(371278.588,371250.722,371272.618,371328.421,371349.974,
371311.95,371296.265,371406.46,371411.551,371329.041,371338.081,
371334.182,371333.756,371299.818,371254.374,371193.673,371172.836,
371173.803,371153.73,371165.051,371140.417,371168.279,371166.367,
371180.575,371132.664,371129.791,371232.919,371208.502,371289.462,
371207.595,371219.008,371139.921,371133.215,371061.467,371053.69,
371099.897,371108.782,371112.52,371114.241,371176.236,371159.185,
371159.291,371158.552,370978.252,371120.03,371116.993)

yp<-c(8246507.94,8246493.176,8246465.974,8246464.413,8246403.465,
8246386.098,8246432.144,8246394.827,8246366.201,8246337.626,
8246311.125,8246300.039,8246299.594,8246298.072,8246379.351,
8246431.998,8246423.913,8246423.476,8246431.658,8246418.226,
8246400.161,8246396.891,8246394.225,8246400.391,8246370.244,
8246367.019,8246311.075,8246255.174,8246255.085,8246226.514,
8246215.847,8246337.316,8246330.197,8246311.197,8246304.183,
8246239.282,8246239.887,8246241.678,8246240.361,8246167.364,
8246171.581,8246171.803,8246169.807,8246293.57,8246183.194,8246189.926)

#Now I have the size of each nest in meters (marked process)

area<-c(117,30,4,341,15,160,35,280,108,168,63,143,2,48,182,42,
88,56,27,156,288,45,49,234,72,270,91,40,304,56,35,4,56.7,9,4.6,
105,133,135,23.92,190,12.9,15.2,192.78,104,255,24)

# Make a contour for the window creation
W <- convexhull.xy(xp,yp)

#Create ppm object
syn.ppp <- ppp(x=xp,y=yp,window=W, marks=area)

# Plot the point process
plot(syn.ppp)

#Definition of raster resolution - 1 meter square
ext <- as(extent(c(W$xrange,W$yrange)), "SpatialPolygons")
syn.ras.res<-rasterToPoints(raster(ext, resolution = 1), spatial = TRUE)

#Now Rasterize
syn.ras<- rasterize(syn.ras.res@coords, raster(syn.ras.res), *?????*)

I' ve like to create some kind of rule in *?????*, where pixel values in
my final raster was 1 when inside de area (marks=area) and zero for
outside de circular area given by points coordinates
(syn.ras.res@coords) using 1 meter as resolution?

Any ideas, please

Thanks,

--
======================================================================
Alexandre dos Santos
Prote??o Florestal
IFMT - Instituto Federal de Educa??o, Ci?ncia e Tecnologia de Mato Grosso
Campus C?ceres
Caixa Postal 244
Avenida dos Ramires, s/n
Bairro: Distrito Industrial
C?ceres - MT                      CEP: 78.200-000
Fone: (+55) 65 99686-6970 (VIVO) (+55) 65 3221-2674 (FIXO)

         [hidden email]
Lattes: http://lattes.cnpq.br/1360403201088680
OrcID: orcid.org/0000-0001-8232-6722
Researchgate: www.researchgate.net/profile/Alexandre_Santos10
LinkedIn: br.linkedin.com/in/alexandre-dos-santos-87961635
Mendeley:www.mendeley.com/profiles/alexandre-dos-santos6/
======================================================================


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Rasterize point process using specific rule

Bede-Fazekas Ákos
Dear Alexandre,
I'm not familiar with point processes, but as far as I understand the
task well, it can be easily solved using sp+raster or sf+raster.

library(sf)
library(raster)
points_sf <- st_as_sf(data.frame(xp, yp, area), coords = c("xp", "yp"),
crs = 32629)
circles_sf <- st_buffer(x = points, dist = sqrt(points_sf$area / pi)) #
if it is really the area, or dist = points_sf$area if it is the radius
empty_raster <- raster(points_sf, resolution = 1)
filled_raster <- rasterize(x = circles_sf, y = empty_raster, field = 1,
fun = function(x, na.rm) 1, background = 0)
plot(filled_raster)

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences


2019.08.20. 15:12 keltezéssel, ASANTOS via R-sig-Geo írta:

> Dear members,
>
> I've like to create a raster using my event coordinates and information
> about the size in this coordinates as a rule for my raster creation.
> First, I make:
>
> library(raster)
> library(spatstat)
>
> #Points coordinates in UTM
> xp<-c(371278.588,371250.722,371272.618,371328.421,371349.974,
> 371311.95,371296.265,371406.46,371411.551,371329.041,371338.081,
> 371334.182,371333.756,371299.818,371254.374,371193.673,371172.836,
> 371173.803,371153.73,371165.051,371140.417,371168.279,371166.367,
> 371180.575,371132.664,371129.791,371232.919,371208.502,371289.462,
> 371207.595,371219.008,371139.921,371133.215,371061.467,371053.69,
> 371099.897,371108.782,371112.52,371114.241,371176.236,371159.185,
> 371159.291,371158.552,370978.252,371120.03,371116.993)
>
> yp<-c(8246507.94,8246493.176,8246465.974,8246464.413,8246403.465,
> 8246386.098,8246432.144,8246394.827,8246366.201,8246337.626,
> 8246311.125,8246300.039,8246299.594,8246298.072,8246379.351,
> 8246431.998,8246423.913,8246423.476,8246431.658,8246418.226,
> 8246400.161,8246396.891,8246394.225,8246400.391,8246370.244,
> 8246367.019,8246311.075,8246255.174,8246255.085,8246226.514,
> 8246215.847,8246337.316,8246330.197,8246311.197,8246304.183,
> 8246239.282,8246239.887,8246241.678,8246240.361,8246167.364,
> 8246171.581,8246171.803,8246169.807,8246293.57,8246183.194,8246189.926)
>
> #Now I have the size of each nest in meters (marked process)
>
> area<-c(117,30,4,341,15,160,35,280,108,168,63,143,2,48,182,42,
> 88,56,27,156,288,45,49,234,72,270,91,40,304,56,35,4,56.7,9,4.6,
> 105,133,135,23.92,190,12.9,15.2,192.78,104,255,24)
>
> # Make a contour for the window creation
> W <- convexhull.xy(xp,yp)
>
> #Create ppm object
> syn.ppp <- ppp(x=xp,y=yp,window=W, marks=area)
>
> # Plot the point process
> plot(syn.ppp)
>
> #Definition of raster resolution - 1 meter square
> ext <- as(extent(c(W$xrange,W$yrange)), "SpatialPolygons")
> syn.ras.res<-rasterToPoints(raster(ext, resolution = 1), spatial = TRUE)
>
> #Now Rasterize
> syn.ras<- rasterize(syn.ras.res@coords, raster(syn.ras.res), *?????*)
>
> I' ve like to create some kind of rule in *?????*, where pixel values in
> my final raster was 1 when inside de area (marks=area) and zero for
> outside de circular area given by points coordinates
> (syn.ras.res@coords) using 1 meter as resolution?
>
> Any ideas, please
>
> Thanks,
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Rasterize point process using specific rule

Ege Rubak
In reply to this post by R-sig-geo mailing list
If I understand your question correctly you can simply use the spatstat
function `discs()`. Given `syn.ppp` created from your code the call is
something like:

     D <- discs(syn.ppp, radii = marks(syn.ppp)/2, mask = TRUE, eps = 1)

For your dataset this covers almost the entire window if both the
coordinates and the marks are in meters as I assume, but that is up to
you to investigate.

/Ege

On 20/08/2019 15.12, ASANTOS via R-sig-Geo wrote:

> Dear members,
>
> I've like to create a raster using my event coordinates and information
> about the size in this coordinates as a rule for my raster creation.
> First, I make:
>
> library(raster)
> library(spatstat)
>
> #Points coordinates in UTM
> xp<-c(371278.588,371250.722,371272.618,371328.421,371349.974,
> 371311.95,371296.265,371406.46,371411.551,371329.041,371338.081,
> 371334.182,371333.756,371299.818,371254.374,371193.673,371172.836,
> 371173.803,371153.73,371165.051,371140.417,371168.279,371166.367,
> 371180.575,371132.664,371129.791,371232.919,371208.502,371289.462,
> 371207.595,371219.008,371139.921,371133.215,371061.467,371053.69,
> 371099.897,371108.782,371112.52,371114.241,371176.236,371159.185,
> 371159.291,371158.552,370978.252,371120.03,371116.993)
>
> yp<-c(8246507.94,8246493.176,8246465.974,8246464.413,8246403.465,
> 8246386.098,8246432.144,8246394.827,8246366.201,8246337.626,
> 8246311.125,8246300.039,8246299.594,8246298.072,8246379.351,
> 8246431.998,8246423.913,8246423.476,8246431.658,8246418.226,
> 8246400.161,8246396.891,8246394.225,8246400.391,8246370.244,
> 8246367.019,8246311.075,8246255.174,8246255.085,8246226.514,
> 8246215.847,8246337.316,8246330.197,8246311.197,8246304.183,
> 8246239.282,8246239.887,8246241.678,8246240.361,8246167.364,
> 8246171.581,8246171.803,8246169.807,8246293.57,8246183.194,8246189.926)
>
> #Now I have the size of each nest in meters (marked process)
>
> area<-c(117,30,4,341,15,160,35,280,108,168,63,143,2,48,182,42,
> 88,56,27,156,288,45,49,234,72,270,91,40,304,56,35,4,56.7,9,4.6,
> 105,133,135,23.92,190,12.9,15.2,192.78,104,255,24)
>
> # Make a contour for the window creation
> W <- convexhull.xy(xp,yp)
>
> #Create ppm object
> syn.ppp <- ppp(x=xp,y=yp,window=W, marks=area)
>
> # Plot the point process
> plot(syn.ppp)
>
> #Definition of raster resolution - 1 meter square
> ext <- as(extent(c(W$xrange,W$yrange)), "SpatialPolygons")
> syn.ras.res<-rasterToPoints(raster(ext, resolution = 1), spatial = TRUE)
>
> #Now Rasterize
> syn.ras<- rasterize(syn.ras.res@coords, raster(syn.ras.res), *?????*)
>
> I' ve like to create some kind of rule in *?????*, where pixel values in
> my final raster was 1 when inside de area (marks=area) and zero for
> outside de circular area given by points coordinates
> (syn.ras.res@coords) using 1 meter as resolution?
>
> Any ideas, please
>
> Thanks,
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Rasterize point process using specific rule

Karl Duffy
In reply to this post by R-sig-geo mailing list
I will be out of office from August 10th to August 23rd and will have limited access to email. I will respond to your message when I return

On 20 Aug 2019, at 15:12, ASANTOS via R-sig-Geo <[hidden email]> wrote:

> Dear members,
>
> I've like to create a raster using my event coordinates and information
> about the size in this coordinates as a rule for my raster creation.
> First, I make:
>
> library(raster)
> library(spatstat)
>
> #Points coordinates in UTM
> xp<-c(371278.588,371250.722,371272.618,371328.421,371349.974,
> 371311.95,371296.265,371406.46,371411.551,371329.041,371338.081,
> 371334.182,371333.756,371299.818,371254.374,371193.673,371172.836,
> 371173.803,371153.73,371165.051,371140.417,371168.279,371166.367,
> 371180.575,371132.664,371129.791,371232.919,371208.502,371289.462,
> 371207.595,371219.008,371139.921,371133.215,371061.467,371053.69,
> 371099.897,371108.782,371112.52,371114.241,371176.236,371159.185,
> 371159.291,371158.552,370978.252,371120.03,371116.993)
>
> yp<-c(8246507.94,8246493.176,8246465.974,8246464.413,8246403.465,
> 8246386.098,8246432.144,8246394.827,8246366.201,8246337.626,
> 8246311.125,8246300.039,8246299.594,8246298.072,8246379.351,
> 8246431.998,8246423.913,8246423.476,8246431.658,8246418.226,
> 8246400.161,8246396.891,8246394.225,8246400.391,8246370.244,
> 8246367.019,8246311.075,8246255.174,8246255.085,8246226.514,
> 8246215.847,8246337.316,8246330.197,8246311.197,8246304.183,
> 8246239.282,8246239.887,8246241.678,8246240.361,8246167.364,
> 8246171.581,8246171.803,8246169.807,8246293.57,8246183.194,8246189.926)
>
> #Now I have the size of each nest in meters (marked process)
>
> area<-c(117,30,4,341,15,160,35,280,108,168,63,143,2,48,182,42,
> 88,56,27,156,288,45,49,234,72,270,91,40,304,56,35,4,56.7,9,4.6,
> 105,133,135,23.92,190,12.9,15.2,192.78,104,255,24)
>
> # Make a contour for the window creation
> W <- convexhull.xy(xp,yp)
>
> #Create ppm object
> syn.ppp <- ppp(x=xp,y=yp,window=W, marks=area)
>
> # Plot the point process
> plot(syn.ppp)
>
> #Definition of raster resolution - 1 meter square
> ext <- as(extent(c(W$xrange,W$yrange)), "SpatialPolygons")
> syn.ras.res<-rasterToPoints(raster(ext, resolution = 1), spatial = TRUE)
>
> #Now Rasterize
> syn.ras<- rasterize(syn.ras.res@coords, raster(syn.ras.res), *?????*)
>
> I' ve like to create some kind of rule in *?????*, where pixel values in
> my final raster was 1 when inside de area (marks=area) and zero for
> outside de circular area given by points coordinates
> (syn.ras.res@coords) using 1 meter as resolution?
>
> Any ideas, please
>
> Thanks,
>
> --
> ======================================================================
> Alexandre dos Santos
> Prote??o Florestal
> IFMT - Instituto Federal de Educa??o, Ci?ncia e Tecnologia de Mato Grosso
> Campus C?ceres
> Caixa Postal 244
> Avenida dos Ramires, s/n
> Bairro: Distrito Industrial
> C?ceres - MT                      CEP: 78.200-000
> Fone: (+55) 65 99686-6970 (VIVO) (+55) 65 3221-2674 (FIXO)
>
>         [hidden email]
> Lattes: http://lattes.cnpq.br/1360403201088680
> OrcID: orcid.org/0000-0001-8232-6722
> Researchgate: www.researchgate.net/profile/Alexandre_Santos10
> LinkedIn: br.linkedin.com/in/alexandre-dos-santos-87961635
> Mendeley:www.mendeley.com/profiles/alexandre-dos-santos6/
> ======================================================================
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

        [[alternative text/enriched version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo