Geographic Information Systems Asked on February 4, 2021
I keep getting the below error message when I try to use R in QGIS. For example Monte Carlo or Quadrant.
I use a point shape file with the x and y coordinates as centroids within the attribute table.
For example
##Point pattern analysis=group
##Layer=vector point
##Simulations=number 100
##Optional_plot_name=string
##showplots
library(spatstat)
library(maptools)
sp <- as(Layer, "SpatialPoints")
sp <- as(sp, "ppp")
e <- envelope(sp, Kest, nsim = Simulations)
>e
plot(e, main = Optional_plot_name)
Error Message
Error in as(Layer, "SpatialPoints") :
no method or default for coercing "sf" to "SpatialPoints"
Calls: as -> .class1 -> as
Info on the point shapefile as follows
Name
LandScanJoinCTAT
Path
G:ArticleGISLandScanMasterLandScanJoinCTAT.shp
Storage
ESRI Shapefile
Comment
Encoding
System
Geometry
Point (Point)
CRS
EPSG:4326 - WGS 84 - Geographic
Extent
17.0590112291777913,-34.4981314092633582 : 32.5317232060707155,-22.4313408665917606
Unit
degrees
Feature count
234
Latest version of Processing R Provider allows us to choose between sf
and rgdal
to load vector data, and sf
is the default provider (from version 2.0, I guess).
You may follow the suggestion by @Jeffrey Evans, or add ##load_vector_using_rgdal
option to use rgdal
instead of sf
; for instance -
##Point pattern analysis=group
##load_vector_using_rgdal
##Layer=vector point
##Simulations=number 100
##Optional_plot_name=string
##showplots
library(spatstat)
library(maptools)
sp <- as(Layer, "SpatialPoints")
sp <- as(sp, "ppp")
e <- envelope(sp, Kest, nsim = Simulations)
>e
plot(e, main = Optional_plot_name)
It's the second line.
Answered by Kazuhito on February 4, 2021
Thanks. I have used your advise and it seems to work. However I found another solution. I save the shape-files in csv via QGIS, then transfer the csv file into R and then use R to create another shape-file (similar to the original). I then open the R created shape-file in QGIS And it works fine. But only for point layers and files
Answered by Clive Coetzee on February 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP