不使用示例数据时,无法将字符串转换为float

时间:2017-07-12 11:10:43

标签: python string arcmap

我正在运行以下python代码:

import arcpy
import polyline
import csv
import re

fc = "E:\\GoogleString\\CadastreCoordinates\\version1\\coordinates.gdb\\cadastre_wc_1"
csvfile = "E:\\GoogleString\\CadastreCoordinates\\version1\\WC\\output.csv"
cursor = arcpy.SearchCursor(fc)
coord_list = []
ltlong = []
final_strings=[]

for row in cursor:
    co = row.getValue("coordinates")
    sg = row.getValue("sg21key")
    testa = re.sub('(,[^,]*),', r'\1 ', co)
    testb = re.sub('[()]', '', testa)
    test2 = testb.split(' ')
    coord_list.append(test2)
    coords = [map(float,a.split(',')) for a in test2]
    ltlong.append([sg,coords])

for i in ltlong:
    string=polyline.encode(i[1],5)
    final_strings.append([i[0],string])

with open(csvfile, "w") as output:
    writer = csv.writer(output, lineterminator='\n')
    writer.writerows(final_strings)

在我的示例fc上,我获得了我想要的输出,并且我的代码成功运行但是当我运行我的整个fc时,它告诉我我无法将字符串转换为浮点数。但它只是一个样本相同的数据。请帮忙不知道该怎么做。

ERROR:

Traceback (most recent call last):
  File "C:\Handri\Python\google_str3.py", line 20, in <module>
    coords = [map(float,a.split(',')) for a in test2]
ValueError: could not convert string to float: 

0 个答案:

没有答案