次の形式の文字列があります。
ポリゴン ((159.5 534.5、157.5 535.5、157.5 554.5、155.5 557.5、...))
次のようなタプルのリストに変換したい:
[(159.5, 534.5), (157.5, 535.5), (157.5, 554.5), (155.5, 557.5), ...]
ありがとうございました
>>> re.findall(r'([\d\.]+)\s([\d\.]+)', the_string)
[('159.5', '534.5'), ('157.5', '535.5'), ('157.5', '554.5'), ('155.5', '557.5')]
次に、各アイテムをフロートに変換するだけです
オプションのように、これを試すことができます:
data = "POLYGON ((159.5 534.5, 157.5 535.5, 157.5 554.5, 155.5 557.5))"
print [tuple(map(float, x.split())) for x in data.replace('POLYGON ((', '').replace('))', '').strip().split(', ')]
またはリスト内包表記なし:
data = data.replace('POLYGON ((', '').replace('))', '').strip()
res = []
for rec in data.split(', '):
res.append(tuple(float(val) for val in rec.split()))