2

I am attempting to add a feature with defined geometry as a layer. Having added the feature I checked on the dimensions of its sides and they measure differently.

This is the code that I am using.

x = [0,0,-5000,-5000,0,0]
y = [0,-1000,-1000,1000,1000,0]

vl = QgsVectorLayer("MultiLineString?crs=epsg:7405", "temp", "memory")
pr = vl.dataProvider()
pr.addAttributes([QgsField("name", QVariant.String)])
vl.updateFields() 

PointList = []
for i in range(len(x)):
    p = QgsPointXY(x[i],y[i])
    PointList.append(p)

geom_line=QgsGeometry.fromPolylineXY(PointList)
f = QgsFeature()
f.setGeometry(geom_line)
pr.addFeature(f)
vl.updateExtents() 
QgsProject.instance().addMapLayer(vl)

The lines do not measure as 2000m and 5000m, but as 1997m and 4992m (although opposite sides do not measure the same).

I wonder if it is to do with the CRS or the measure tool? I think that I am missing something fundamental here.

2

QGIS 3 uses ellipsoid length calculations by default whereas in previous versions, this was ignored and instead planimetric distance calculations were used. If you measure the lines using the expression:

length($geometry)

You should get the values you were looking for (5000m and 2000m):

Field calculator


Before you use your code, set your project ellipsoid measurement to None / Planimetric and then run your code again. You can set this from the menubar:

Project > Properties > General > Measurements

Project properties

You could just use the expression

$length

And you should get the same values as mentioned above (5000m and 2000m).

0

A very though answer from Joseph clarifying how QGiS makes measurements However, the question is now clearer to me and it is:

How can I place the shape of defined dimensions (in metres, 5000m X 2000m) measured on the WGS84 ellipsoid at a location on the ellipsoid (51 degrees N 2 degrees W)?

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.