0
votes

Hey people of Stackoverflow!

I'm trying to see which factors increases the incidence of fire caused by lightnings, but I'm having problems creating a pixel image object using the im() function of the library spatstat.

The thing is the data I have is in the shape of the area and not a rectangle or square, so I can't transform the data into a matrix.

I tried to create a window with the function owin() and the poly argument, but I have ALL the points (including border and filling) of the area, so I can't get the polygon of the area.

So I need help to get ideas to a) create an pixel image object directly from my database or b) adding points to create a rectangle to then transform my data into a matrix and create with it the pixel image object.

I hope you can help me and if you need more info, please let me know.

Edit: Sorry for not putting an example of the data before.

So my data looks like this:

no. lon      lat    elev  exp slope veg

1 700.5380 984.4786  548  -1     0   1
2 704.0483 984.4786  518 135     0   1
3 707.5586 984.4786  548  -1     0   1
4 711.0689 984.4786  569 254     4   1
5 714.5791 984.4786  590 178     5   1
6 697.0277 981.9342  518  -1     0   1

You can see a plot of the data here.

The other datafile I have only has the data of the lightnings.

Hope you can help me and thanks for everything!

Also, I can't use the im() because I can't make my data into a matrix and I also tried to use owin(poly=data) but it makes me a shape made of lines with the data, also I read more and I think owin wasn't the solution I needed either...

I'm reading right now other libraries to see if I can do the raster with other library instead of spatstat.

1
To get help on SO you'll need to provide some example data, the code you've tried, and the outcome you're trying to achieve. And we don't need to see ALL your data /code, a minimal working example is best. - SymbolixAU
Yes we need so example data and code. Especially the format of you data is important to get anywhere. - Ege Rubak
@SymbolixAU and Ege Rubak. I already edited the question with an example of the data. Thanks in advance! - Victor Taracena

1 Answers

0
votes

I think this recipe should work for you to create a SpatialPointsDataframe and an image (in the example with the raster package) from you data:

https://gis.stackexchange.com/questions/20018/how-can-i-convert-data-in-the-form-of-lat-lon-value-into-a-raster-file-using-r

Then you can convert the spatial df to spatstat with:

library(maptools)
library(spatstat)
spatialPointsDF<-as(spatialPointsDataFrame, "ppp")
plot(spatialPointsDF)

See the maptools functions:

https://www.rdocumentation.org/packages/maptools/versions/0.9-2/topics/as.ppp

To create an im object from raster, see again the maptools spatstat API (as.im.RasterLayer):

https://www.rdocumentation.org/packages/maptools/versions/0.9-2/topics/as.ppp