3

I need to use QGIS to create an ellipse employing a SatScan output with information on spatial risk clusters for the occurrence of an.

The output contains the coordinates of the centroid point of the ellipse, as well as E-MINOR, E-MAJOR, E-ANGLE and E-SHAPE.

I've already created a circular buffer using MMQGIS plugin, but I could not do the same for an elliptical shape. Any ideas?

5

I can't see any option in MMQGIS plugin for creating buffers shaped as ellipses. So, if you are really interested in create this kind of objects, you can learn about how to run following PyGIS code in Python Console of QGIS.

It produces ellipses based in its parametric equations. Parameters that you have to change in this code (at the beginning) are center, semi axis a, semi axis b, angle and EPSG code projection (in meters, not degrees).

from math import pi, cos, sin

##################################################  
pt = (392127.908689, 4449521.71257) #center

a = 200 #semi axis a
b = 100 #semi axis b

angle = 45

epsg = 32612

###################################################
ctr = QgsPointXY(pt[0], pt[1])

x0 = pt[0]
y0 = pt[1]

interv = 2*pi

parts = 60

add = interv/parts

t = 0

t_values = [ 0 ]

for i in range(parts-1):
    t += add
    t_values.append(t)

points = [ QgsPointXY( x0 + a*cos(t), y0 + b*sin(t)) for t in t_values ]

points.append(points[0])

uri = "Polygon?crs=epsg:" + str(epsg) + "&field=id:integer""&index=yes"

mem_layer = QgsVectorLayer(uri,
                           'polygon',
                           'memory')

prov = mem_layer.dataProvider()

polygon = [ [ points ] ]

feats = [ QgsFeature() for i in range(len(polygon)) ]

for i, feat in enumerate(feats):
    feat.setAttributes([i])
    geom = QgsGeometry.fromPolygonXY(polygon[i])
    geom.rotate(angle, ctr)
    feat.setGeometry(geom)

prov.addFeatures(feats)

registry = QgsProject.instance()
registry.instance().addMapLayer(mem_layer)

After running it in Python Console of QGIS, with center, semi axis a, semi axis b, angle and EPSG code projection established there, I got an ellipse centered in (392127.908689, 4449521.71257) point, with 200 and 100 meters, respectively, for its a and b semi axis, rotated 45 degrees in anticlockwise sense and with an EPSG code of 32612 (WGS 84/ UTM zone 12N).

example

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.