Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. self.x = pythonaddins.GetSelectedTOCLayerOrDataFrame() #Sets FC on different button
  2.  
  3. fc = str(button2.x)
  4. cursor = arcpy.da.InsertCursor( fc, ["SHAPE@"])
  5. array = arcpy.Array(vertices)
  6. simpleBuilding = arcpy.Polygon(array)
  7. cursor.insertRow([simpleBuilding])
  8.  
  9. One or more layers failed to draw:
  10. FDO error 0: [Failed to label layer
  11. databaseVersionDBO for class Defaut.}
  12. The requested operation is invalid on a closed state
  13. [database]
  14.  
  15. in onClick
  16. edit = arcpy.da.Editor(workspace)
  17. RuntimeError: cannot open workspace
  18.  
  19. import arcpy
  20. import pythonaddins
  21. import os
  22. import math
  23. import sys
  24.  
  25. class setCenterpoint(object):
  26. """Implementation for leetScripts_addin.tool (Tool)"""
  27. def __init__(self):
  28. self.enabled = True
  29. self.cursor = 3
  30. #selects a point on the map
  31. def onMouseDownMap(self, x, y, button, shift):
  32. print "onMouseDowMap executing"
  33. setCenterpoint.enabled = True
  34. self.x = x
  35. self.y = y
  36. print "Selected point is at %r, %r" % (self.x, self.y)
  37. pass
  38. return self.x
  39. return self.y
  40.  
  41.  
  42. class setArea(object):
  43. """Implementation for leetScripts_addin.combobox (ComboBox)"""
  44. def __init__(self):
  45. self.editable = True
  46. self.enabled = True
  47. #self.dropdownWidth = ''
  48. self.width = 'WWWWWWWWW'
  49. #Takes user input Area and returns half the side length of the square
  50. def onEditChange(self,text) :
  51. squareFeet = text
  52. self.buffDist = (math.sqrt(float(squareFeet))/2)
  53. print "Square size: %r ft^2 Buffer Distance: %r ft^2" % (squareFeet,
  54. self.buffDist)
  55. return self.buffDist
  56. pass
  57.  
  58. #This is supposed to be how you select the feature class, but right now
  59. #it doesn't do anything for debugging purposes.
  60. class SeltLayer(object):
  61. """Implementation for leetScripts_addin.button2 (Button)"""
  62. def __init__(self):
  63. self.enabled = True
  64. self.checked = False
  65. def onClick(self):
  66. #need the input as a string not a class layer.
  67. self.x = pythonaddins.GetSelectedTOCLayerOrDataFrame()
  68. print "Selected filepath is: %r" % self.x.dataSource
  69. print "filepath is %r type" % type(self.x.dataSource)
  70. pass
  71.  
  72.  
  73. class buildingTool(object):
  74. """Implementation for leetScripts_addin.button (Button)"""
  75. def __init__(self):
  76. self.enabled = True
  77. self.checked = False
  78. def onClick(self):
  79. print "building tool button is executing"
  80. #Variables for Creating the polygon
  81. xCoordinate = float(tool.x)
  82. yCoordinate = float(tool.y)
  83. bob = float(combobox.buffDist)
  84. #fc = str(button2.x.dataSource) was used to get featureclass info
  85. fc = r"realfulldatabasepathrealnextpartrealpolygonlayer"
  86.  
  87. outFolderPath = r"U:tempStuff"
  88. outName = r"actualName"
  89. databasePlatform = "SQL_Server"
  90. instance = "realinstance"
  91. username = "myusername"
  92. password = "authenticpassword"
  93. version = "myVersionName"
  94. arcpy.CreateDatabaseConnection_management(outFolderPath, outName,
  95. databasePlatform,
  96. instance,
  97. 'DATABASE_AUTH',
  98. username, password,
  99. 'DO_NOT_SAVE_USERNAME',
  100. 'instancenameagain',
  101. '','TRANSACTIONAL',
  102. version,)
  103. print "Centroid of buidling:(%r,%r) Side length: %r" % (xCoordinate,
  104. yCoordinate,
  105. bob)
  106. def doStuff():
  107. #Calculates and creates an array of vertex points, opens an
  108. #insert cursor, creates a polygon using the arra, and inserts
  109. #building into the appropriate database. This works fine in file
  110. #geodatabase
  111. vertices = []
  112. vertices.append(arcpy.Point((xCoordinate + bob), (yCoordinate + bob)))
  113. vertices.append(arcpy.Point((xCoordinate + bob), (yCoordinate - bob)))
  114. vertices.append(arcpy.Point((xCoordinate - bob), (yCoordinate - bob)))
  115. vertices.append(arcpy.Point((xCoordinate - bob), (yCoordinate + bob)))
  116. vertices.append(arcpy.Point((xCoordinate + bob), (yCoordinate + bob)))
  117.  
  118. cursor = arcpy.da.InsertCursor( fc, ["SHAPE@"])
  119. array = arcpy.Array(vertices)
  120. simpleBuilding = arcpy.Polygon(array)
  121. cursor.insertRow([simpleBuilding])
  122.  
  123.  
  124. del cursor
  125. print "Building should be drawn"
  126.  
  127. desc = arcpy.Describe(fc)
  128. print "%r" % desc
  129. sde = desc.catalogPath.find('.sde')
  130.  
  131. #Checks for .sde versions code provided by BenSNadler.
  132. #arcpy.Describe().isVersioned needs dataset input
  133. if sde != -1 and desc.isVersioned:
  134. workspace = desc.catalogPath#problem opening workspace
  135. print workspace
  136. #Start editing
  137. print "initiating editing"
  138. edit = arcpy.da.Editor(workspace)
  139. edit.startEditing(True, True)
  140. edit.startOperation()
  141.  
  142. #soon to be function's name
  143. doStuff()
  144. print "made it past function call."
  145.  
  146. #Stop/save edits
  147. edit.stopOperation()
  148. print "Stopping editing"
  149. edit.stopEditing(True)
  150. #if no versions then the function runs without using the
  151. #connection
  152. else:
  153. print "made it to else statemenet"
  154. doStuff()
  155. print "made it past function call"
  156.  
  157. desc = arcpy.Describe(fc)
  158. sde = desc.catalogPath.find('.sde') #if SDE this will return a value
  159. #If in sde AND is Versioned, use editor start/stop
  160. if sde != -1 and desc.isVersioned:
  161. #get the connection information
  162. workspace = desc.catalogPath
  163. #Start editing
  164. print "Initiating editing"
  165. edit = arcpy.da.Editor (workspace)
  166. edit.startEditing ()
  167. edit.startOperation()
  168.  
  169. DO STUFF
  170.  
  171. #Stop/save edits
  172. edit.stopOperation()
  173. print "Stopping editing"
  174. edit.stopEditing("True")
  175. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement