Esempio n. 1
0
def calc_connectivity_network(path_arcgis_db, path_streets_shp, path_connection_point_buildings_shp, path_potential_network):
    """
    This script outputs a potential network connecting a series of building points to the closest street network
    the street network is assumed to be a good path to the district heating or cooling network

    :param path_arcgis_db: path to default ArcGIS database
    :param path_streets_shp: path to street shapefile
    :param path_connection_point_buildings_shp: path to substations in buildings (or close by)
    :param path_potential_network: output path shapefile
    :return:
    """
    # first add distribution network to each building form the roads

    arcpy.env.overwriteOutput = True
    spatialReference = arcpy.Describe(path_connection_point_buildings_shp).spatialReference
    memorybuildings = path_arcgis_db + "\\" + "points"
    merge = path_arcgis_db + "\\" + "merge"
    Newlines = path_arcgis_db + "\\" + "linesToerase"
    Finallines = path_arcgis_db + "\\" + "final_line"

    arcpy.CopyFeatures_management(path_connection_point_buildings_shp, memorybuildings)
    arcpy.Near_analysis(memorybuildings, path_streets_shp, location=True, angle=True) # find the closest point on the street to a buildings
    arcpy.MakeXYEventLayer_management(memorybuildings, "NEAR_X", "NEAR_Y", "Line_Points_Layer", spatialReference) # make that point into a node
    arcpy.FeatureClassToFeatureClass_conversion("Line_Points_Layer", path_arcgis_db, "Line_points")
    arcpy.Append_management(path_arcgis_db + '\\' + "Line_points", memorybuildings, "No_Test") # combine all nodes into one layer
    arcpy.MakeFeatureLayer_management(memorybuildings, "POINTS_layer")
    arcpy.env.workspace = path_arcgis_db
    arcpy.PointsToLine_management(memorybuildings, Newlines, "Name", "#", "NO_CLOSE")
    arcpy.Merge_management([path_streets_shp, Newlines], merge)
    arcpy.FeatureToLine_management(merge, path_potential_network)  # necessary to match vertices
