-3

I created a python script using Fiona and shapely where I can find same values between two shapefiles in the specific field (myfield) for any of two shapefiles.

If I use next snippet code:

for p2 in input2:
    for p1 in file1features:
       if p2['properties']['myfield'] == p1['properties']['myfield']:

the script works fine and I got a new shapefile where it has only the features where there is some value. However, it doesn't work if I want to take wrong features for different field values.

For example, when I use:

p2['properties']['myfield'] != p1['properties']['myfield'] 

then it takes all values from the shapefile.

  • 1
    What do p2 is? A feature or something else? I don't know why you didn't use p2['myfield'] instead of p2['properties']['myfield'] for evaluating the field 'myfield': what do 'properties' is? – mgri Jan 28 '17 at 13:44
  • 3
    I can't figure out how to edit this to makes sense in English. Please make an attempt at proper capitalization and punctuation, so we can understand how to help you. – Vince Jan 28 '17 at 13:58
1

This question concerns how to do a difference operation between two sets of vector features A and B.

A [not in] B

import fiona
# open datasets input2 and file1features
# ...
for p2 in input2:
    for i, p1 in enumerate(file1features):
       if p2['properties']['myfield'] == p1['properties']['myfield']:
           break
    #do something such as write feature p1
    #shpout.write(p1) # pseudocode

(A [not in] B) [and] (B [not in] A)

Also called the symmetric difference

# open datasets input2 and file1features
# ...
for p2 in input2:
    for i, p1 in enumerate(file1features):
       if p2['properties']['myfield'] == p1['properties']['myfield']:
           break
    #do something such as write feature p1
    #shpout.write(p1) # pseudocode

for p1 in file1features:
    for i, p2 in enumerate(input2):
       if p2['properties']['myfield'] == p1['properties']['myfield']:
           break
    #do something such as write feature p2
    #shpout.write(p2) # pseudocode
  • yes Mr.Byers that good but how to take in the new shapefile the wrong features ? – Chris Papas Jan 30 '17 at 19:45
  • why not work != ? – Chris Papas Jan 30 '17 at 19:45

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.