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"

2
  • 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
    Commented Apr 5, 2018 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 gis.stackexchange.com/questions/153309/… might help point you in the right direction. Commented Apr 6, 2018 at 0:31

0

Browse other questions tagged or ask your own question.