Sunday 21 January 2018

coordinate system - Adding shape of defined dimensions using PyQGIS in QGIS 3.4


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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...