0

I'm using QGIS 2.18.11. So I have a list of various coordinates and rotation angle. I'd like to paste a template polygon with each of their center point positioned on each coordinate and rotated by an angle as specified in the list. For the translation part, I tried to use the method outlined here: Move a layer in QGIS to a precise position based on centroid but got stuck near the end because QgsFeature.setGeometry() is voided.

feat = QgsFeature()
feat.setGeomertry(QgsGeometry.fromPolygon(pol_t))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'QgsFeature' object has no attribute 'setGeomertry'

As for the rotation part, I came across QgsVector.rotateBy() that seems to be able to do the trick. Am I on the right track?

GIS_Newbie
  • 97
  • 5
  • Don't forget to take the [Tour]. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an [edit] button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. – PolyGeo Sep 18 '17 at 03:04
  • As for any automation process work on writing a code snippet that does just the first part first. That way you can research/ask about where you get stuck trying to do it, based on some starting code that you have written. – PolyGeo Sep 18 '17 at 03:07
  • @PolyGeo Hi... I'm stuck from the beginning – GIS_Newbie Sep 18 '17 at 03:37
  • This may be a good place to start: https://gis.stackexchange.com/questions/30063/writing-standalone-python-scripts-using-pyqgis I recommend not thinking about GIS SE as being some sort of online GIS tutor. – PolyGeo Sep 18 '17 at 03:48
  • @PolyGeo From the beginning as in, I'm not sure how to use certain PyQGIS classes. There are no good reference material like ArcPy and not as widely discussed as ArcPy. Thank you for your link but I do know how to write a standalone scripts so unfortunately that is not where I'm stuck. Would you then recommend that I separate vector moving and vector rotation into 2 questions? Because I have nowhere else to turn to. – GIS_Newbie Sep 18 '17 at 05:53
  • Are you saying that you already know how to do the first part? If so, then showing that and then asking about the second part would be a good first question. Then a separate question that starts by showing how you've done the first two parts and are stuck on the third would work. – PolyGeo Sep 18 '17 at 06:30
  • @GIS_Newbie Look for the classes QgsVectorLayer, QgsFeature and QgsGeometry. The last one has methods rotate() and translate(). – Redoute Sep 18 '17 at 09:17
  • setGeomertry do you mean setGeometry? – alphabetasoup Sep 19 '17 at 03:56
  • I suppose that solves your issue? – alphabetasoup Sep 19 '17 at 09:16
  • @RichardLaw I actually have trouble rotating the translated polygon as well, I've tried using QgsGeometry.rotate() but with no luck – GIS_Newbie Sep 19 '17 at 09:26

0 Answers0