3

I'm completely new to PYQGIS. I'm pretty handy with MapBasic in MapInfo and was wondering how I would 'translate' this command from SQL select into Python (hope that makes sense)

Essentially, I have a layer with multiple objects - but I only want to select and extract the objects which have an id like %ABC% into a separate layer.

In MapBasic I would:

Select * from *examplelayer* where id Like "%ABC%" into *ABC*

where 'id' is a field I want to search in the table/layer 'examplelayer', id Like "%ABC%" meaning that any id's containing ABC will be selected into a new table/map layer named "ABC"

sys49152
  • 1,691
  • 1
  • 19
  • 21
MikBrowne
  • 31
  • 1
  • Welcome to GIS SE! As a new user be sure 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 Apr 05 '18 at 23:54
  • Can you show more of your python code so we can see where you're up to. Do you have a list of IDs? If so layer.setSelectedFeatures([ID,ID,ID...]) then export the selected, this post https://gis.stackexchange.com/questions/153309/qgis-export-shapefile-using-pyqgis might help point you in the right direction. – Michael Stimson Apr 06 '18 at 00:31

0 Answers0