outputShapefile= os.path.splitext(inRaster)[0] + "_thr" + str(i) + "_" + str(minHa).replace('.','p') + "ha.shp" whereClause = '"Area_ha" >=' + minHa waterSql = '"Value" > 0 AND "Value" <=' + int(i) # Process: Con (needs spatial analyst license) outCon = Con(inRaster, 1, 0 , waterSql) outCon.save("outCon") arcpy.AddMessage("Open flood extent map is created (raster)") # Process: Focal Statistics (5x5 Mode) outFocalStats = FocalStatistics(outCon, "Rectangle 5 5 CELL", "MAJORITY", "DATA") outFocalStats.save("outFocalStats") arcpy.AddMessage("Image is filtered") # Process: Convert Raster to Polygon arcpy.RasterToPolygon_conversion(outFocalStats, "Raster2poly.shp", "NO_SIMPLIFY", "") arcpy.AddMessage("Converted to vector") # Process: Select Gridcode >0 arcpy.Select_analysis("Raster2poly.shp", "Raster2polyCode0.shp", "GRIDCODE >0") # Process: Add Field to Calculate Area arcpy.AddField_management("Raster2polyCode0.shp", "Area_ha", "FLOAT", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field: Area in Ha arcpy.CalculateField_management("Raster2polyCode0.shp", "Area_ha", "!Shape!.area/10000", "PYTHON_9.3", "") arcpy.AddMessage("Area calculated (ha) for flooded polygons") # Process: Select min polygon size arcpy.Select_analysis("Raster2polyCode0.shp", outputShapefile, whereClause) arcpy.AddMessage("Applying the minimum hectare size") # Process: Delete intermediate files arcpy.Delete_management("outCon", "") arcpy.Delete_management("outFocalStats", "") arcpy.Delete_management("Raster2poly.shp", "") arcpy.Delete_management("Raster2polyCode0.shp", "") arcpy.AddMessage("Intermediate files deleted")
edit your original post and throw the script within code blocks (the # symbol in the html editor)
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.