Skip to main content
Tweeted twitter.com/StackGIS/status/1075179113542049792
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
edited tags
Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286
Source Link
Waterman
  • 1.2k
  • 12
  • 29

Use Only First "x" Characters from Table in qgis:selectbyexpression

I have a list of street names in this format:

STRNAME
Elsinore
Neil Young
Penny
Fall

And a shapefile ("input_streets") with street names in this format:

STREET
Elsinore Av
Neil Young St
Penny Lane
Fall Dr

I want to select streets in the "input_streets" shapefile that are also found in the 1st list, but you can see my challenge, the first list doesn't have the street suffixes, the second list does. This means a simple expression like this won't work:

expression = '"STREET" = '+ "'"+ strname"'" 

...where "strname" is just the "STRNAME" values from the first list. The suffixes in "STREET" values 'get in the way'.

I need a way to give QGIS an expression that can compare ONLY the Street Names (their Prefixes, Ignoring the Suffixes, whatever they happen to be: St, Lane, Rd, etc.)

Something like:

street = STREET[0:firstspace]

But can this be done? Can one refer to the column heading of a table with RESTRICTIONS on HOW MUCH of the column value to USE in an expression? (ie. "give me the value in STREET but stop at the first space")

Example:

street = STREET[0:firstspace]
expression = 'street = '+ "'"+ strname"'" 

Or can one only refer to the column heading in an expression, and whatever values happen to be in that column, you're stuck with?