[英]Referencing alphabet beyond Z… ie AA, AB
I have no idea what I am doing with Python. My only experience with it is in QGIS and I am a novice at that too.我不知道我在用 Python 做什么。我唯一的经验是在 QGIS 中,我也是新手。 I have tried to search for something that fits what I am looking for but it's not making sense, maybe because of how it sits within QGIS
我试图搜索适合我正在寻找的东西,但它没有意义,可能是因为它在 QGIS 中的位置
I am using QGIS mapping to create Atlas style grids.我正在使用 QGIS 映射来创建 Atlas 风格的网格。 This has resulted in me finding the following code to apply to a virtual layer…
这导致我找到以下代码以应用于虚拟层......
select *, char(r+64) || ROW_NUMBER() OVER(PARTITION BY r) as newID from (SELECT *,DENSE_RANK() OVER (ORDER BY round( ST_minY(geometry)/0.02) desc) as r FROM Grid ORDER BY round(ST_minY(geometry)/0.02) DESC, round(ST_minX(geometry)/0.02) ASC)
From https://gis.stackexchange.com/questions/344161/how-to-create-a-grid-with-customized-labels-in-qgis来自https://gis.stackexchange.com/questions/344161/how-to-create-a-grid-with-customized-labels-in-qgis
My issue is that the char(r+64) bit continues into ASCII symbols and then lowercase after reaching “Z”我的问题是 char(r+64) 位继续进入 ASCII 符号,然后在到达“Z”后小写
Is there a way to modify this code to make it continue beyond Z in the style of excel columns?有没有办法修改这段代码,使其以 excel 列的样式继续超出 Z? Ie AA, AB etc.
即 AA、AB 等。
I don't mind if it is has limits or each reference needs to be typed in.我不介意它是否有限制或每个参考文献都需要输入。
Here is a quick code to generate a pool of letter identifiers (A->Z, AA->ZZ).这是生成字母标识符池(A->Z,AA->ZZ)的快速代码。 There are 702 identifiers, if you need more you can easily add more levels on the same principle.
有 702 个标识符,如果您需要更多,您可以根据相同的原则轻松添加更多级别。
from string import ascii_uppercase
from itertools import product
pool = list(map(''.join, product(['']+list(ascii_uppercase), list(ascii_uppercase))))
>>> pool
['A', 'B', 'C', ..., 'ZY', 'ZZ']
If you want to map numbers to those, you can use: dict_pool = dict(enumerate(pool))
如果你想将 map 个数字分配给那些,你可以使用:
dict_pool = dict(enumerate(pool))
{0: 'A',
1: 'B',
2: 'C',
3: 'D',
...
699: 'ZX',
700: 'ZY',
701: 'ZZ'}
I came up with this and it works….我想出了这个并且它有效...... I just need to add in extra lines for each time it cycles through 26.
我只需要在每次循环 26 时添加额外的行。
‘select *,
Case
when r<=26 then char(r+64) || ROW_NUMBER() OVER(PARTITION BY r)
when r between 27 and 52 then 'A' || char(r+38) || ROW_NUMBER() OVER(PARTITION BY r)
else 'B' || char(r+12) || ROW_NUMBER() OVER(PARTITION BY r)
end as newID
from
(SELECT *,DENSE_RANK() OVER (ORDER BY round( st_minx(geometry)/0.02) asc) as r
FROM Grid
ORDER BY round(ST_minY(geometry)/0.02) DESC,
round( ST_minX(geometry)/0.02) ASC)’
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.