Query for orginal numbers

645
26
09-23-2019 03:48 PM
CCWeedcontrol
Regular Contributor

I am trying to query a filed to find original parcels, i would like to create a filled and mark the ones that are original and don't have not split. Currently the field is a string with a length of 11. Some parcels have 5, some 8 and some 10 - not including the alph letter. Hopefully i have explained good what I am needing, i am just not sure how to do this. At first i thought of doing unique numbers but some how it would need to know if the first 5 digits are used, there are some duplicate numbers as well. I am kind of lost on how to proceed, if anyone has done something similar could share some code please?

the attributes are as follows for example;

R00062 (Original parcel)--> has R00062010 (Split parcel, next one below) - this is not one i need marked.

R00062010 - Not Original parcel

R32073114 - Not Original parcel 

R32078 - Original parcel because there is no other parcel number associated with it, need this one mark in the new filed.

R32079 - Original parcel because there is no other parcel number associated with it,, need this one mark in the new filed.

R32081 - Original parcel because there is no other parcel number associated with it,, need this one mark in the new filed.

R32082012 - Not Original parcel 

R32083012 - Not Original parcel 

0 Kudos
26 Replies
JoeBorgione
MVP Esteemed Contributor

When you say 'Original parcel because there is no other parcel number associated with it'  how is that 'association' maintained?   Do you have a related table of the 'child' parcels? Is it maintained in the actual parcel data itself?

Is there some what to see what the parent parcel of R00062010 is? etc.....

That should just about do it....
0 Kudos
CCWeedcontrol
Regular Contributor

Joe,

When a parcel is split for example, a split comes through for R00062, R00062 stays as the mother account and the new parcels (child parcels) get 010 or 011 or 012 etc. There is currently no efficient way of maintaining this data, one would just have to look to see of there is a R00062010 or R00062010 or R00062011 or R00062012 etc. This is not my data this is data i am working with.

0 Kudos
RandyBurton
MVP Regular Contributor

Is the original parcel always 6 characters?  If so, would slicing work?

>>> parcel = 'R00062010'
>>> original = parcel[:6]
>>> original
'R00062'
>>> subparcel = parcel[6:]
>>> subparcel
'010'
>>> len(subparcel)
3
0 Kudos
CCWeedcontrol
Regular Contributor

Yes it's always 6 characters,  R00062 would seem like it's an original parcel but there could be R00062010 or R00062010 or R00062011 or R00062012 (These would be considered child parcels) but some how it needs to check to see if R00062 (6 characters) are used in other parcel numbers. This parcel would not be considered an original parcel because it's has child parcel numbers.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

So you are really interesting in marking/finding all original parcels that were never split and thus have no children parcels?

0 Kudos
CCWeedcontrol
Regular Contributor

Yes that is correct.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Try:

import arcpy
from collections import Counter

tbl = # path to table containing parcels

parcel_count = Counter(
    (pid[:6] for pid, in arcpy.da.SearchCursor("tbl","PARCEL_NO"))
)

for pid,cnt in parcel_count.items():
    if cnt == 1:
        print(pid)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
CCWeedcontrol
Regular Contributor

Joshua, i appreciate the help. I am getting error, see below. Also how can i get this to this to put a mark in a another field vs just printing them?

line 10, in <module>
    for pid,cnt in parcel_count.items():
AttributeError: 'generator' object has no attribute 'items'

import arcpy
from collections import Counter

tbl = 'C:/Temp/ParcelNumberSample2.dbf'

parcel_count = (
    (pid[:6] for pid, in arcpy.da.SearchCursor(tbl,"PARCEL_NO"))
)

for pid,cnt in parcel_count.items():
    if cnt == 1:
        print(pid)
JoshuaBixby
MVP Esteemed Contributor

My bad, i left out of function call, I just edited my earlier code.

0 Kudos