Last active
August 27, 2016 12:18
-
-
Save dersteppenwolf/bd4721e41d4c01155e73165c0a31be08 to your computer and use it in GitHub Desktop.
Killing Godzillas using Arcpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
max_num_vertex = 250 | |
feature = "yourFeatureName" | |
dataset = "yourDatasetName" | |
sourceWorkspace= "C:/data/gdb/yourdata.gdb" | |
env.workspace = sourceWorkspace + '/' + dataset + '/' | |
layerSelection = "selectedLayer" | |
arcpy.MakeFeatureLayer_management(feature, layerSelection) | |
result = arcpy.GetCount_management(layerSelection) | |
resultValue = result.getOutput(0) | |
if int(resultValue) > 0: | |
# transform your geometries from multipart to singlepart | |
features_as_single_part = feature+"_SinglePart" | |
arcpy.MultipartToSinglepart_management(layerSelection, features_as_single_part) | |
# Dice your features | |
diceFeatures = feature+"_Dice" | |
arcpy.Dice_management(features_as_single_part, diceFeatures, max_num_vertex) | |
result = arcpy.GetCount_management(diceFeatures) | |
resultValue = result.getOutput(0) | |
logging.info("Number of new records : "+resultValue) | |
######################################################################### | |
## Replace your old data for the new one | |
arcpy.DeleteFeatures_management(layerSelection) | |
arcpy.Append_management(diceFeatures, layerSelection, "NO_TEST") | |
######################################################################### | |
# repair geometries | |
logging.debug("Sorry, some of your new geometries are invalid, let's fix them..") | |
arcpy.RepairGeometry_management (layerSelection) | |
logging.debug("Everything should be ok...") | |
######################################################################### | |
arcpy.Delete_management(features_as_single_part) | |
arcpy.Delete_management(diceFeatures) | |
except Exception as e: | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment