朋友们,你们知道ArcGIS里面分式标注的四种写法么?

放错图了,是这个
 
 
   我们可以把这类叫分式标注,网上也有博主分享过如何在ArcGIS中制作这类标注,但我觉得仍有一些不足。
一是基本都使用VB编写,我看不懂

二是没有很好解决分式标注的格式问题
 
 
  三是需要直接操作表达式语句,较为繁琐。

为了解决以上三点不足,鼠鼠我啊创建了一个基于Python的ArcGIS Pro脚本工具,在无脑的道路上又前进了一步。
工具演示
工具代码
  
   - 
    
     
    
    
     
      import arcpy
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      aprx = arcpy.mp.ArcGISProject(
      r"CURRENT")
     
    
- 
    
     
    
    
     
      m = aprx.activeMap
     
    
- 
    
     
    
    
     
      lyrs = m.listLayers()
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      tarLayer = arcpy.GetParameterAsText(
      0)
     
    
- 
    
     
    
    
     
      fid1 = arcpy.GetParameterAsText(
      1)
     
    
- 
    
     
    
    
     
      fid2 = arcpy.GetParameterAsText(
      2)
     
    
- 
    
     
    
    
     
      fid3 = arcpy.GetParameterAsText(
      3)
     
    
- 
    
     
    
    
     
      fid4 = arcpy.GetParameterAsText(
      4)
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      fidList=
      set([fid1,fid2,fid3,fid4])
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      fidsPara=
      ""
     
    
- 
    
     
    
    
     
      for i 
      in fidList:
     
    
- 
    
     
    
    
     
          fidsPara = fidsPara+
      "[{0}],".
      format(i)
     
    
- 
    
     
    
    
     
      fidsPara = fidsPara[:-
      1]
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      exp = 
      """def FindLabel({4}):
     
    
- 
    
     
    
    
     
      
     
    
- 
    
     
    
    
     
       def Len(txt): 
     
    
- 
    
     
    
    
     
       lenTxt = len(txt) 
     
    
- 
    
     
    
    
     
       lenTxt_utf8 = len(txt.encode('utf-8')) 
     
    
- 
    
     
    
    
     
       size = int((lenTxt_utf8 - lenTxt)/2 + lenTxt)
     
    
- 
    
     
    
    
     
       return size
     
    
- 
    
     
    
    
     
      
     
    
- 
    
     
    
    
     
       b=Len([{0}])
     
    
- 
    
     
    
    
     
       c=Len([{1}])
     
    
- 
    
     
    
    
     
       d=Len([{2}])
     
    
- 
    
     
    
    
     
       e=Len([{3}])
     
    
- 
    
     
    
    
     
      
     
    
- 
    
     
    
    
     
       if b>c:
     
    
- 
    
     
    
    
     
       a=b
     
    
- 
    
     
    
    
     
       else:
     
    
- 
    
     
    
    
     
       a=c
     
    
- 
    
     
    
    
     
      
     
    
- 
    
     
    
    
     
       if d>e:
     
    
- 
    
     
    
    
     
       label =[{0}] + "\\n"+ [{2}] +"-"*(a+2) +[{3}]+" "*((d-e)//2) + "\\n" + [{1}]
     
    
- 
    
     
    
    
     
       else:
     
    
- 
    
     
    
    
     
       label =[{0}] + "\\n"+ " "*((e-d)//2) +[{2}] +"-"*(a+2) +[{3}] + "\\n" + [{1}]
     
    
- 
    
     
    
    
     
      
     
    
- 
    
     
    
    
     
       return "<LIN leading = '0.5' leading_type = 'multiple'>" + "<ALIGN horizontal = 'center'>" + label + "</ALIGN>" + "</LIN>" """.
      format(fid1, fid2, fid3, fid4, fidsPara)
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      for lyr 
      in lyrs:
     
    
- 
    
     
    
    
     
          longName = lyr.longName
     
    
- 
    
     
    
    
         
      if longName == tarLayer 
      and lyr.isFeatureLayer == 
      True:
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
              lyr_cim = lyr.getDefinition(
      'V2')
     
    
- 
    
     
    
    
     
              lyr_cim.labelClasses[
      0].expressionEngine = 
      'Python'
     
    
- 
    
     
    
    
     
              lyr_cim.labelClasses[
      0].maplexLabelPlacementProperties.removeExtraWhiteSpace=
      "False"
     
    
- 
    
     
    
    
     
              lyr.setDefinition(lyr_cim)
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
              lblClass = lyr.listLabelClasses()[
      0]
     
    
- 
    
     
    
    
     
              lblClass.expression = exp
     
    
- 
    
     
    
    
     
              lblClass.visible = 
      True
     
    
- 
    
     
    
    
     
              lyr.showLabels = 
      True
     
    
 工具说明
- 工具可以在ArcGIS Pro2.x和3.x版本中使用。
- 工具界面中,分子和分母字段是必填的,前缀和后缀选填。
- 生成的分式标注将作用在图层的第一个标注类上
工具获取
代码可自取,完整工具请私信联系。
传播代码和工具请注明出处
转载:https://blog.csdn.net/baidu_28157641/article/details/128748439
查看评论
					 
					