当前位置:网站首页>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
边栏推荐
- [unity entry program] make my first little game
- P1049 [NOIP2001 普及组 T4] 装箱问题
- Efcore's solution of multi tenant zero script, table and database read-write separation under SaaS system
- [paper notes] next vit: next generation vision transformer for efficient deployment in real industry
- 【FFmpeg】mp4转yuv
- UNIPRO multi terminal deployment to meet customers' diversified needs
- Network packet loss, network delay? This artifact helps you solve all problems
- Raspberry pie CM4 -- using metartc3.0 to integrate ffmpeg to realize webrtc push-pull streaming
- What products and funds should novices invest in first?
- Raspberry pie 4B ffmpeg RTMP streaming
猜你喜欢

Advanced C language (11) - user defined data types

Enq: HW - fault analysis caused by content waiting

batchnorm 和layernorm的区别

刷题《剑指Offer》day02

Rk3399 development board i2c4 attaching EEPROM instance

Today in history: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

滴滴 - eta(Estimate the Travel Time)

475-82(230、43、78、79、213、198、1143)
Technical Analysis | Doris connector combined with Flink CDC to achieve accurate access to MySQL database and table exactly once
![[unity introduction program] basic concepts - 2D collider collider 2D](/img/cf/a546238a5eaf4707006ecf1b7f19c6.png)
[unity introduction program] basic concepts - 2D collider collider 2D
随机推荐
Cache design in Web services (error allowed, error not allowed)
The difference between batchnorm and layernorm
P1046 [noip2005 popularity group t1] Taotao picking apples
pom容易忽略的问题
Test the mock data method of knowing and knowing
由两个栈组成的队列
刷题《剑指Offer》day01
How to reverse a stack with recursive functions and stack operations only
Network file storage system (III) practice of fastdfs distributed file system
Dijkstra序列(暑假每日一题 5)
Cerebral cortex: the relationship between lifestyle and brain function in the elderly and its relationship with cognitive decline
刷题《剑指Offer》day02
7.24模拟赛总结
while(~scanf(“%d“, &n)) 等价于 while(scanf(“%d“,&n)!=EOF)
2022-07-19 Daily: too many icml2022 papers to read? "One sentence comments on 1234 paper highlights" helps you quickly lock
Calculation formula of cross entropy
[ffmpeg] MP4 to YUV
RK3399开发板I2C4挂载EEPROM实例
oracle 触发器创建
Machine learning theory and case analysis (Part2) -- Regression
https://docs.python.org/zh-cn/3.7/library/sqlite3.html