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.
No comments:
Post a Comment