Guest User

Untitled

a guest
Dec 18th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. import arcpy
  2. import os
  3. import csv
  4. import time
  5. import shutil
  6.  
  7.  
  8. def compareLists(listOne, listTwo,):
  9.  
  10. notInList = [item for item in listOne if item not in listTwo]
  11. print "Lists compared wp"
  12. return notInList
  13. ## for item in listOne:
  14. ## i += 1
  15. ## if (item not in listTwo) and (str(item) != "None"):
  16. ## j += 1
  17. ## elif str(item) == "None":
  18. ## j += 1
  19. ## writer.writerow(["<Null>",])
  20.  
  21.  
  22. def compareDicts(dictOne, dictTwo):
  23. #should build a dictionary, no?
  24. #For some reason, the results for this are different when
  25. #dictOne is swapped with dictTwo. Why?
  26. dictCompare = {}
  27. for item in dictOne:
  28. areaMoreThan1Percent = ""
  29. lengthMoreThan1Percent = ""
  30. if item in dictTwo:
  31. if not (dictOne[item][0] < (dictTwo[item][0] * 1.01) and
  32. (dictOne[item][0] > 0.99)):
  33. areaMoreThan1Percent = "Check Area"
  34. if not (dictOne[item][1] < (dictTwo[item][1] * 1.01) and
  35. (dictOne[item][1] > 0.99)):
  36. lengthMoreThan1Percent = "Check Length"
  37. if areaMoreThan1Percent or lengthMoreThan1Percent:
  38. dictCompare.update({item: [areaMoreThan1Percent,
  39. lengthMoreThan1Percent] +
  40. dictOne[item]})
  41. print "Done with what's in {} and not {}".format(compareNameOne,
  42. compareNameTwo)
  43. return dictCompare
  44.  
  45. #Making a FC to cut things down to the relevant records
  46. Directory = r"U:Temp Connections"
  47.  
  48. # Calculate date, time, and FGDB name
  49. date = time.strftime('%Y %m %d %H %M %S')
  50. GDB_Name = date + '_NewFootprints.gdb'
  51.  
  52. # Create a new FileGDB
  53. arcpy.CreateFileGDB_management(Directory, GDB_Name)
  54.  
  55. # Set to path of created FileGDB
  56. GDB = os.path.join(Directory, GDB_Name)
  57.  
  58. connection_name = "Real enterprise path"
  59. database_platform = "SQL_SERVER"
  60. instance = "realInstance"
  61. authentication = "correctAuthForm"
  62. username = "RightUserName"
  63. password = "CorrectPassword"
  64. savePW = "SAVE_USERNAME"
  65. database = "SolidDatabase"
  66.  
  67. # Look for folder to put Prod Connection into
  68. if not os.path.isdir(Directory):
  69. os.path.makedirs(Directory)
  70.  
  71. # Look for Prod connection and create if absent
  72. if not os.path.isfile(os.path.join(Directory, connection_name)):
  73. print ("Making connection file")
  74. arcpy.CreateDatabaseConnection_management(Directory,
  75. connection_name,
  76. database_platform,
  77. instance,
  78. authentication,
  79. username,
  80. password,
  81. savePW,
  82. database)
  83.  
  84. easyFDS = r"realFeatureDataset"
  85. FeatureClass = r"realFeatureClass"
  86. FullPathFC = os.path.join(Directory, connection_name, easyFDS, FeatureClass)
  87. sr = arcpy.Describe(FullPathFC).spatialReference
  88.  
  89. # Create new FDS for fc
  90. arcpy.CreateFeatureDataset_management(GDB,
  91. "someStuff",
  92. sr)
  93.  
  94. # Get file path of FDS in created FileGDB
  95. newFDS = os.path.join(GDB, "someStuff")
  96.  
  97. print ("New File GDB and feature dataset have been created")
  98.  
  99. difficultFC = os.path.join(r"first half of the connection path",
  100. r"second half of the connection path")
  101. easyFC = os.path.join(r"first half of the connection path",
  102. r"Second half of the other connection path"
  103. )
  104. anotherFCForTheHardOne = r"rightConnectionPathForThis"
  105.  
  106.  
  107. inFeaturesList = [hardFC, anotherFCForTheHardOne]
  108. outFeatureClass = os.path.join(newFDS,"The Right Stuff")
  109.  
  110. arcpy.Intersect_analysis(inFeaturesList, outFeatureClass)
  111. print "Intersect ran"
  112.  
  113. #list and dict comprehensions
  114. easyFC = os.path.join(r"first half of the connection path",
  115. r"Second half of the other connection path"
  116. )
  117. easyFields = ["common","OBJECTID","SHAPE.STArea()","SHAPE.STLength()"]
  118. #Dunno if we're using OWNER_NUMBER
  119. easyFieldsDict = ["common","OBJECTID","SHAPE.STArea()","SHAPE.STLength()",
  120. "Field0", "Field1", "Field2", "Field3",
  121. "Field3", "Field4","Field5",
  122. "Field6", "Field7", "Field8", "Field9"]
  123. easyList = [[str(row[0]),str(row[4]), str(row[5]), str(row[6]),
  124. str(row[7]), str(row[8]), str(row[9]),str(row[10]),
  125. str(row[11]), str(row[12]),str(row[13])]
  126. for row in arcpy.da.SearchCursor(easyFC,
  127. easyFieldsDict)]
  128. easyDict = {str(row[0]): [float(row[2]), float(row[3])] for row in
  129. arcpy.da.SearchCursor(easyFC, easyDict)}
  130. print "Done with easy List"
  131.  
  132. hardFC = outFeatureClass
  133. hardFields = ["common","OBJECTID","Shape_Area","Shape_Length"]
  134. hardFieldsDict = ["common","OBJECTID","Shape_Area","Shape_Length"]
  135. hardList = [str(row[0]) for row in arcpy.da.SearchCursor(hardFC, hardFields)]
  136. hardDict = {str(row[0]): [float(row[2]) ,float(row[3])] for row in
  137. arcpy.da.SearchCursor(hardFC, hardFieldsDict)}
  138. moreData = r"Correct connection path"
  139. moreDataFields = ["common", "OBJECTID", "Field0", "Field1", "Field2",
  140. "Field3", "Field4", "Field5", "Field6", "Field7",
  141. "Field8", "Field9"]
  142.  
  143. #This takes forever.
  144. #This one bit seems to be taking forever. What did I do!?
  145.  
  146. hardList = [[str(row[0]), str(row[1]), str(row[2]), str(row[11]),str(row[3]),
  147. str(row[4]), str(row[5]), str(row[6]), str(row[7]), str(row[8]),
  148. str(row[9]), str(row[10])] for item in lCADList for row in
  149. arcpy.da.SearchCursor(moreData, moreDataFields,
  150. "common = '{}'".format(item))]
  151. print "hardList made"
Add Comment
Please, Sign In to add comment