I'm having some trouble applying my Python skills to develop some scripts in PyQGIS. For me it's far simpler to write it in ArcPy, but then again I wouldn't get that much satisfaction after finishing my project. Trying to work with open source tools as much as possible.

In short, for now I want to write a Python script that takes in a shapefile and from that generates another one with some specific attribute data related to buildings. If I were doing it in ArcPy, my algorithm would be the following: use the MakeFeature Layer_management, then perform a SelectLayerByLocation_management, within the selection select the data you need, and then create another layer with desired data.

How could I this in PyQGIS?

One idea, reading the PyQGIS Cookbook, to use .getFeatures(), QgsVectorFileWriter to write the shapefile, but how do I perform the query?

  • Can you expand your script, because if you want to use Open Source tools you can even do that in Python only without ArcPy or PyQGIS – gene May 21 '15 at 15:40
  • Sure I can, it was only meant as a starting point. Hmm, I haven't tried or thought about that before. – Geosphere May 21 '15 at 16:33
  • However, isn't there a need for a cursor-like object that's already implemented in the PyQGIS core library? Can you do that simply by Python? I don't see how... – Geosphere May 22 '15 at 8:07
  • 2
    Only ArcPy use cursors to call ArGIS commands (same with Python database modules), PyQGIS and Geospatial Python modules don't need cursors (only Python) – gene May 22 '15 at 14:55
  • In any case, thank you @gene. I'll change my approach accordingly. – Geosphere May 23 '15 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.