用于提取坐标的python正则表达式

时间:2012-05-14 13:32:22

标签: regex

有人可以帮我使用正则表达式来提取此列表中MULTIPOLYGON中的三维坐标:

[(1,
  'public Library',
  'SRID=4326;MULTIPOLYGON(((352877.02163887 1233618.83923531 5,352872.32998848 1233609.44478035 5,352867.693426132 1233612.15611458 5,352861.67354393 1233602.76770592 5,352841.814386368 1233616.9818058 5,352848.495328903 1233625.69463921 5,352861.076768875 1233617.56668663 5,352866.429475784 1233626.28557014 5,352877.02163887 1233618.83923531 5)))')]

1 个答案:

答案 0 :(得分:2)

我认为这个正则表达式可能会在你的字符串中找到你要找的东西:'([\ d。] +?)\ s([\ d。] +?)\ s([\ d。] +? )'

我用python测试它,它返回一个坐标列表列表:

import re
foo = "SRID=4326;MULTIPOLYGON(((352877.02163887 1233618.83923531 5,352872.32998848 1233609.44478035 5,352867.693426132 1233612.15611458 5,352861.67354393 1233602.76770592 5,352841.814386368 1233616.9818058 5,352848.495328903 1233625.69463921 5,352861.076768875 1233617.56668663 5,352866.429475784 1233626.28557014 5,352877.02163887 1233618.83923531 5)))"
print re.findall('([\d.]+?)\s([\d.]+?)\s([\d.]+?)', foo)

打印:

[('352877.02163887', '1233618.83923531', '5'), ('352872.32998848', '1233609.44478035', '5'), ('352867.693426132', '1233612.15611458', '5'), ('352861.67354393', '1233602.76770592', '5'), ('352841.814386368', '1233616.9818058', '5'), ('352848.495328903', '1233625.69463921', '5'), ('352861.076768875', '1233617.56668663', '5'), ('352866.429475784', '1233626.28557014', '5'), ('352877.02163887', '123361 8.83923531', '5')]