3

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?

3
  • I would calculate in the shapefile with a python syntax ''.join(split(NameField," ")[-1:]) and join on that; It would probably be best to upcase or lowercase both fields though : Neil young != Neil Young. May 19, 2016 at 1:23
  • Thanks @Michael Miles-Stimson, but can you explain further? You're suggesting I perform a join between the list and the shapefile? There are no common columns on which to do that. Thank you.
    – Waterman
    May 19, 2016 at 2:02
  • I'm suggesting you make a common column. May 19, 2016 at 2:14

1 Answer 1

1

Try using an expression like this:

left( "STRNAME", strpos( "STREET", "STRNAME") )

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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