Thursday, 29 August 2013

Python Mutiple Lists into multiple lists to deconflict

Python Mutiple Lists into multiple lists to deconflict

I have ran into a very complicated issue. To protect the sensitivity of
the information i am manipulating, everything will be refered to as
"Trees", and "Birds".
Below is my code:
import arcpy
import os, string
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:\Users\Student\Desktop\Leaks"
arcpy.MakeFeatureLayer_management("Trees_20Aug13.shp", "AlphaTree" )
##arcpy.MakeFeatureLayer_management("Trees_27Aug13.shp", "BravoTree" )
arcpy.AddField_management("Trees_20Aug13.shp", "New_C", "TEXT")
arcpy.AddJoin_management("AlphaTree", "C","Trees_27Aug13.shp", "C")
arcpy.CalculateField_management("AlphaTree", "Trees_20Aug13.New_C",
"[Trees_20Aug13.C] & [Trees_27Aug13.C]", "VB", "")
arcpy.FeatureClassToFeatureClass_conversion("AlphaTree",
arcpy.env.workspace, "CharlieTree.shp")
##arcpy.FeatureClassToFeatureClass_conversion("BravoTree",
arcpy.env.workspace, "DeltaTree.shp")
Cloud = []
with arcpy.da.UpdateCursor("CharlieTree.shp", ["New_C"]) as cursor:
for row in cursor:
Cloud = row[0]
Cloud.strip()
TreeLine = ':'.join(Cloud.split(' '))
x = TreeLine
SpaceTree= x[1:]
str(SpaceTree)
(print gives me A:B:C:A:C:D at this point; however it isnt keeping all my
lines of data, im trying to manipulate THOUSANDS of lines of data at once)
SkyTree = [SpaceTree.split(':') for x in text]
(So at this point i am trying to take A:B:C:A:C:D, which is two excel
document tables combined, in Arcmap, and dedup it to A:B:C:D, then export
it back to the "new master" file as A:B:C:D on each line of data, however
when i split it it looks like this
[[u'A', u'B', u'C', u'A', u'C', u'D'], [u'A', u'B', u'C', u'A', u'C',
u'D'], [u'A', u'B', u'C', u'A', u'C', u'D'], [u'A', u'B', u'C', u'A',
u'C', u'D'], [u'A', u'B', u'C', u'A', u'C', u'D'], [u'A', u'B', u'C',
u'A', u'C', u'D'], [u'A', u'B', u'C', u'A', u'C', u'D'], [u'A', u'B',
u'C', u'A', u'C', u'D'], [u'A', u'B', u'C', u'A', u'C', u'D'], [u'A',
u'B', u'C', u'A', u'C', u'D'], [u'A', u'B', u'C', u'A', u'C', u'D']]
[[u'A', u'B', u'C', u'A', u'C', u'D']])
TexasTree = SkyTree
if TexasTree:
TexasTree.sort()
last = TexasTree[-1]
for i in range(len(TexasTree)-2, -1, -1):
if last == TexasTree[i]:
del TexasTree[i]
else:
last = TexasTree[i]
print TexasTree
( This is my final result. [[u'A', u'B', u'C', u'A', u'C', u'D']]) I am
utterly lost at this point.
So to summerize i am trying to to do this
Spreadsheet 1 Spreadsheet 2 Master Final
Sheet
Trees Location Birds Trees Location Birds Trees
Location Birds
1A A,B A:B:C 1A A,B A:D:C 1A
A,B A:B:C:D
2B A,B C:A:B 2B A,B A:B:D 2B
A,B A:B:C:D
3C A,B C:B:A 3C A,B D:B:C 3C
A,B A:B:C:D
BUT this will be used on tens of thousands of lines of data. It will also
have certain feilds like Tree height, Bird Color, ect.

No comments:

Post a Comment