jmiller121

Select certain rows from an UpdateCursor and export those rows to a new shapefile

Discussion created by jmiller121 on Nov 4, 2011
Latest reply on Nov 8, 2011 by jskinner-esristaff
Here is what I am trying to do...  Given a feature class, sort that feature class based on certain fields, then pick each unique record (where certain field values from the CURRENT record don't match certain field values from the PREVIOUS record...) and export those unique records to a new feature class...

Here is what I have so far...

rows = arcpy.UpdateCursor(r"c:\centerlinestemp.shp","","","", "LSN A; L_CITY A; R_CITY A)
previous = []
for row in rows:
    current = [row.LSN, row.L_CITY, row.R_CITY]
    if current != previous:
        print "FIRST RECORD-", current
    else:
        print "-------------", current

    previous = current[:]


That code yields results like this...


FIRST RECORD- [u'WATER ST', u'HOLMESVILLE', u'HOLMESVILLE']
------------- [u'WATER ST', u'HOLMESVILLE', u'HOLMESVILLE']
------------- [u'WATER ST', u'HOLMESVILLE', u'HOLMESVILLE']
------------- [u'WATER ST', u'HOLMESVILLE', u'HOLMESVILLE']
FIRST RECORD- [u'WEST ST', u'BERLIN', u'BERLIN']
------------- [u'WEST ST', u'BERLIN', u'BERLIN']
FIRST RECORD- [u'WILDHORN DR', u'LAKE BUCKHORN', u'LAKE BUCKHORN']
FIRST RECORD- [u'WISE ST', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WISE ST', u'MILLERSBURG', u'MILLERSBURG']
FIRST RECORD- [u'WOOD ST', u'WINESBURG', u'WINESBURG']
FIRST RECORD- [u'WOODLAND DR', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOODLAND DR', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOODLAND DR', u'MILLERSBURG', u'MILLERSBURG']
FIRST RECORD- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
------------- [u'WOOSTER RD', u'MILLERSBURG', u'MILLERSBURG']
FIRST RECORD- [u'ZERMATT DR', u'LAKE BUCKHORN', u'LAKE BUCKHORN']
FIRST RECORD- [u'ZURICH DR', u'LAKE BUCKHORN', u'LAKE BUCKHORN']
------------- [u'ZURICH DR', u'LAKE BUCKHORN', u'LAKE BUCKHORN']



What I want to do is export all of the "FIRST RECORD" rows to a new shapefile...  how might one do that...?

rows = arcpy.UpdateCursor(r"c:\centerlinestemp.shp","","","", "LSN A; L_CITY A; R_CITY A)
previous = []
for row in rows:
    current = [row.LSN, row.L_CITY, row.R_CITY]
    if current != previous:
        # SELECT THIS ROW AND ADD IT TO A SELECTION SET??? 

    previous = current[:]

# EXPORT SELECTION SET???


Thank you for your assistance...!
Jason

Outcomes