Create yes/no field based on location of other shapefiles

2477
6
10-04-2011 03:45 AM
JonathanHarper1
New Contributor
Hi,

I believe what I'm wanting to achieve is fairly simple...
I'm wanting to create a field which basically says yes or no to whether or not the feature falls completely within another feature in a different shapefile.

I've tried using the spatial join function and it works in that it can distinguish whether or not it falls within another feature but the field doesn't say yes/no it has a value in.

Any help would be much appreciated.

Thanks!
0 Kudos
6 Replies
NobbirAhmed
Esri Regular Contributor
the feature falls completely within another feature


When using Spatial Join, use the first group of features as target.

In the Join Operation parameter, use JOIN_ONE_TO_MANY

In the output, the Join_Count field will have 0 or 1:

0 means - False (the target is not completely within join feature)
1 means - True

Let me know how it goes.
0 Kudos
JonathanHarper1
New Contributor
Nobbir,

Thanks for replying! This was exactly what I was looking for. Is there any way I can make it say yes/no instead of 1/0? It's not essential but as its going to be published for non tech people it would be handy if it could be.

Thanks for your help, it's much appreciated
Jonny
0 Kudos
NobbirAhmed
Esri Regular Contributor
Add a new field of type Text (string) and then run Calculate field as show in the image below.

Basically, you use a codeblock to set YES for 1 and NO for 0. I'm using Python here. Use the new field in the Field Name parameter.

Expression:
 calc(!Join_Count!)

Codeblock:
def calc(field):
   if field == 0:
      return 'NO'
   return 'YES'
0 Kudos
JonathanHarper1
New Contributor
Brilliant that worked a treat.

Thanks very much for your help, I really appreciate it 🙂
0 Kudos
AngelaSpitzer
New Contributor
A less scripty way of doing this is simply to select features by location. Once they are selected you just calculate the field (yes) for everything that is selected. Then sort that field so that all the ones with a yes are grouped together. Then highlight everything without a yes and then calculate the field of those to say 'no'. Easy.
0 Kudos
JonathanHarper1
New Contributor
I had a play around with this in the first instance but didn't know how to do the field calculate to set everything that was selected as Yes.

I assume it's very similar to the 2nd part of the above methodology?

Cheers
0 Kudos