예제 #1
0
    def execute(self, parameters, messages):
        """The source code of the tool."""
        visibility_lines = parameters[0].valueAsText
        observer_offset_field = parameters[1].valueAsText
        target_offset_field = parameters[2].valueAsText
        self.b1 = float(parameters[5].valueAsText)
        self.h = float(parameters[3].valueAsText)
        self.beta = parameters[4].value

        useCurvatures = parameters[6].value
        refCoeff = parameters[7].value


        fieldsNew = [ ("Visible", "Visibility of target", "SHORT"),
                       ("ViewAngle", "Viewing angle of target", "DOUBLE"),
                       ("ElevDiff", "Elevation difference of observer and target", "DOUBLE"),
                       ("AngleDiff_H", "Angle difference of target to horizon", "DOUBLE"),
                       ("ElevDiff_H", "Elevation difference of target to horizon", "DOUBLE"),
                       ("SlopeDiff", "Difference of target viewing angle to LoS slope", "DOUBLE"),
                       ("Horizon_C", "Horizon count", "SHORT"),
                       ("HorDist", "Distance of horizon from observer", "DOUBLE"),
                       ("FuzzyVis", "Fuzzy visibility", "DOUBLE")]

        fieldsNames = [row[0] for row in fieldsNew]

        columns = ["OBJECTID", "SHAPE@"] + [observer_offset_field, target_offset_field]

        farcmap.prepareDataColumns(visibility_lines, fieldsNew)

        number_of_LoS = int(arcpy.GetCount_management(visibility_lines).getOutput(0))

        arcpy.SetProgressor("step", "Analyzing " + str(number_of_LoS) + " lines of sight...", 0, number_of_LoS, 1)

        with arcpy.da.UpdateCursor(visibility_lines, columns + fieldsNames) as cursor:
            for row in cursor:

                points = []
                poi = visibility.WKTtoPoints(row[1].WKT)
                # get coordinates of first point for distance calculation

                observer_offset = row[2]
                target_offset = row[3]

                start_point_x = float(poi[0].split(" ")[0])
                start_point_y = float(poi[0].split(" ")[1])
                observer_elev = float(poi[0].split(" ")[2]) + observer_offset

                # for every point do this
                for i in range(0, len(poi)):
                    parts = poi[i].split(" ")
                    x = float(parts[0])
                    y = float(parts[1])
                    z = float(parts[2])
                    dist = visibility.distance(x, y, start_point_x, start_point_y)

                    if useCurvatures:
                        z = visibility.curvatureCorrections(z, dist, refCoeff)

                    if i == 0:
                        points.append([x, y, 0, observer_elev, -90])
                    elif i == len(poi) - 1:
                        points.append([x, y, dist, z + target_offset, visibility.angle(dist, z + target_offset - observer_elev)])
                    else:
                        points.append([x, y, dist, z, visibility.angle(dist, z - observer_elev)])

                results = self.analyzeLoS(points)
                for i in range(0, len(results)):
                    row[i + 4] = results[i]
                cursor.updateRow(row)
                arcpy.SetProgressorPosition()

        arcpy.ResetProgressor()

        return
    def execute(self, parameters, messages):
        """The source code of the tool."""
        visibility_lines = parameters[0].valueAsText
        id_observer_field = parameters[1].valueAsText
        observer_offset_field = parameters[2].valueAsText
        id_target_field = parameters[3].valueAsText
        target_offset_field = parameters[4].valueAsText
        horizons = parameters[5].valueAsText

        useCurvatures = parameters[6].value
        refCoeff = parameters[7].value

        workspace = fv.getPath(horizons)

        file_name = horizons.replace(workspace + "\\", "")

        arcpy.CreateFeatureclass_management(
            workspace,
            file_name,
            "POINT",
            has_z="ENABLED",
            spatial_reference=arcpy.Describe(
                visibility_lines).spatialReference)

        fieldsNew = [
            (id_observer_field, id_observer_field, "SHORT"),
            (id_target_field, id_target_field, "SHORT"),
            ("Elevation", "Elevation", "DOUBLE"),
            ("Hor_Type", "Horizon Type", "SHORT"),
            ("Hide_Tar", "Hides target point", "SHORT"),
            ("ViewAngle", "Viewing angle", "DOUBLE"),
            ("AngleDiff_H", "Viewing angle difference to previous horizon",
             "DOUBLE"), ("Dist_Observ", "Distance to observer", "DOUBLE"),
            ("OID_LoS", "OID_LoS", "SHORT")
        ]

        fieldsNames = [row[0] for row in fieldsNew]

        # field_list = [id_observer_field, id_target_field, "Elevation", "Hor_Type", "Hide_Tar", "ViewAngle",
        #             "AngleDiff_H", "Dist_Observ", "OID_LoS"]

        functions_arcmap.prepareDataColumns(horizons, fieldsNew)

        arcpy.AddMessage("\t Determination of horizons started...")

        insert_cursor = arcpy.da.InsertCursor(horizons,
                                              ["SHAPE@"] + fieldsNames)

        number_of_LoS = int(
            arcpy.GetCount_management(visibility_lines).getOutput(0))
        arcpy.SetProgressor(
            "step", "Analyzing " + str(number_of_LoS) + " lines of sight...",
            0, number_of_LoS, 1)

        with arcpy.da.SearchCursor(visibility_lines, [
                "OBJECTID", "SHAPE@", id_observer_field, id_target_field,
                observer_offset_field, target_offset_field
        ]) as cursor:
            for row in cursor:

                points = []
                poi = visibility.WKTtoPoints(row[1].WKT)

                # get coordinates of first point for distance calculation
                start_point_x = float(poi[0].split(" ")[0])
                start_point_y = float(poi[0].split(" ")[1])
                observer_elev = float(poi[0].split(" ")[2]) + float(row[4])
                # for every point do this
                for i in range(0, len(poi)):
                    parts = poi[i].split(" ")
                    x = float(parts[0])
                    y = float(parts[1])
                    z = float(parts[2])
                    dist = visibility.distance(x, y, start_point_x,
                                               start_point_y)

                    if useCurvatures:
                        z = visibility.curvatureCorrections(z, dist, refCoeff)

                    if i == 0:
                        points.append([x, y, 0, observer_elev, -90])
                    elif i == len(poi) - 1:
                        points.append([
                            x, y, dist, z + float(row[5]),
                            visibility.angle(dist,
                                             z + float(row[5]) - observer_elev)
                        ])
                    else:
                        points.append([
                            x, y, dist, z,
                            visibility.angle(dist, z - observer_elev)
                        ])

                results = visibility.findLocalHorizons(points)

                point = arcpy.Point()

                for i in range(0, len(results)):
                    hor_type = 0
                    point.X = results[i][0]
                    point.Y = results[i][1]
                    point.Z = results[i][3]
                    ptGeometry = arcpy.PointGeometry(point)
                    if i == len(results) - 1:
                        hor_type = 1

                    insert_cursor.insertRow([
                        ptGeometry, row[2], row[3], results[i][3], hor_type,
                        results[i][5], results[i][4], results[i][6],
                        results[i][2], row[0]
                    ])

                arcpy.SetProgressorPosition()

        arcpy.ResetProgressor()
        arcpy.AddMessage("\t Determination of horizons sucessfuly ended.")

        functions_arcmap.addLayer(horizons)
        return