3

A basic QGIS 2.2.0-Valmiera, Select By Expression - Field Calculator question.

Introduction

I am a geologist searching through a geological database (see attached figure). I have a shapefile and associated attribute file of which I would like to select certain records within a field to make as new shapefile layer.

Task/method

I wish to search the 'GEOLHIST' and select Permian lithologies using the field calculator. Subsequently I shall Save Selection As. I have tried using the following script unsuccessfully.

"GEOLHIST" 
  IS 'Early Carboniferous to Early Permian' 
  OR 'Early Permian' 
  OR 'Early Permian to Late Carboniferous' 
  OR 'Early Permian to Late Permian' 
  OR 'Late Carboniferous to Early Permian' 
  OR 'Late Carboniferous to Permian' 
  OR 'Late Permian' 
  OR 'Late Permian to Permian' 'Permian' 
  OR 'Permian to Early Permian'

Question

What script can I use to select the above records?

Discussion

'GEOLHIST' IS 'Permian'

This script works. I have looked at the other OPERATORS (AND OR IS LIKE) and CONDITIONALS and have not figured out how to achieve my task.

Geological Attribute Table

@Nathan provided a working script, see attached figure.

I was not aware of the SQL operator in or the method of bracketing. This technique will be most helpful in the future.

"GEOLHIST" IN 
(
    'Carboniferous to Early Permian'
    , 'Early Permian'
    , 'Early Permian to Late Carboniferous'
    , 'Early Permian to Late Permian'
    , 'Late Carboniferous to Early Permian'
    , 'Permian'
    , 'Permian to Early Permian'
)

GEOLHIST SQL for multiple record success

7

If there is only need to select 'all permian lithologies' and no other conditions - you can use syntax like this:

"GEOLHIST" LIKE '%Permian%'

This should select all occurencess of 'Permian' word. This will not work with 'permian' probably. But you can change to '%ermian' thought.

  • Hello Tomas, Your script works as well. I noticed anything within '% x %' must be case sensitive. I was going to ask what you provided, but I erred on asking a another question within the main post to keep it specific. Thank you for contributing, absolutely marvelous. I shall be using it alot. Yours sincerely, Tom. – user27839 Apr 21 '14 at 8:43
  • Every % in value will be an "wildcard". I'm using it to select polish administrative units id's TERYT. For example "teryt:terc" LIKE '0808%'will find all administrative units of Świebodzin county (county, municipality, and villages) with TERYT TERC code 0808xxx. – Tomasz Nycz Apr 22 '14 at 6:04
  • 1
    Use ILIKE for case insensitive matching. – Michal Mackiewicz Apr 22 '14 at 9:29
3

You need to write a full expression between each OR, something like this:

"GEOLHIST" IS 'Early Carboniferous to Early Permian' OR "GEOLHIST" IS 'Early Permian' OR "GEOLHIST" IS ...

  • Hello Martin, Unfortunately that combination does not work. A simple "GEOLHIST" IS 'Early Carboniferous to Early Permian' will find the records I require but, still I cannot create a more comprehensive search. Thank you for providing advice. Tom – user27839 Apr 20 '14 at 6:40
  • 1
    Try this: "GEOLHIST" IN ('Early Carboniferous to Early Permian', 'Early Permian') – Nathan W Apr 20 '14 at 6:55
  • Hello Nathan, Thank you. Your script was what I required. – user27839 Apr 20 '14 at 9:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.