def export_bankfull(bf_group, counter, halfway_polys, ac_polys,
                    complete_polys):
    ##        arcpy.AddMessage("Exporting final copy")

    copy_features(bf_group, env.workspace, naming + "bankfull" + str(counter))

    if counter != 0:
        polys = os.path.join(env.workspace,
                             naming + "bankfull_polys" + str(counter))
        arcpy.AggregatePoints_cartography(bf_group, polys, "7.5 meters")
        arcpy.Append_management([polys], halfway_polys)

    else:
        halfway_polys = os.path.join(env.workspace,
                                     naming + "bankfull_polys" + str(counter))
        arcpy.AggregatePoints_cartography(bf_group, halfway_polys,
                                          "7.5 meters")

    #use fill gaps function to fill in gaps in the data
    points = os.path.join(env.workspace,
                          naming + "_slopepoints" + str(counter))

    if counter != 0:
        polys = fill_polygon_gaps(points, halfway_polys, ac_polys, counter)
        arcpy.Append_management([polys], complete_polys)

    else:
        complete_polys = fill_polygon_gaps(points, halfway_polys, ac_polys,
                                           counter)

    return halfway_polys, complete_polys
def fill_polygon_gaps(points, master_polys, ac_polys, counter):

    #calculate dist of points from ac polygons
    arcpy.Near_analysis(points, ac_polys)

    #copy result into second field
    arcpy.AddField_management(points, "NEAR_DIST2", "FLOAT")
    arcpy.CalculateField_management(points, "NEAR_DIST2", "!NEAR_DIST!",
                                    "PYTHON_9.3")

    #calculate dist of points from bankfull polys
    arcpy.Near_analysis(points, master_polys)

    #select points that are adj to ac_polys, but not adj to bankfull polys
    query = "NEAR_DIST2<=5 AND NEAR_DIST>0"
    lyr = arcpy.MakeFeatureLayer_management(points, "layera", query)

    #save these points into new feature class
    copy_features(lyr, env.workspace, naming + "gap_points" + str(counter))
    gap_points = os.path.join(env.workspace,
                              naming + "gap_points" + str(counter))

    #calculate dist of gap points to other points
    arcpy.Near_analysis(points, gap_points)

    #select points that are adj to gap points and not in ac_polys
    query = "NEAR_DIST<=7.071 AND NEAR_DIST2>0"
    lyr = arcpy.MakeFeatureLayer_management(points, "layerb", query)

    #save these points into new feature class
    copy_features(lyr, env.workspace, naming + "gap_points2" + str(counter))
    gap_points = os.path.join(env.workspace,
                              naming + "gap_points2" + str(counter))

    #turn these points into polygons
    gap_polys = os.path.join(
        env.workspace, naming + "bankfull_polys_with_gaps" + str(counter))
    arcpy.AggregatePoints_cartography(gap_points, gap_polys, "7.5 meters")

    #merge these polygons with the master bankfull polygons
    filled_polys = os.path.join(env.workspace,
                                naming + "bankfull_beforeagg" + str(counter))
    arcpy.Merge_management([gap_polys, master_polys], filled_polys)

    #aggregate polys
    final_polys = os.path.join(env.workspace,
                               naming + "bankfull_polys_final" + str(counter))
    arcpy.AggregatePolygons_cartography(filled_polys, final_polys,
                                        "7.5 Meters")

    #after aggreagating polygons there will be a bunch of BS little polygons that we don't need
    #use dissolve tool to eliminate these little guys, but first you must use near tool to get proper
    #parameters for dissolving. we are going to dissolve by nearest stream so run near on polygons and streams.

    ##        arcpy.Near_analysis(pred_final_polys,ac_polys)
    ##
    ##        final_polys=os.path.join(env.workspace,naming+"bankfull_polys_final"+str(counter))
    ##        arcpy.Dissolve_management(pred_final_polys, final_polys,["NEAR_FID", "TAXCODE"])

    return final_polys
