[R-sig-Geo] as.im in spatstat::ppm not working as before

2024-05-07 Thread Alexandre Santos via R-sig-Geo
Dear Members,

I'll calculate some old codes for a paper review, and I'm astonished that 
as.im() for fitting the Poisson model is not working as before. In my example:

library(raster)
library(spatstat)


# Elevation
r.grid.world <- 
raster('https://raw.githubusercontent.com/Leprechault/trash/main/wc2.1_10m_elev.tif')
proj4string(r.grid.world) <- CRS("+proj=longlat +datum=WGS84 +no_defs 
+ellps=WGS84 +towgs84=0,0,0")
r.grid.world.SGDF.F <- as(r.grid.world, "SpatialGridDataFrame")


#Fitting Poisson model
fit.c <- ppm(nztrees, ~ elev,
covariates=list(elev=as.im(r.grid.world.SGDF.F[[1]])))
#
# Error in as.im.default(r.grid.world.SGDF.F[[1]]) : 
#   Can't convert X to a pixel image

I tried as matrix and rotate, and the final real-valued pixel image didn't work 
as a covariate in the model. 

Please, any help with it?

Thanks in advance

Alexandre

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Create a ppp object in UTM with mixture of zones

2021-07-30 Thread Alexandre Santos via R-sig-Geo
Thanks, Mike

Problem solved with a transformation of to Lambert azimuthal equal-area 
projection centred on longitude and latitude of 0:

# Packages
library(spatstat)
library(sf)
library(sp)
library(raster)


# Open spatial data set in GitHub
sp_ds<-read.csv("https://raw.githubusercontent.com/Leprechault/trash/master/myspds.csv;)
str(sp_ds)
#'data.frame':  4458 obs. of  2 variables:
# $ Lat : num  9.17 9.71 9.12 9.12 9.71 ...
# $ Long: num  35.8 35.5 35.8 35.8 35.5 ...


sp_ds <- 
st_read("https://raw.githubusercontent.com/Leprechault/trash/master/myspds.csv;)
sp_ds_sf <- st_as_sf(sp_ds, coords = c("Lat", "Long"), crs = 4326)


# Here the Mike tip!!
sp_ds_laea = st_transform(sp_ds_sf, 
                           crs = "+proj=laea +x_0=0 +y_0=0 +lon_0=0 +lat_0=0")
# Create boudaries using sf
ch_ds <- st_convex_hull(st_union(sp_ds_laea))
W<- as.owin(ch_ds) 


# Create a ppp Point Pattern with sf object
out.ppp <- as.ppp(X=st_coordinates(sp_ds_laea),W=W)
plot(out.ppp)




# Make a CRS test
f1 <- ppm(out.ppp~1) 
E <-envelope(f1, Kinhom, nsim = 19, global = TRUE, correction = "border")
plot(E)

Best wishes,

Alexandre








Em sexta-feira, 30 de julho de 2021 15:41:08 BRT, Michael Sumner 
 escreveu: 





Don't use UTM, it's a legacy of a bygone era. Use a local custom projection 
such as laea:

https://twitter.com/mdsumner/status/1136794870113218561?s=19

I know it's common advice, utm for projection choice but it's trash propagated 
by folks who should know better. Traversing zones for projection choice for 
basic distance properties is unnecessary.

Best, Mike

On Fri, 30 Jul 2021, 08:21 Alexandre Santos via R-sig-Geo, 
 wrote:
> Dear Members,
> 
> 
> I'd like to use my spatial data set ("sp_ds") as ppp (spatstat Point Pattern 
> object), an I try to do:
> 
> 
> 
> # Open spatial data set in GitHub
> library(spatstat)
> library(sf)
> library(sp)
> 
> 
> sp_ds<-read.csv("https://raw.githubusercontent.com/Leprechault/trash/master/myspds.csv;)
> str(sp_ds)
> #'data.frame':  4458 obs. of  2 variables:
> # $ Lat : num  9.17 9.71 9.12 9.12 9.71 ...
> # $ Long: num  35.8 35.5 35.8 35.8 35.5 ...
> 
> 
> # Create boudaries using sf
> sfds = st_as_sf(sp_ds, coords=c("Long","Lat"), crs=4326)
> traps<-sp_ds
> ch <- chull(traps[,c(2,1)])
> coords <- traps[c(ch, ch[1]), ] 
> coordinates(coords) <- c("Long","Lat")
> proj4string(coords) <- CRS("+init=epsg:4326")
> W <- owin(poly=cbind(coordinates(coords)[,2],coordinates(coords)[,1])) 
> 
> 
> 
> # Create a ppp Point Pattern object
> out.ppp<-ppp(x=sp_ds$Lat,y=sp_ds$Long,window=W)
> plot(out.ppp)
> 
> 
> f1 <- ppm(out.ppp~1) 
> E <-envelope(f1, Kinhom, nsim = 19, global = TRUE, correction = "border")
> plot(E)
> 
> 
> #But I'd like to r distance (x axis) in kilometers and for this I need to 
> convert the coordinate reference system of 4326 to
> UTM, a have 3 UTM zones:
> #34N bounds: (18.0, 0.0, 24.0, 84.0)
> #35N bounds: (24.0, 0.0, 30.0, 84.0)
> #36N bounds: (30.0, 0.0, 36.0, 84.0)
> 
> 
> Please the area a simple way to create a ppp object in UTM with a mixture of 
> zones?
> 
> 
> Thanks in advance,
> 
> 
> Alexandre
> 
> 
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> 

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Create a ppp object in UTM with mixture of zones

2021-07-29 Thread Alexandre Santos via R-sig-Geo
Dear Members,


I'd like to use my spatial data set ("sp_ds") as ppp (spatstat Point Pattern 
object), an I try to do:



# Open spatial data set in GitHub
library(spatstat)
library(sf)
library(sp)


sp_ds<-read.csv("https://raw.githubusercontent.com/Leprechault/trash/master/myspds.csv;)
str(sp_ds)
#'data.frame':  4458 obs. of  2 variables:
# $ Lat : num  9.17 9.71 9.12 9.12 9.71 ...
# $ Long: num  35.8 35.5 35.8 35.8 35.5 ...


# Create boudaries using sf
sfds = st_as_sf(sp_ds, coords=c("Long","Lat"), crs=4326)
traps<-sp_ds
ch <- chull(traps[,c(2,1)])
coords <- traps[c(ch, ch[1]), ] 
coordinates(coords) <- c("Long","Lat")
proj4string(coords) <- CRS("+init=epsg:4326")
W <- owin(poly=cbind(coordinates(coords)[,2],coordinates(coords)[,1])) 



# Create a ppp Point Pattern object
out.ppp<-ppp(x=sp_ds$Lat,y=sp_ds$Long,window=W)
plot(out.ppp)


f1 <- ppm(out.ppp~1) 
E <-envelope(f1, Kinhom, nsim = 19, global = TRUE, correction = "border")
plot(E)


#But I'd like to r distance (x axis) in kilometers and for this I need to 
convert the coordinate reference system of 4326 to
UTM, a have 3 UTM zones:
#34N bounds: (18.0, 0.0, 24.0, 84.0)
#35N bounds: (24.0, 0.0, 30.0, 84.0)
#36N bounds: (30.0, 0.0, 36.0, 84.0)


Please the area a simple way to create a ppp object in UTM with a mixture of 
zones?


Thanks in advance,


Alexandre

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Simple Ripley's CRS test for market point patters

2019-07-22 Thread Alexandre Santos via R-sig-Geo
Dear R-Sig-Geo Members,     I"ve like to find any simple way for apply CRS test 
for market point patters, for this I try to create a script below:
#Packages require(spatstat)require(sp)

# Create some points that represents ant nests in 
UTMxp<-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)
# Then I create the size of each nest - my covariate used as marked 
processarea<-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 countour - only as exerciseW <- convexhull.xy(xp,yp)
#Create a ppp 
objectp_xy<-cbind(xp,yp)syn.ppp<-ppp(x=coordinates(p_xy)[,1],y=coordinates(p_xy)[,2],window=W,
 marks=area)syn.ppp <- as.ppp(syn.ppp)plot(syn.ppp, main=" ")
First, I've like to study CSR of market point process (my hypothesis is that 
different size have a same spatial distribution) when area >= 0, area < 25 and 
area >=25, area < 55, for this I make:
# Area 0-25env.formi1<-envelope(syn.ppp,nsim=99,fun=Kest, area >= 0, area < 
25)plot(env.formi1,lwd=list(3,1,1,1), main="") 
# Area 25-55env.formi2<-envelope(syn.ppp,nsim=99,fun=Kest, area >=25, area < 
55)plot(env.formi2,lwd=list(3,1,1,1), main="") 
My first problem is that I have the same plot in both conditions and I don't 
know why.
Second, if I try to estimate the market intensity observed pattern
est.int <- density(syn.ppp)est_xy <-  rmpoispp(est.int)plot(est_xy, main=" ")
My output is only my points position without marked area in my ppp object 
created.
My question is what is the problem with this Ripley's reduced second moment 
function approach? There are any way for study my point process when the area 
is a covariate of my point process?
Thanks in advanced
Alexandre


-- 
==Alexandre 
dos SantosProteção Florestal IFMT - Instituto Federal de Educação, Ciência e 
Tecnologia de Mato GrossoCampus CáceresCaixa Postal 244Avenida dos Ramires, 
s/nBairro: Distrito Industrial Cáceres - MT  CEP: 
78.200-000Fone: (+55) 65 99686-6970 (VIVO) (+55) 65 3221-2674 
(FIXO)e-mails:alexandresanto...@yahoo.com.br 
alexandre.san...@cas.ifmt.edu.br Lattes: http://lattes.cnpq.br/1360403201088680 
OrcID: orcid.org/-0001-8232-6722   -   ResearcherID: 
A-5790-2016Researchgate: www.researchgate.net/profile/Alexandre_Santos10
   LinkedIn: 
br.linkedin.com/in/alexandre-dos-santos-87961635Mendeley:www.mendeley.com/profiles/alexandre-dos-santos6/
==



[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo