I'm searching how the output of one program (text file with some writings, but also with data as numbers, dates, times, coordinates, all separated with commas) can be transformed to a Feature Dataset.
1) .txt -> .csv -> gp.TabletodBase and then it's nearly done.. But get problems writing csv with Excel dialect - all row is writen in one cell. So, I create the delimiter ';' to get the data into cell by cell.
f= open(rawtable, 'r') f2 = open(outtable, 'wb') csv.register_dialect('dotcoma', delimiter=';') writer=csv.writer(f2, dialect='dotcoma') for line in itertools.islice(f, 6, 7): #reading labels that are in 6'th row labels= line.strip('\n').split(",") writer.writerow(labels)
But well, then Arcgis does not recognize the table.. I have been trying to cast the data, like integers, floats, strings.. but that did not help..
2) .txt -> .shp... ----> THAT WORKS!!!
The shapefile does not have a type of time.. So was skiping it.
However tried the Pyshp library. But after creating fields blindly I record the tuple of all data in a row and I'm getting an error:
IndexError: tuple index out of range..
I simply write fields from the list of data, depending to which group they go:
for fieldname in labelkeys: if fieldname in t_int: w.field(fieldname, 'N', 8, 0) #1probl was here as I made '8' vs. 8 ! stpd ... else: w.field (fieldname,'C', 25)
Another problem with coordinates. I was writing floats... and it did not like it.. So I had to write integers. Plus one cannot pass a tuple to w.record(). Thanks to StackExchange I've learned the benefits of asterix :) and one simply has to write w.record(*mylist).
3) .txt -> feature class...
Here I have problems writing the entire row at once..(like the list of values) into a NewRow. Since field names are made automatically I can not for each make like
row.fieldname=somevariable. I have tried while looping to SetValues
row.setValue(labelkeys[unit], data[unit]) and then at the end of a list
rows.InsertRow(row) , but it seemed that it sets just one value. Though I tried by hand and got an error in data casting..
The error comes that I read data like string '34', cast it to int(34) and try to write into field with type 'DOUBLE' (since I grouped some data and wanted to make more generic types).
if labelkeys[unit] in t_int: if data[unit]: row.setValue(labelkeys[unit], int(data[unit]))
So for now.. nothing is really working..
Maybe there is some other way I have not though about?
If not, could anyone help to get the things work?...