I am attempting to iterate a process using spatial analyst tools which seems to be causing some type of data lock type error that I am struggling to work around. I am attempting to perform an analysis on building roofs (identified by the ‘BIN’ (Building ID Number) value referenced in the code) using point elevation readings captured from lidar. The data throughout the project is stored in a series file geodatabases. Each iteration in the for loop is supposed to copy the source lidar points (which have been previously converted to vector) and polyline outline of the building footprint into a working geodatabase, where several geoprocessing tools are run. Once the iteration is complete, the database is cleared out (currently deletes entire GDB, but that was implemented as a failed work around) when finished. The analysis always seems to work as intended on the first iteration, but on the second iteration all the data copied into the workspace GDB ends up being empty geometry. The empty geometry then causes any following geoprocessing to fail. This has occurred in both python 2 and 3 as well as in ArcMap, ArcPro and stand-alone python (where it’s intended to be run). I’ve tried the initial copy into the workspace GDB via feature class to feature class, making a layer selecting and ‘copy’ and ‘copy feature’, copying xy coordinates and building the elevation points from scratch (which took too long to use), as well as copying each BIN to it’s own feature class and just being pointed via a python list. I’ve tested the script by commenting out the spatial analysis and the workspace copies work as intended, leading me to think it’s something about the spatial analyst tools causing it. I’ve also built python processes of this scale in the past using strictly vector, and never encountered this before. I’ve checked the source GDB to make sure there are no open cursors, and have found none. Has anyone encountered something like this before?
For context, this is the project I'm working on
Here’s my code (sorry it’s kind of a mess):
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> sys
<SPAN class="keyword token">import</SPAN> traceback
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Spatial"</SPAN><SPAN class="punctuation token">)</SPAN>
outputGbd <SPAN class="operator token">=</SPAN> <SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting\\TestFinal.gdb'</SPAN> <SPAN class="comment token">#TODO</SPAN>
tileOutlineAllFeature <SPAN class="operator token">=</SPAN> <SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting\\BadHouse.gdb\\Tile_26875E244534N'</SPAN>
tileOutlineAll <SPAN class="operator token">=</SPAN> <SPAN class="string token">'tileOutlineAllLayer'</SPAN>
tileOutlineCurrentFeature <SPAN class="operator token">=</SPAN> <SPAN class="string token">'tileOutlineCurrent'</SPAN>
tileOutlineCurrent <SPAN class="operator token">=</SPAN> <SPAN class="string token">'tileOutlineCurrentLayer'</SPAN>
<SPAN class="comment token">#currentTileFeature = 'F:\\Lidar\\lidar_2018\\RearRoofTesting\\ExportForTesting2.gdb\\Tile_26875E244534N' #TODO create this-->This is the lidar points for current tile</SPAN>
<SPAN class="comment token">#currentTile = 'currentTileLayer'</SPAN>
<SPAN class="comment token">#buildingFootprintsAllFeature = 'F:\\Lidar\\LiDARAnalysis\\Footprints.gdb\\LI_BUILDING_FOOTPRINTS' #TODO update this to footprints layer used for lidar</SPAN>
buildingFootprintsAllFeature <SPAN class="operator token">=</SPAN> <SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting\\BuildingFootprints.gdb\\TestBuildingsWithVios'</SPAN> <SPAN class="comment token">#TODO Delete after testing</SPAN>
buildingFootprintsAll <SPAN class="operator token">=</SPAN> <SPAN class="string token">'buildingFootprintsAllLayer'</SPAN>
buildingFootprintsFeature <SPAN class="operator token">=</SPAN> <SPAN class="string token">'buildingFootprintsCurrent'</SPAN>
buildingPointsFeature <SPAN class="operator token">=</SPAN> <SPAN class="string token">'CurrentInputBuildingPoints'</SPAN>
<SPAN class="comment token">#buildingFootprintsFeature = 'BIN_1009464_Footprint'</SPAN>
buildingFootprints <SPAN class="operator token">=</SPAN> <SPAN class="string token">'buildingFootprintsLayer'</SPAN>
outputPoints <SPAN class="operator token">=</SPAN> outputGbd <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\\HoleFlags'</SPAN>
<SPAN class="comment token">#outputPoints = 'HoleFlags'</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>tileOutlineAllFeature<SPAN class="punctuation token">,</SPAN> tileOutlineAll<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>buildingFootprintsAllFeature<SPAN class="punctuation token">,</SPAN> buildingFootprintsAll<SPAN class="punctuation token">)</SPAN>
tileResult <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>tileOutlineAllFeature<SPAN class="punctuation token">)</SPAN>
tileCount <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>tileResult<SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tileCursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>tileOutlineAll<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'FileName'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">rasterizeRoof</SPAN><SPAN class="punctuation token">(</SPAN>currentBuilding<SPAN class="punctuation token">,</SPAN> bin<SPAN class="punctuation token">,</SPAN> binPoints<SPAN class="punctuation token">,</SPAN> workspace<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Working Variables</SPAN>
binPointsName <SPAN class="operator token">=</SPAN> <SPAN class="string token">'BIN_'</SPAN> <SPAN class="operator token">+</SPAN> bin
minB <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_MinB'</SPAN>
minBRaster <SPAN class="operator token">=</SPAN> minB <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_Rast'</SPAN>
zonalStats <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_ZonalStats'</SPAN>
roofZoneFeature <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_RoofZones'</SPAN>
roofZones <SPAN class="operator token">=</SPAN> <SPAN class="string token">'RoofZonesLayer'</SPAN>
roofZoneVertFeature <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_RoofZoneVerts'</SPAN>
roofZoneVerts <SPAN class="operator token">=</SPAN> <SPAN class="string token">'roofZoneVertsLayer'</SPAN>
roofZoneCurrent <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_RoofZoneCurrent'</SPAN>
<SPAN class="comment token"># Output Variables</SPAN>
outputGbd <SPAN class="operator token">=</SPAN> <SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting\\TestFinal.gdb'</SPAN>
outputPoints <SPAN class="operator token">=</SPAN> outputGbd <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\\HoleFlags'</SPAN> <SPAN class="comment token"># TODO Temp</SPAN>
idw <SPAN class="operator token">=</SPAN> Idw<SPAN class="punctuation token">(</SPAN>binPoints<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'POINT_Z'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'0.5'</SPAN><SPAN class="punctuation token">,</SPAN> in_barrier_polyline_features<SPAN class="operator token">=</SPAN><SPAN class="string token">"BIN_"</SPAN> <SPAN class="operator token">+</SPAN> bin <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_Outline"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"BIN_"</SPAN> <SPAN class="operator token">+</SPAN> bin <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_Outline"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create Slope Raster Of Roof</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Slope Analysis'</SPAN><SPAN class="punctuation token">)</SPAN>
slope <SPAN class="operator token">=</SPAN> Slope<SPAN class="punctuation token">(</SPAN>idw<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'PERCENT_RISE'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'GEODESIC'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Use Con to create a raster representing areas of the idw that do not have a slope of 90 and are within the minimum bounds.</SPAN>
<SPAN class="comment token"># This Raster will only have a value of 1 as a constant for the Region Group Prcoess</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Con Analysis'</SPAN><SPAN class="punctuation token">)</SPAN>
rawGroups <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>slope <SPAN class="operator token"><</SPAN> <SPAN class="number token">90</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">&</SPAN> <SPAN class="operator token">~</SPAN>IsNull<SPAN class="punctuation token">(</SPAN>minBRaster<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Clean the Boundaries to eliminate any small cells</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Boundary Clean'</SPAN><SPAN class="punctuation token">)</SPAN>
rawGroupsClean <SPAN class="operator token">=</SPAN> BoundaryClean<SPAN class="punctuation token">(</SPAN>rawGroups<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'ONE_WAY'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Region group all isolated sections of roof elevation</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Region Group'</SPAN><SPAN class="punctuation token">)</SPAN>
groups <SPAN class="operator token">=</SPAN> RegionGroup<SPAN class="punctuation token">(</SPAN>rawGroupsClean<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'FOUR'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'WITHIN'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Zonal Statistics to find elevation stats for each group</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Zonal Statistics'</SPAN><SPAN class="punctuation token">)</SPAN>
ZonalStatisticsAsTable<SPAN class="punctuation token">(</SPAN>groups<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Value'</SPAN><SPAN class="punctuation token">,</SPAN> idw<SPAN class="punctuation token">,</SPAN> zonalStats<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Convert to vector polygons and delineate the "Large" sections (over 25 ft)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Converting back to vector'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RasterToPolygon_conversion<SPAN class="punctuation token">(</SPAN>groups<SPAN class="punctuation token">,</SPAN> roofZoneFeature<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'SIMPLIFY'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Value'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>roofZoneFeature<SPAN class="punctuation token">,</SPAN> roofZones<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Large_Section'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'SHORT'</SPAN><SPAN class="punctuation token">)</SPAN>
idLargeCursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Shape_Area'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Large_Section'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> idLargeCursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">25</SPAN><SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
idLargeCursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> idLargeCursor
<SPAN class="comment token"># Delete all raster related datasets</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>minB<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>minBRaster<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>idw<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>slope<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>rawGroups<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>rawGroupsClean<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>groups<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Pull height stats for roof zones into a dictionary</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Pulling stats'</SPAN><SPAN class="punctuation token">)</SPAN>
statCursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>zonalStats<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Value'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MIN'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MAX'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MEAN'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
statDict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> list<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> statCursor<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">del</SPAN> statCursor
<SPAN class="comment token"># Create feature class and layer of roof zone vertices</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Feature Vertices to Points'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureVerticesToPoints_management<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">,</SPAN> roofZoneVertFeature<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Making Feature Layer'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>roofZoneVertFeature<SPAN class="punctuation token">,</SPAN> roofZoneVerts<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Iterate through all "small" roof zones (under 25 Ft), these "small" zones are believed to represent roof holes</SPAN>
hCursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'gridcode'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Large_Section'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> hCursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Roof Section '</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">is</SPAN> None<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Analysing small section'</SPAN><SPAN class="punctuation token">)</SPAN>
currentMIN <SPAN class="operator token">=</SPAN> statDict<SPAN class="punctuation token">[</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
currentMAX <SPAN class="operator token">=</SPAN> statDict<SPAN class="punctuation token">[</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
currentMEAN <SPAN class="operator token">=</SPAN> statDict<SPAN class="punctuation token">[</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
evalList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> k<SPAN class="punctuation token">,</SPAN> v <SPAN class="keyword token">in</SPAN> statDict<SPAN class="punctuation token">.</SPAN>items<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> k <SPAN class="operator token">!=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> currentMAX <SPAN class="operator token"><</SPAN> v<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN>
evalList<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>k<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> evalList<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Nothing to evaluate'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">continue</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"gridcode = "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByLocation_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'WITHIN_A_DISTANCE'</SPAN><SPAN class="punctuation token">,</SPAN> roofZones<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'5 Feet'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Remove vertices from self and those that are lower in elevation</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'REMOVE_FROM_SELECTION'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"gridcode = "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">" or gridcode in ("</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">', '</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>
evalList<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">")"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Near Analysis to find angles from current section's center to selected vertices</SPAN>
angleCount <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> angleCount <SPAN class="operator token"><=</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Not enough angles'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">continue</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureToPoint_management<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">,</SPAN> roofZoneCurrent<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Near_analysis<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">,</SPAN> roofZoneCurrent<SPAN class="punctuation token">,</SPAN> location<SPAN class="operator token">=</SPAN><SPAN class="string token">'LOCATION'</SPAN><SPAN class="punctuation token">,</SPAN> angle<SPAN class="operator token">=</SPAN><SPAN class="string token">'ANGLE'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Calculate range between min and max angles ( > 180 representing a hole)</SPAN>
rangeCursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NEAR_ANGLE'</SPAN><SPAN class="punctuation token">,</SPAN>
sql_clause<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">(</SPAN>None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ORDER BY NEAR_ANGLE"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
firstRow <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
angleMIN <SPAN class="operator token">=</SPAN> None
angleMAX <SPAN class="operator token">=</SPAN> None
rangeCount <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">for</SPAN> angle <SPAN class="keyword token">in</SPAN> rangeCursor<SPAN class="punctuation token">:</SPAN>
rangeCount <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">if</SPAN> firstRow <SPAN class="keyword token">is</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">:</SPAN>
angleMIN <SPAN class="operator token">=</SPAN> angle<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
firstRow <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
<SPAN class="keyword token">if</SPAN> rangeCount <SPAN class="operator token">==</SPAN> angleCount<SPAN class="punctuation token">:</SPAN>
angleMAX <SPAN class="operator token">=</SPAN> angle<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">del</SPAN> rangeCursor
<SPAN class="comment token"># Calculate range in angles</SPAN>
angleRange <SPAN class="operator token">=</SPAN> angleMAX <SPAN class="operator token">-</SPAN> angleMIN
<SPAN class="keyword token">if</SPAN> angleRange <SPAN class="operator token">>=</SPAN> <SPAN class="number token">180</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Found Possible hole'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Add building point to output, delete all related features for analysis and continue to next building</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureToPoint_management<SPAN class="punctuation token">(</SPAN>currentBuilding<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'in_memory\\BIN_'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>bin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Append_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'in_memory\\BIN_'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>bin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> outputPoints<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NO_TEST'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'in_memory\\CurrentBuilding'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'in_memory\\BIN_'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>bin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Delete all analysis related feature classes</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>zonalStats<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneVertFeature<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneCurrent<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># arcpy.Delete_management(binPoints)</SPAN>
<SPAN class="comment token"># arcpy.Delete_management(currentTile)</SPAN>
<SPAN class="comment token"># arcpy.Delete_management(currentBuilding)</SPAN>
<SPAN class="keyword token">break</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Clear selections and current zone centroid and continue on current building</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneCurrent<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'CLEAR_SELECTION'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'CLEAR_SELECTION'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> hCursor
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Exited Loop'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Delete all analysis related feature classes</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>zonalStats<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZones<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneVertFeature<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneVerts<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>roofZoneCurrent<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># arcpy.Delete_management(binPoints)</SPAN>
<SPAN class="keyword token">del</SPAN> binPoints
<SPAN class="comment token"># arcpy.Delete_management(currentTile)</SPAN>
<SPAN class="comment token"># arcpy.Delete_management(currentBuilding)</SPAN>
<SPAN class="keyword token">del</SPAN> minB
<SPAN class="keyword token">del</SPAN> minBRaster
<SPAN class="keyword token">del</SPAN> zonalStats
<SPAN class="keyword token">del</SPAN> roofZoneFeature
<SPAN class="keyword token">del</SPAN> roofZones
<SPAN class="keyword token">del</SPAN> roofZoneVertFeature
<SPAN class="keyword token">del</SPAN> roofZoneVerts
<SPAN class="keyword token">del</SPAN> roofZoneCurrent
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#Scroll through tile outlines to perform analysis on tile by tile basis</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Begining Tile Cursor'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> tile <SPAN class="keyword token">in</SPAN> tileCursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>tile<SPAN class="punctuation token">)</SPAN>
currentTileFeature <SPAN class="operator token">=</SPAN> <SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\ExportForTesting2.gdb\\Tile_'</SPAN> <SPAN class="operator token">+</SPAN> tile<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>rstrip<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'.las'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#TODO Update to production path</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>outputCoordinateSystem <SPAN class="operator token">=</SPAN> currentTileFeature
<SPAN class="comment token">#TODO append Surrounding Tiles</SPAN>
<SPAN class="comment token">#Select out all BINS in tile for analysis</SPAN>
tileBINCursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>buildingFootprintsAll<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'BIN'</SPAN><SPAN class="punctuation token">,</SPAN> where_clause<SPAN class="operator token">=</SPAN><SPAN class="string token">"FileName = '"</SPAN> <SPAN class="operator token">+</SPAN> tile<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#tileBINList = list(set([r[0] for r in tileBINCursor]))#TODO This will be pulled from the lidar source in production</SPAN>
tileBINList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'1019616'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'1064332'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token">#TODO temp BIN input for testing</SPAN>
<SPAN class="keyword token">del</SPAN> tileBINCursor
binCount <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">for</SPAN> bin <SPAN class="keyword token">in</SPAN> tileBINList<SPAN class="punctuation token">:</SPAN>
binCount <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">if</SPAN> bin <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token">#TODO Use for already processed BINs in testing, remove line for prod</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Starting BIN '</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>bin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Create Local Workspace for each iteration</SPAN>
workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting\\WorkspaceGDB.gdb'</SPAN>
<SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CreateFileGDB_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'WorkspaceGDB'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> workspace
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token">#Local Variables</SPAN>
binPointsName <SPAN class="operator token">=</SPAN> <SPAN class="string token">'BIN_'</SPAN> <SPAN class="operator token">+</SPAN> bin
<SPAN class="comment token">#binPoints = 'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting\\BinLidar.gdb\\' + binPointsName</SPAN>
binPoints <SPAN class="operator token">=</SPAN> binPointsName
currentBuilding <SPAN class="operator token">=</SPAN> <SPAN class="string token">'F:\\Lidar\\lidar_2018\\RearRoofTesting\\lidartesting\\BuildingFootprints.gdb\\BIN_'</SPAN><SPAN class="operator token">+</SPAN>bin
minB <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_MinB'</SPAN>
minBRaster <SPAN class="operator token">=</SPAN> minB <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_Rast'</SPAN>
zonalStats <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_ZonalStats'</SPAN>
roofZoneFeature <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_RoofZones'</SPAN>
roofZones <SPAN class="operator token">=</SPAN> <SPAN class="string token">'RoofZonesLayer'</SPAN>
roofZoneVertFeature <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_RoofZoneVerts'</SPAN>
roofZoneVerts <SPAN class="operator token">=</SPAN> <SPAN class="string token">'roofZoneVertsLayer'</SPAN>
roofZoneCurrent <SPAN class="operator token">=</SPAN> binPointsName <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_RoofZoneCurrent'</SPAN>
<SPAN class="comment token"># Copy Building Outline and elevation points to workspace</SPAN>
currentTile <SPAN class="operator token">=</SPAN> <SPAN class="string token">'currentTileLayer'</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>currentTileFeature<SPAN class="punctuation token">,</SPAN> currentTile<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureToLine_management<SPAN class="punctuation token">(</SPAN>currentBuilding<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BIN_"</SPAN> <SPAN class="operator token">+</SPAN> bin <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_Outline"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>currentTile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BIN = '"</SPAN> <SPAN class="operator token">+</SPAN> bin <SPAN class="operator token">+</SPAN> <SPAN class="string token">"' AND BUILDING_PERIMETER IS NULL"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureClassToFeatureClass_conversion<SPAN class="punctuation token">(</SPAN>currentTile<SPAN class="punctuation token">,</SPAN> workspace<SPAN class="punctuation token">,</SPAN> binPoints<SPAN class="punctuation token">)</SPAN>
<SPAN class="string token">""</SPAN>"
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Starting Point Extraction'</SPAN><SPAN class="punctuation token">)</SPAN>
pointCursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>currentTile<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'POINT_X'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'POINT_Y'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'POINT_Z'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
pointList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> pointCursor<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">del</SPAN> pointCursor
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Inserting Points'</SPAN><SPAN class="punctuation token">)</SPAN>
pointCount <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>currentTile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>exists<SPAN class="punctuation token">(</SPAN>binPoints<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">and</SPAN> int<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>binPoints<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> pointCount<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Point Layer Exists'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">continue</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CreateFeatureclass_management<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN> binPoints<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'POINT'</SPAN><SPAN class="punctuation token">,</SPAN> currentTile<SPAN class="punctuation token">,</SPAN> has_z<SPAN class="operator token">=</SPAN><SPAN class="string token">'SAME_AS_TEMPLATE'</SPAN><SPAN class="punctuation token">)</SPAN>
count <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
breaks <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>int<SPAN class="punctuation token">(</SPAN>float<SPAN class="punctuation token">(</SPAN>pointCount<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> float<SPAN class="punctuation token">(</SPAN>b<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">/</SPAN> <SPAN class="number token">100.0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> b <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">100</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> point <SPAN class="keyword token">in</SPAN> pointList<SPAN class="punctuation token">:</SPAN>
count <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">if</SPAN> count <SPAN class="keyword token">in</SPAN> breaks<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Appending Points '</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>count<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'% Complete'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Append_management<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>PointGeometry<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> point<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> point<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> binPoints<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NO_TEST'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> pointList
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>binPointsName<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>currentTile<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Bin Points Selected'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>desc<SPAN class="punctuation token">.</SPAN>FIDset<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#arcpy.MakeFeatureLayer_management(currentTile, binPoints)#TODO Testing ->Hoping to keep</SPAN>
<SPAN class="string token">""</SPAN>"
<SPAN class="comment token"># Establish Minimum Bounds For Processing On BIN</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Establishing Minimum Bounds'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MinimumBoundingGeometry_management<SPAN class="punctuation token">(</SPAN>binPoints<SPAN class="punctuation token">,</SPAN> minB<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'CONVEX_HULL'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>PolygonToRaster_conversion<SPAN class="punctuation token">(</SPAN>minB<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'OBJECTID'</SPAN><SPAN class="punctuation token">,</SPAN> minBRaster<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'MAXIMUM_AREA'</SPAN><SPAN class="punctuation token">,</SPAN> cellsize<SPAN class="operator token">=</SPAN><SPAN class="string token">'0.5'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Set Raster Environments based off minimum bounds raster</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>cellSize <SPAN class="operator token">=</SPAN> minBRaster
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>snapRaster <SPAN class="operator token">=</SPAN> minBRaster
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> minBRaster
<SPAN class="comment token">###Create Roof Zones to compare heights####</SPAN>
<SPAN class="comment token">#Create IDW Raster of Roof Elevations</SPAN>
<SPAN class="comment token">#arcpy.SelectLayerByAttribute_management(buildingFootprintsAll, 'NEW_SELECTION', "BIN = '" + str(bin) + "'")</SPAN>
<SPAN class="comment token">#print('Bin Outline Selected')</SPAN>
<SPAN class="comment token">#desc = arcpy.Describe(buildingFootprintsAll)</SPAN>
<SPAN class="comment token">#print(desc.FIDset)</SPAN>
<SPAN class="comment token">#Extract XY Vertices from BIN Feature</SPAN>
<SPAN class="string token">"""
features = []
outlineCursor = arcpy.da.SearchCursor(buildingFootprintsAll, 'SHAPE@')
for b in outlineCursor:
for part in b:
features.append(arcpy.Polyline(arcpy.Array([[point.X, point.Y] for point in part])))
del outlineCursor
"""</SPAN>
<SPAN class="comment token">#arcpy.CopyFeatures_management(buildingFootprintsAll, currentBuilding)</SPAN>
<SPAN class="comment token">#arcpy.MakeFeatureLayer_management(buildingFootprintsAll, currentBuilding)</SPAN>
<SPAN class="comment token">#print(arcpy.GetCount_management(currentBuilding)[0])</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Beginning Raster Analysis'</SPAN><SPAN class="punctuation token">)</SPAN>
rasterizeRoof<SPAN class="punctuation token">(</SPAN>currentBuilding<SPAN class="punctuation token">,</SPAN> bin<SPAN class="punctuation token">,</SPAN> binPoints<SPAN class="punctuation token">,</SPAN> workspace<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Script Complete'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ExecuteError<SPAN class="punctuation token">:</SPAN>
tb <SPAN class="operator token">=</SPAN> sys<SPAN class="punctuation token">.</SPAN>exc_info<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
tbinfo <SPAN class="operator token">=</SPAN> traceback<SPAN class="punctuation token">.</SPAN>format_tb<SPAN class="punctuation token">(</SPAN>tb<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
pymsg <SPAN class="operator token">=</SPAN> <SPAN class="string token">"PYTHON ERRORS:\nTraceback info:\n"</SPAN> <SPAN class="operator token">+</SPAN> tbinfo <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\nError Info:\n"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>sys<SPAN class="punctuation token">.</SPAN>exc_info<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
msgs <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>msgs<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>pymsg<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
tb <SPAN class="operator token">=</SPAN> sys<SPAN class="punctuation token">.</SPAN>exc_info<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
tbinfo <SPAN class="operator token">=</SPAN> traceback<SPAN class="punctuation token">.</SPAN>format_tb<SPAN class="punctuation token">(</SPAN>tb<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
pymsg <SPAN class="operator token">=</SPAN> <SPAN class="string token">"PYTHON ERRORS:\nTraceback info:\n"</SPAN> <SPAN class="operator token">+</SPAN> tbinfo <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\nError Info:\n"</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>sys<SPAN class="punctuation token">.</SPAN>exc_info<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>pymsg<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>