当前位置:网站首页>ArcGIS Pro scripting tool (10) -- generate.Stylx style symbols from layers
ArcGIS Pro scripting tool (10) -- generate.Stylx style symbols from layers
2022-07-25 08:05:00 【Learn GIS】
The reason for making this tool is , Want to make a Xiangyuan controlled land color .stylx file .
But there are too many types of land in Xiangyuan , As shown in the figure below , fully 110 class . So many colored face symbols , One by one .stylx Don't be tired in the document ?

Fortunately Pro Yes CAD File support is better , We load directly CAD Of Polygon To Pro in ,Polygon It has been divided into layers , And the color is also similar to CAD In the agreement ( Check carefully CAD And Pro Of the same layer in RGB Color , You can still find RGB There are some differences in value , But the color is roughly right , It is not clear whether there is any way to maintain complete consistency . In the diagram above Pro The color of the land in the interface is light , Because Pro Automatically for all CAD Surface layer added 50% Transparency , This is also what needs to be handled in the next steps ).
One 、Pro Cancel CAD Layer transparency
To be in Pro Manually cancel this 110 individual CAD The transparency of layers is also a matter good fortune ... Trouble , Fortunately, I have figured out how to modify the code before .
ArcGIS Pro Scripting tools (6)—— Repair CAD Layer data source _ Science GIS The blog of -CSDN Blog _arcgis Scripting tools Pro Yes CAD File support is obviously better than ArcMap. Although they will CAD Identify points 、 Line 、 Noodles 、 Polyhedron and notes 5 Categories: , But when we drag one of the classes to Pro In the middle of the day ,Pro Automatically display it in layers , And the color of the layer is the same as CAD Agreement .nice! But the embarrassment is , once CAD File moved location or changed name , It's a long list of red exclamation point warnings . Experienced users may expect to repair a layer after , Other layers are automatically repaired , But it's a pity that this is not for these CAD Invalid layer . I'll put it off again CAD Just come in ? Maybe not , Because it's already in Pro The symbol system of some layers has been changed in , Drag again CAD Come in, you have to redo many layer symbols https://blog.csdn.net/baidu_28157641/article/details/125480952 After using the format face layer tool to cancel transparency , The comparison diagram before and after the color block of urban planning land is as follows .

Two 、Pro New China .stylx The style file
Can be built .stylx The style file , You can also use existing .stylx The style file ( If you use an existing style file , Please judge first CAD Whether the name will appear after the layer symbol is added 、 Key value conflict ).
In order to CAD Surface layer symbols are written .stylx The style file , We need to be right about .stylx Have a basic understanding of ..stylx It's actually a SQLite database , We can use Navicat To connect 、 see .

Database ITEMS The table records the ID、CLASS( spot 、 Line 、 Surface, etc. )、CATEGORY( classification )、NAME、TAGS( label )、CONTENT(json character string )、KEY( Key value ). except ID Outside , Other attributes of symbols can be found in Pro View and modify .
To learn Python Intermediate reading and writing SQLite The syntax of the database , We can go to .stylx The style file writes symbols .
3、 ... and 、 To write Python、 Scripting tools
The main processing flow of the script is : First read each CAD The name of the layer 、 Symbol , Then write this information to .stylx The style file (SQLite database ) in .CAD Layer names use ArcPy You can get , To obtain layer symbols, you need to use Python CIM, Because it can directly obtain writable CONTENT Attribute json character string .
Python Script
import arcpy
import sqlite3
aprx = arcpy.mp.ArcGISProject(r"CURRENT")
m = aprx.activeMap
groupLayer = arcpy.GetParameterAsText(0)
lyrs = m.listLayers()
stylx_path = arcpy.GetParameterAsText(1)
stylxDB = sqlite3.connect(stylx_path)
cursor = stylxDB.cursor()
category_switch = {4: " First class ",
5: " Second class ",
6: " Third class ", }
class_switch = {"Point": 3,
"Polyline": 4,
"Polygon": 5}
for lyr in lyrs:
longName = lyr.longName
if longName.startswith(groupLayer) and lyr.isGroupLayer == False:
type = arcpy.Describe(lyr).featureClass.shapeType
classValue = class_switch.get(type)
sym = lyr.symbology
if sym.renderer.type == 'SimpleRenderer':
try:
cim = lyr.getDefinition("V2").renderer.symbol.symbol
content = arcpy.cim.GetJSONForCIMObject(cim, "V2")
name = lyr.name
key = lyr.name
category = category_switch.get(len(name))
new_row = (classValue, category, name, content, key)
cursor.execute(
'INSERT INTO ITEMS(CLASS, CATEGORY, NAME, CONTENT, KEY) VALUES(?,?,?,?)', new_row)
stylxDB.commit()
arcpy.AddMessage("√ "+lyr.name)
except:
arcpy.AddMessage("× "+lyr.name)
stylxDB.close()
Parameter setting

Effect demonstration

Tool description
- Only for ArcGIS Pro
- Before running the tool , Please switch to map view
- This tool can generate points in batch 、 Line 、 Noodles 3 Types of style symbols
边栏推荐
- 2022-07-19 Daily: too many icml2022 papers to read? "One sentence comments on 1234 paper highlights" helps you quickly lock
- "Unable to recognize" yarn "item as cmdlet, function, script file
- Advanced C language (11) - user defined data types
- Raspberrypico analytic PWM
- Mysql-5.7 installation
- 刷题《剑指Offer》day01
- Codeforces Round #809 Editorial(A,B,C)
- Learn when playing No 6 | the magic of document library lies in
- P1049 [NOIP2001 普及组 T4] 装箱问题
- Summer Challenge harmonyos - slider slider for custom components
猜你喜欢

Check the computer restart times and reasons

Enq: HW - fault analysis caused by content waiting

eval与assert一句话木马分析

Calculation formula of cross entropy

一款强大的端口扫描工具(nmap)

People who lose weight should cry: it's no good not eating food, because your brain will be inflamed

475-82(230、43、78、79、213、198、1143)

Niuke dynamic planning training
![[paper notes] effective CNN architecture design guided by visualization](/img/aa/aeeac3f970eac7f110987c523602c8.png)
[paper notes] effective CNN architecture design guided by visualization

475-82(230、43、78、79、213、198、1143)
随机推荐
Redis core principles
node+js搭建时间服务器
Raspberry pie 4B parsing PWM
如何仅用递归函数和栈操作逆序一个栈
While (~scanf ("%d", & n)) is equivalent to while (scanf ("%d", & n)! =eof)
while(~scanf(“%d“, &n)) 等价于 while(scanf(“%d“,&n)!=EOF)
475-82(230、43、78、79、213、198、1143)
整数a按位取反(~)后的值为-(a+1)
[paper notes] effective CNN architecture design guided by visualization
Introduction and principle explanation of 30 common sensor modules in IOT embedded devices
Niuke dynamic planning training
2022-07-19 Daily: too many icml2022 papers to read? "One sentence comments on 1234 paper highlights" helps you quickly lock
Acnet: asymmetric convolution for image hypersegmentation (with implementation code)
一款强大的端口扫描工具(nmap)
The two Nobel Prize winners became the chief scientist of the sky high price Baijiu of "taishanglaojun holding a dream"
Design a stack with getmin function
What products and funds should novices invest in first?
Common commands of raspberry pie
Problems easily ignored by POM
Enq: HW - fault analysis caused by content waiting
https://docs.python.org/zh-cn/3.7/library/sqlite3.html