Python 中的 Arcgis:每次执行都会更改颜色。如何设置填充颜色?

Arcgis in Python: Color change on each execution. How to set fill color?

我想在地图上用特定颜色绘制多边形。阅读文档后: https://developers.arcgis.com/python/api-reference/arcgis.geometry.html ,我无法 select 正确的填充颜色。事实上,使用相同的代码,颜色会在每次执行时发生变化。

下面是一些示例代码:

import arcgis
from arcgis.gis import GIS
from arcgis.geometry import Geometry, Point, Polyline
from arcgis.mapping import create_symbol

gis = GIS()
map1 = gis.map(location=(39.456727, -0.352371), zoomlevel=15)
map1.basemap = "osm"


geom = Geometry({'spatialReference': {'latestWkid': 4326,
    'wkid': 4326},
    'rings': [
    [
            [-0.3524, 39.4566],
            [-0.3524, 39.4568],
            [-0.3522, 39.4568],
            [-0.3522, 39.4566],
            [-0.3524, 39.4566],
        ]
    ]
})
symbol = create_symbol(geometry_type='polygon', colors=[0, 255, 0])  # green

map1.draw(geom, symbol=symbol)
map1.export_to_html("test.html")

如果我执行此命令并使用浏览器打开 test.html,我可以看到:

如果我再次执行相同的代码并打开 test.html,颜色会神奇地改变:

那么,2 个问题: 1)为什么每次执行都会改变颜色? 2) 如何设置正确的颜色?我将颜色设置为 [0, 255, 0] 但它不起作用

要正确设置区域和点的颜色,我发现您可以在 colors 带有 alpha 通道的参数中添加第四个参数:

symbol = create_symbol(geometry_type='polygon', colors=[0, 255, 0, 255])  # green

根据 https://developers.arcgis.com/python/api-reference/arcgis.mapping.html 中的文档,alpha 值应该在 0-1 范围内,但这应该是一个错误,因为它只有在您将值放在 0-255 范围内时才有效。

如果您不添加 alpha 通道,colors 参数将被视为无效,并为其分配一个随机值。这就是每次执行时颜色都会改变的原因