I have a CSV communicating directly with a series of points and lines. The CSV is a bit problematic, however. The hardware that provides the data only provides location data every few rows. That is, there is an attribute table with X and Y columns whose fields are only filled only at key times. The rest is other still useful data, but location is only updated intermittently.
I have my point feature structured so that only the bottom-most (most recent) attribute row is used to display one point. Naturally I need location data for that bottom-most row, otherwise the point disappears. Currently I'm not getting it but sporadically. My CSV -> point code looks like this currently (pyshp library used):
cur_dir = os.path.dirname(os.path.realpath(__file__)) file_location = os.path.join(cur_dir, "data", "mycsv.csv") out_file = os.path.join(cur_dir, "data", "mypoint.shp") idd, az, y, x = , , ,  with open(file_location, 'rb') as csvfile: r = list(csv.reader(csvfile, delimiter=',')) reader = r[len(r) - 1:] #read only top row for i, row in reversed(list(enumerate(reader))): #reverse table idd.append(str(row)) az.append(float(row)) y.append(float(row)) x.append(float(row)) print "appended" w = shapefile.Writer(shapefile.POINT) w.field('ID', 'N') w.field('AZIMUTH', 'N', 12) w.field('Y', 'F', 10, 8) w.field('X', 'F', 10, 8) for j, k in enumerate(x): #write shapefile w.point(k, y[j]) w.record(idd[j],az[j],y[j], k ) print "recorded" w.save(out_file)
I have started by trying to add
if x > 0: conditionals in various places below the multiple enumerators to possibly halt digitization until data is read, but I am given error
min() arg is an empty sequence each time. I'm not even sure this is the right place to begin, as it would probably just put attributes out of sequence with each other. I really just need some sort of "if X or Y field is null, populate field with prior field's data" script.
I am using Python 2.7, developing out of QGIS 2.8 API, and running on Ubuntu 14.04,