Exemplo n.º 1
0
 def Excute(self):
     arcpy.env.workspace = "C:\\Generalize_25_50\\50K_Process.gdb"
     arcpy.env.overwriteOutput = True
     arcpy.env.referenceScale = "50000"
     fcCongThuyLoiP = "CongThuyLoiP"
     fcCauGiaoThongP = "CauGiaoThongP"
     fcDoanTimDuongBo = "DoanTimDuongBo"
     congThuyLoiPLayer = "CongThuyLoiPLayer"
     cauGiaoThongPLayer = "CauGiaoThongPLayer"
     doanTimDuongBoLayer = "DoanTimDuongBoLayer"
     arcpy.MakeFeatureLayer_management(in_features = fcCongThuyLoiP,
                                         out_layer = congThuyLoiPLayer)
     arcpy.MakeFeatureLayer_management(in_features = fcCauGiaoThongP,
                                         out_layer = cauGiaoThongPLayer)
     arcpy.MakeFeatureLayer_management(in_features = fcDoanTimDuongBo,
                                         out_layer = doanTimDuongBoLayer)
     arcpy.SetLayerRepresentation_cartography(in_layer = congThuyLoiPLayer,
                                              representation = "CongThuyLoiP_Rep")
     arcpy.SetLayerRepresentation_cartography(in_layer = cauGiaoThongPLayer,
                                              representation = "CauGiaoThongP_Rep")
     arcpy.SetLayerRepresentation_cartography(in_layer = doanTimDuongBoLayer,
                                              representation = "DoanTimDuongBo_Rep")
     #PERPENDICULAR: aligns representation markers perpendicularly to the stroke or fill edge. This is the default.
     #PARALLEL: aligns representation markers parallel to the stroke or fill edge.
     arcpy.AlignMarkerToStrokeOrFill_cartography(in_point_features = congThuyLoiPLayer,
                                                 in_line_or_polygon_features = doanTimDuongBoLayer,
                                                 search_distance = "0 Meters",
                                                 marker_orientation = "PERPENDICULAR")
     arcpy.AlignMarkerToStrokeOrFill_cartography(in_point_features = cauGiaoThongPLayer,
                                                 in_line_or_polygon_features = doanTimDuongBoLayer,
                                                 search_distance = "0 Meters",
                                                 marker_orientation = "PERPENDICULAR")
Exemplo n.º 2
0
def update_representation(inputfile, rep_lyr, outputfile, opacity):
    """
    给图层添加指定的制图表达效果并添加到 ArcMap 中
    :param inputfile: 输入图层
    :param outputfile: 结果输出
    :param rep_lyr: {String} 制图表达图层名称(.lyr file)
    :param opacity: 透明度设置
    :return:
    """

    # workspace
    arcpy.env.workspace = os.path.dirname(outputfile)
    work = arcpy.env.workspace
    #   check
    if not arcpy.Exists(rep_lyr):
        raise RuntimeError("Representation lyr file not exist.")

    # mxd file obj
    arcpy.env.overwriteOutput = True
    randnum = randint(0, 999999)
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd)[0]

    # create a new layer
    in_lyr = arcpy.mapping.Layer(inputfile)
    # layer name
    new_n = "{}_{}".format("building", randnum)
    arcpy.CopyFeatures_management(inputfile, outputfile)
    new_lyr = arcpy.mapping.Layer(os.path.join(work, outputfile))

    #       make representation symbol to new layer
    representation_lyr = arcpy.mapping.Layer(rep_lyr)
    arcpy.AddMessage("------------------")
    # representation name
    rp_name = "Rep_{}".format(randnum)
    # 创建制图表达
    r_func = arcpy.AddRepresentation_cartography
    r_func(new_lyr, rp_name, import_rule_layer=representation_lyr)

    #       add new layer to arcmap
    arcpy.SetLayerRepresentation_cartography(new_lyr, rp_name)
    new_lyr.transparency = int(opacity)
    arcpy.AddMessage(new_lyr.dataSource)
    arcpy.mapping.AddLayer(df, new_lyr)
    arcpy.AddMessage("\n------------------")
Exemplo n.º 3
0
def update_representation(inputfile, rep_lyr, output):
    """
    给图层添加指定的制图表达效果并添加到 ArcMap 中
    :param inputfile: 输入图层
    :param rep_lyr: {String} 制图表达图层名称(.lyr file)
    :param output: 样式输出图层
    :return:
    """
    #       check
    if not arcpy.Exists(rep_lyr):
        raise RuntimeError("Representation lyr file not exist.")

    #       mxd file obj
    arcpy.env.overwriteOutput = True
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd)[0]

    #       create a new layer
    in_lyr = arcpy.mapping.Layer(inputfile)
    # layer name
    arcpy.CopyFeatures_management(inputfile, output)
    # arcpy.AddMessage(type(new_n)) # <'str'>
    # new_lyr = arcpy.mapping.Layer(new_n)
    new_lyr = arcpy.mapping.Layer(os.path.join(work, output))

    #       make representation symbol to new layer
    representation_lyr = arcpy.mapping.Layer(rep_lyr)
    arcpy.AddMessage("------------------")
    # representation name
    randnum = randint(0, 999999)
    rp_name = "Rep_{}".format(randnum)
    # 创建制图表达
    r_func = arcpy.AddRepresentation_cartography
    r_func(new_lyr, rp_name, import_rule_layer=representation_lyr)

    #       copy transparency value
    opacity = representation_lyr.transparency
    new_lyr.transparency = opacity

    #       add new layer to arcmap
    arcpy.SetLayerRepresentation_cartography(new_lyr, rp_name)
    arcpy.mapping.AddLayer(df, new_lyr)
    arcpy.AddMessage("\n------------------")
Exemplo n.º 4
0
    cascadeFlowTemplate_lyr = 'cascadeFlowTemplate_lyr1'
    arcpy.MakeFeatureLayer_management(cascadeFlowTemplateFCname,
                                      cascadeFlowTemplate_lyr)
    if FLOWFLG == 0:
        repName = 'FLOWFLG_0'
        ruleField = 'RuleID_FLOWFLG_0'
        overrideField = 'Override_FLOWFLG_0'
        pctRule = [(.25, '25'), (.33, '33'), (.5, '50'), (1, '100')]
    else:
        repName = 'FLOWFLG_1'
        ruleField = 'RuleID_FLOWFLG_1'
        overrideField = 'Override_FLOWFLG_1'
        pctRule = [(.25, '25'), (.33, '33'), (.5, '50'), (.66, '66'),
                   (.75, '75'), (1, '100')]

    arcpy.SetLayerRepresentation_cartography(cascadeFlowTemplate_lyr, repName)
    editingOption = 'STORE_CHANGE_AS_OVERRIDE'
    assignOption = 'NO_ASSIGN'
    arcpy.AddRepresentation_cartography(cascadeFlowFC, repName, ruleField,
                                        overrideField, editingOption,
                                        cascadeFlowTemplate_lyr, assignOption)

    # Execute Calculate Representation Rule for each flow percentage rule
    txt = 'Execute Calculate Representation Rule for each flow percentage rule ({0})...'.format(
        cascadeFlowFCname)
    arcpy.AddMessage(txt)
    arcpy.env.workspace = outGDB
    tempCascadeFlow_lyr = cascadeFlowFCname[:7] + ' ' + cascadeFlowFCname[
        7:11] + ' ' + cascadeFlowFCname[11:18] + ' ' + cascadeFlowFCname[19:]
    arcpy.MakeFeatureLayer_management(cascadeFlowFCname, tempCascadeFlow_lyr)
    for pct, rule in pctRule: