Adding a shape of defined dimensions using pyqgis in QGIS 3.4

by Tilson   Last Updated June 13, 2019 07:22 AM

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.



Related Questions


Updated January 28, 2019 20:22 PM

Updated June 16, 2017 00:22 AM

Updated April 27, 2019 10:22 AM

Updated July 29, 2017 08:22 AM

Updated November 12, 2018 18:22 PM