Esempio n. 2
0
def CalcObservers(Simple_CQ, Observers, DataFactorsBoundaries, locationtemporal2, gv):
    # local variables
    Buffer_CQ = locationtemporal2 + '\\' + 'BufferCQ'
    temporal_lines = locationtemporal2 + '\\' + 'lines'
    Points = locationtemporal2 + '\\' + 'Points'
    AggregatedBuffer = locationtemporal2 + '\\' + 'BufferAggregated'
    temporal_lines3 = locationtemporal2 + '\\' + 'lines3'
    Points3 = locationtemporal2 + '\\' + 'Points3'
    Points3Updated = locationtemporal2 + '\\' + 'Points3Updated'
    EraseObservers = locationtemporal2 + '\\' + 'eraseobservers'
    Observers0 = locationtemporal2 + '\\' + 'observers0'
    NonoverlappingBuildings = locationtemporal2 + '\\' + 'Non_overlap'
    templines = locationtemporal2 + '\\' + 'templines'
    templines2 = locationtemporal2 + '\\' + 'templines2'
    Buffer_CQ0 = locationtemporal2 + '\\' + 'Buffer_CQ0'
    Buffer_CQ = locationtemporal2 + '\\' + 'Buffer_CQ'
    Buffer_CQ1 = locationtemporal2 + '\\' + 'Buffer_CQ1'
    Simple_CQcopy = locationtemporal2 + '\\' + 'Simple_CQcopy'
    # First increase the boundaries in 2m of each surface in the community to
    # analyze- this will avoid that the observers overlap the buildings and Simplify
    # the community vertices to only create 1 point per surface

    arcpy.CopyFeatures_management(Simple_CQ, Simple_CQcopy)
    # Make Square-like buffers
    arcpy.PolygonToLine_management(Simple_CQcopy, templines, "IGNORE_NEIGHBORS")
    arcpy.SplitLine_management(templines, templines2)
    arcpy.Buffer_analysis(templines2, Buffer_CQ0, "0.75 Meters", "FULL", "FLAT", "NONE", "#")
    arcpy.Append_management(Simple_CQcopy, Buffer_CQ0, "NO_TEST")
    arcpy.Dissolve_management(Buffer_CQ0, Buffer_CQ1, "Name", "#", "SINGLE_PART", "DISSOLVE_LINES")
    arcpy.SimplifyBuilding_cartography(Buffer_CQ1, Buffer_CQ, simplification_tolerance=8, minimum_area=None)

    # arcpy.Buffer_analysis(Simple_CQ,Buffer_CQ,buffer_distance_or_field=1, line_end_type='FLAT') # buffer with a flat finishing
    # arcpy.Generalize_edit(Buffer_CQ,"2 METERS")

    # Transform all polygons of the simplified areas to observation points
    arcpy.SplitLine_management(Buffer_CQ, temporal_lines)
    arcpy.FeatureVerticesToPoints_management(temporal_lines, Points,
                                             'MID')  # Second the transformation of Lines to a mid point

    # Join all the polygons to get extra vertices, make lines and then get points.
    # these points should be added to the original observation points
    arcpy.AggregatePolygons_cartography(Buffer_CQ, AggregatedBuffer, "0.5 Meters", "0 SquareMeters", "0 SquareMeters",
                                        "ORTHOGONAL")  # agregate polygons
    arcpy.SplitLine_management(AggregatedBuffer, temporal_lines3)  # make lines
    arcpy.FeatureVerticesToPoints_management(temporal_lines3, Points3, 'MID')  # create extra points

    # add information to Points3 about their buildings
    arcpy.SpatialJoin_analysis(Points3, Buffer_CQ, Points3Updated, "JOIN_ONE_TO_ONE", "KEEP_ALL",
                               match_option="CLOSEST", search_radius="5 METERS")
    arcpy.Erase_analysis(Points3Updated, Points, EraseObservers, "2 Meters")  # erase overlaping points
    arcpy.Merge_management([Points, EraseObservers], Observers0)  # erase overlaping points

    #  Eliminate Observation points above roofs of the highest surfaces(a trick to make the
    # Import Overlaptable from function CalcBoundaries containing the data about buildings overlaping, eliminate duplicades, chose only those ones no overlaped and reindex
    DataNear = pd.read_csv(DataFactorsBoundaries)
    CleanDataNear = DataNear[DataNear['FactorShade'] == 1]
    CleanDataNear.drop_duplicates(subset='Name_x', inplace=True)
    CleanDataNear.reset_index(inplace=True)
    rows = CleanDataNear.Name_x.count()
    for row in range(rows):
        Field = "Name"  # select field where the name exists to iterate
        Value = CleanDataNear.loc[row, 'Name_x']  # set the value or name of the City quarter
        Where_clausule = '''''' + '"' + Field + '"' + "=" + "\'" + str(
            Value) + "\'" + ''''''  # strange writing to introduce in ArcGIS
        if row == 0:
            arcpy.MakeFeatureLayer_management(Simple_CQ, 'Simple_lyr')
            arcpy.SelectLayerByAttribute_management('Simple_lyr', "NEW_SELECTION", Where_clausule)
        else:
            arcpy.SelectLayerByAttribute_management('Simple_lyr', "ADD_TO_SELECTION", Where_clausule)

        arcpy.CopyFeatures_management('simple_lyr', NonoverlappingBuildings)

    arcpy.ErasePoint_edit(Observers0, NonoverlappingBuildings, "INSIDE")
    arcpy.CopyFeatures_management(Observers0, Observers)  # copy features to reset the OBJECTID
    with arcpy.da.UpdateCursor(Observers, ["OBJECTID", "ORIG_FID"]) as cursor:
        for row in cursor:
            row[1] = row[0]
            cursor.updateRow(row)
    gv.log('complete calculating observers')
    return arcpy.GetMessages()