[Qgis-user] Standard Deviational Ellipse
gene
martin.laloux at gmail.com
Sat May 21 01:31:57 PDT 2016
It is very easy to do in R with aspace
library(aspace)
library rgdal
# open the shapefile
layer = readOGR("/Users/Shared",layer="points_test_aspace")
coords=coordinates(layer)
# calculate the ellipse
calc_sde(id=1,points=coords) #you can add many parameters here as
calc_sde(id=1, filename="SDE_Output.txt", centre.xy=NULL, calccentre=TRUE,
weighted=FALSE, weights=NULL, points=coords, verbose=FALSE)
# save the result to shapefile
shp = convert.to.shapefile(sdeloc,sdeatt,"id",5)
write.shapefile(shp, "SDE_Shape", arcgis=T)
aspace uses the package shapefile
<https://cran.r-project.org/web/packages/shapefiles/> to write the
shapefile (a polygon from points, parameter 5 in shp) and it needs an
intermediate file to store the coordinates (SDE_Output.txt here).
But as the geometry (ellipse) is stored in the sdeloc variable (points) and
the attributes in the sdeatt variable, you can make a processing rscript.
In the script, you don't need the intermediate file because QGIS uses Rgdal
to read and write files but aspace needs it otherwise it doesn't work
##Ellipse=group
##Layer=vector
##Output = output vector
library(aspace)
coords<-coordinates(Layer)
calc_sde(id=1, filename="/Users/me/SDE_Output.txt", centre.xy=NULL,
calccentre=TRUE, weighted=FALSE, weights=NULL, points=coords, verbose=FALSE)
fin_coord = c(sdeloc[2],sdeloc[3])
# directly transform the points to a SpatialPolygonsDataFrame
sp = SpatialPolygons( list(Polygons(list(Polygon(fin_coord )), 1)))
res = SpatialPolygonsDataFrame(sp, sdeatt)
Output<-res
There are many other variables in the resulting attribute table that you can
use (cendroid, theta angle, etc.)
<http://osgeo-org.1560.x6.nabble.com/file/n5267523/ellipse.png>
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Standard-Deviational-Ellipse-tp5267195p5267523.html
Sent from the Quantum GIS - User mailing list archive at Nabble.com.
More information about the Qgis-user
mailing list