Пример #3
0
    # define local variables from the CSV headings
    CSV_x = "X"
    CSV_y = "Y"
    CSV_z = "D"

    # make the event layer
    arcpy.MakeXYEventLayer_management(csv_file, CSV_x, CSV_y, temp1,
                                      CSV_coordinate_system, CSV_z)
    # save to temporary shapefile
    arcpy.CopyFeatures_management(temp1, temp2)
    # make feature layer for select by attribute tool
    arcpy.MakeFeatureLayer_management(temp2, temp2a)

    # select only depths greater than 0.05 ft
    arcpy.SelectLayerByAttribute_management(temp2a, "NEW_SELECTION", "D>0.05")
    # save only selected features to shapefile
    arcpy.CopyFeatures_management(temp2a, output1)

    # clear selection
    arcpy.SelectLayerByAttribute_management(temp2a, "CLEAR_SELECTION")

    # aggregate point features to create temporary polygon
    arcpy.AggregatePoints_cartography(output1, temp3, "50")

    # smooth temporary polygon
    arcpy.SmoothPolygon_cartography(temp3, output2, "PAEK", 30)

    # delete in_memory objects (temps)
    arcpy.Delete_management("in_memory")
Пример #4
0
def doPointsClusterA(InputTable,OutputTable,ClusterDistance="500 Meters"):
    ##params of dbdata
    POI = ArcCatalogPath+"\\WangYouTouSu60.sde\\WangYouTouSu.DBO.GIS_POI_AREA_ALLGRID"
    cacheAggregatePoints2 =  clusterCacheDB+"/cacheAggregatePoints2"
    cacheAggregatePoints2Tbl =  clusterCacheDB+"/cacheAggregatePoints2_Tbl"
    pointCluster3 =  clusterCacheDB+"/pointCluster3"
    OutPolygon4 =  clusterCacheDB+"/OutPolygon4"
    SpatialJoin5  = OutputTable
    OutPolygonPoints6 = clusterCacheDB+"/OutPolygonPoints6"
    SpatialJoinPoint7 = clusterCacheDB+"/SpatialJoinPoint7"
    
    if(arcpy.Exists(cacheAggregatePoints2)):
        arcpy.Delete_management(cacheAggregatePoints2)
    if(arcpy.Exists(cacheAggregatePoints2Tbl)):
        arcpy.Delete_management(cacheAggregatePoints2Tbl)
    if(arcpy.Exists(pointCluster3)):
        arcpy.Delete_management(pointCluster3)
    if(arcpy.Exists(OutPolygon4)):
        arcpy.Delete_management(OutPolygon4)
    if(arcpy.Exists(SpatialJoin5)):
        arcpy.Delete_management(SpatialJoin5)
    if(arcpy.Exists(OutPolygonPoints6)):
        arcpy.Delete_management(OutPolygonPoints6)
    if(arcpy.Exists(SpatialJoinPoint7)):
        arcpy.Delete_management(SpatialJoinPoint7)
        
    print "1.Process:AggregatePoints"
    logging.info("1.Process:AggregatePoints")
    # Process: 聚合点
    arcpy.AggregatePoints_cartography(InputTable, cacheAggregatePoints2, ClusterDistance)

    print "2.Process:PointClusterinsert"
    logging.info("2.Process:PointClusterinsert")
    # Process: 面聚合插入式
    arcpy.gp.toolbox = "C:\\Users\\Administrator\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcToolbox\\My Toolboxes\\ClusterTools.tbx";    
    arcpy.gp.PointClusterinsert(cacheAggregatePoints2, pointCluster3)
    
    print "3.Process:Dissolve"
    logging.info("3.Process:Dissolve")
    # Process: 融合
    arcpy.Dissolve_management(pointCluster3, OutPolygon4, "CLUSTERID", "", "MULTI_PART", "DISSOLVE_LINES")

    print "4.Process:SpatialJoin"
    logging.info("4.Process:SpatialJoin")
    # Process: 空间连接
    arcpy.SpatialJoin_analysis(InputTable, OutPolygon4, SpatialJoin5, "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT", "", "")

    print "5.Process:FeatureToPoint"
    logging.info("5.Process:FeatureToPoint")
    # Process: 要素转点
    arcpy.FeatureToPoint_management(OutPolygon4, OutPolygonPoints6, "CENTROID")

    print "6.Process:SpatialJoin"
    logging.info("6.Process:SpatialJoin")
    # Process: 空间连接 (2)
    arcpy.SpatialJoin_analysis(OutPolygonPoints6, POI, SpatialJoinPoint7, "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "CLOSEST", "", "DISTANCE")

    print "7.Process:JoinField"
    logging.info("7.Process:JoinField")
    # Process: 连接字段
    arcpy.JoinField_management(SpatialJoin5, "CLUSTERID", SpatialJoinPoint7, "CLUSTERID",  "DISTANCE;CLUSTERID;Name;CITY;COUNTY;GRID;LON;LAT")

    print "8.Process:delete no user field"
    logging.info("8.Process:delete no user field")
    arcpy.DeleteField_management (SpatialJoin5, "Join_Count") 
    arcpy.DeleteField_management (SpatialJoin5, "TARGET_FID")
    arcpy.DeleteField_management (SpatialJoin5, "ObjectID_1")
    arcpy.DeleteField_management (SpatialJoin5, "CLUSTERID_1")
    arcpy.CalculateField_management(SpatialJoin5, "DISTANCE", '!DISTANCE!/0.0009*100' , "PYTHON_9.3")
outputField = "VALUE"
arcpy.RasterToPoint_conversion(Search_Extract, Search_Points, outputField)

# Conduct near point analysis and calculate maximum near distance
arcpy.AddMessage("Determining maximum point distances...")
arcpy.Near_analysis(Search_Points, Search_Points, "", "NO_LOCATION",
                    "NO_ANGLE", "PLANAR")
arr = arcpy.da.FeatureClassToNumPyArray(Search_Points,
                                        ('NEAR_DIST'))['NEAR_DIST']
Max = (numpy.percentile(arr, 90) * Mod_Float)

# Aggregate input points based on maximum near distance
arcpy.AddMessage(
    "Creating concave polygon based on maximum point distances (step 1 of 3)..."
)
arcpy.AggregatePoints_cartography(Input_Points, Aggregate_Polygon, Max)

# Buffer aggregate polygon based on buffer distance
arcpy.AddMessage(
    "Creating concave polygon based on maximum point distances (step 2 of 3)..."
)
sideType = "FULL"
endType = "ROUND"
dissolveType = "NONE"
dissolveField = ""
Method = "PLANAR"
arcpy.Buffer_analysis(Aggregate_Polygon, Buffer_Polygon, Buffer_Distance,
                      sideType, endType, dissolveType, dissolveField, Method)

# Dissolve buffered polygon
arcpy.AddMessage(
Пример #6
0
    #MBpointMerge = outPointMerge
    MBpointMerge = os.path.basename(outPointMerge)
    arcpy.AddMessage("short name...")
    arcpy.AddMessage(MBpointMerge)

except:
    # If an error occurred while running a tool, then print the messages.
    arcpy.AddMessage("did not create merged point file: " + outPointMerge)
    print arcpy.GetMessages()

try:
    outMBboundary = str(workspaceGDB + "\\" + DataType + "_Seg_" + inSegment +
                        "_" + inYear + "_boundary")
    fc = outPointMerge
    # Process: Aggregate Points
    arcpy.AggregatePoints_cartography(fc, outMBboundary, aggregation_distance)
    arcpy.AddMessage("Created Polygons from XYZ points...")
    arcpy.AddMessage(outMBboundary)

except:
    # If an error occurred while running a tool, then print the messages.
    arcpy.AddMessage("Did Not Create Polygons from XYZ points...")
    arcpy.AddMessage(outMBboundary)
    print arcpy.GetMessages()

try:
    outMBboundaryElim = str(workspaceGDB + "\\" + DataType + "_Seg_" +
                            inSegment + "_" + inYear + "_bdy_elim")
    EliminationAreaExpression = str(EliminationArea + " SquareMeters")
    arcpy.EliminatePolygonPart_management(outMBboundary,
                                          outMBboundaryElim,
Пример #7
0
def ExtractRange(outRaster, outFilePath, file):
    inSQLClause = "VALUE > 0"
    try:
        # Execute ExtractByAttributes
        attExtract = arcpy.sa.ExtractByAttributes(outRaster, inSQLClause)
        print('87')
        sys.stdout.flush()
        # Save the output
        #attExtract.save("F:\\ree\\PM25T08.tif")
        rasfile = os.path.split(outRaster)[1]
        in_point_features = os.path.join(file, u"RasterToPoint_conversion.shp")
        out_feature_class = os.path.join(file,
                                         u"AggregatePoints_cartography.shp")
        out_SmoothPolygon_class = os.path.join(file,
                                               u"out_SmoothPolygon_class.shp")
        calculate_output = os.path.join(file, u"calculate_output.shp")
        try:
            arcpy.RasterToPoint_conversion(attExtract, in_point_features,
                                           "VALUE")
        except:
            pass
        try:
            arcpy.AggregatePoints_cartography(in_point_features,
                                              out_feature_class, 30)
        except:
            pass
        try:
            arcpy.SmoothPolygon_cartography(out_feature_class,
                                            out_SmoothPolygon_class, 'PAEK',
                                            30)
        except:
            pass
        try:
            # Process: Calculate Areas...
            arcpy.CalculateAreas_stats(out_SmoothPolygon_class,
                                       calculate_output)
        except:
            # If an error occurred when running the tool, print out the error message.
            traceback.print_exc()
        try:
            arcpy.Delete_management(in_point_features)
        except:
            traceback.print_exc()
        try:
            arcpy.DeleteFeatures_management(out_SmoothPolygon_class)
        except:
            traceback.print_exc()
        try:
            arcpy.DeleteFeatures_management(out_feature_class)
        except:
            traceback.print_exc()
        try:
            arcpy.Delete_management(out_feature_class)
        except:
            traceback.print_exc()
        try:
            arcpy.Delete_management(out_SmoothPolygon_class)
        except:
            traceback.print_exc()

    except Exception as err:
        arcpy.AddMessage("ExtractByAttributes Failed")
        arcpy.AddMessage(err)
        traceback.print_exc()
        return
Пример #8
0
            )
            raw_input("\nHit Enter to Continue...")
            sys.exit()

    except Exception as IE:
        e = sys.exc_info()[1]
        print(
            "\n\nError while merging results. This error can't be handled here.\n\nArcpy says:\n"
            + e.args[0])
        raw_input("\nHit Enter to Continue...")
        sys.exit()

    try:
        OUTPUT_POLYGONS_NAME = OUTPUT_DATASET_NAME + "_polys"
        arcpy.AggregatePoints_cartography(OUTPUT_DATASET_NAME,
                                          OUTPUT_POLYGONS_NAME,
                                          POLYGON_AGGREGATE_DISTANCE)
        printProgressBar(75)
    except Exception as IE:
        e = sys.exc_info()[1]
        print(
            "\n\nError while creating polygons. This error can't be handled here.\n\nArcpy says:\n"
            + e.args[0])
        raw_input("\nHit Enter to Continue...")
        sys.exit()

    printProgressBar(100)

    print("\n\nDone.\n")

    #HUZZAH!
Пример #9
0
sql_query=("("+str(SO_field)+"=1 AND grid_code <= ("+str(minfield)+"+"+str(tol_1)+")) OR ("+ str(SO_field)+"=2 AND grid_code <= ("+str(minfield)+"+"+str(tol_2)+")) OR "
"("+str(SO_field)+"=3 AND grid_code <= ("+str(minfield)+"+"+str(tol_3)+")) OR ("+ str(SO_field)+"=4 AND grid_code <= ("+str(minfield)+"+"+str(tol_4)+")) OR "
"("+str(SO_field)+"=5 AND grid_code <= ("+str(minfield)+"+"+str(tol_5)+")) OR ("+ str(SO_field)+"=6 AND grid_code <= ("+str(minfield)+"+"+str(tol_6)+")) OR "
"("+str(SO_field)+"=7 AND grid_code <= ("+str(minfield)+"+"+str(tol_7)+")) OR ("+ str(SO_field)+">=8 AND grid_code <= ("+str(minfield)+"+"+str(tol_8)+"))")

arcpy.AddMessage(sql_query)

#select points that fit query 
lyr=arcpy.MakeFeatureLayer_management(dem_points,"slayer",sql_query)

#use a while loop to itrate until counter exceeds buffer number
#to iterate through every buffer
arcpy.AddMessage("Copying identified points into workspace...(Step 2 of 3)")
final_points=arcpy.CopyFeatures_management(lyr,os.path.join(env.workspace,naming+"_"+"AC_Points"))

polys_draft=os.path.join(env.workspace, naming+"_Active_Channel_Polys_draft")

#get necessary point dist for aggregate points. 
agg_dist=calculate_aggregate_point_dist()
###create polygons from points
arcpy.AddMessage("Building Active Channel Polygons from points...(Step 3 of 3)")
try:
        arcpy.AggregatePoints_cartography(lyr,polys_draft, agg_dist)

except:
        arcpy.AddMessage("Polygons could not be created because an Advanced License has not been checked out.")

arcpy.Delete_management(os.path.join(env.workspace,naming+"Active_Channel_Polys_draft_tbl"))