简体   繁体   English

引用 Z 以外的字母表……即 AA、AB

[英]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.

相关问题 如何在python中编写字母bigram(aa,ab,bc,cd…zz)频率分析计数器? - How to write a alphabet bigram (aa, ab, bc, cd … zz) frequency analysis counter in python? 如何制作连续的字母列表python(从az然后从aa,ab,ac等) - How to make a continuous alphabetic list python (from a-z then from aa, ab, ac etc) 在Python中将&#39;aa&#39;转换为&#39;a&#39;并将&#39;ab&#39;转换为&#39;b&#39; - translate 'aa' to 'a' and 'ab' to 'b' in python a、b、aa、ab、ba、bb、aaa、aab 的生成器 - generator for a, b, aa, ab, ba, bb, aaa, aab 为什么 &#39;aa&#39; &lt; &#39;z&#39; 在 Python 中的计算结果为 True? - Why does 'aa' < 'z' evaluate to True in Python? 根据字母(AZ)分页 - Paginating based on the alphabet (A-Z) 根据字母(AZ)分页 - Paginated based on the alphabet (A-Z) 在字符串中查找字母相邻字母(2 种类型:aABClg = ABC,aAbcd = aA) - Find alphabet neighbour letters in string (2 types: aABClg = ABC, aAbcd = aA) Python 中的排序字典(AA 必须在 Z 之后) - Sorting dictionary in Python (AA must come after Z) 是否可以将文件从 URL 部分上传到 S3? 文件.aa、文件.ab、文件.ac - is it possible to upload a file to S3 from a URL in parts? file.aa, file.ab, file.ac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM