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
                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"


Here is a snippet of the CSV. You will see the chopped up columns on the right: enter image description here

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,

closed as off-topic by Vince, PolyGeo Oct 30 '15 at 0:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general Information Technology, with no clear GIS component, are off-topic here, but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software) and Database Administrators (relational databases)" – Vince, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Isn't this a just a straight Python issue? – Vince Oct 29 '15 at 22:01
  • @vince I'm not sure how to answer that. It might be? – Alex92 Oct 29 '15 at 22:05
  • 1
    GIS SE exists for GIS-centric questions. If the question is about Python code accessing GIS components, it's a GIS question; if the question is about Python looping or flow of control, it's a Python question. This question appears to be on the ragged edge between the two -- it's flow of control to access a library for GIS data, but it seems closer to a StackOverflow question (especially considering that your program logic is using more memory than necessary by saving all the data between read and write, instead of integrating the two -- read, write, read, write). – Vince Oct 29 '15 at 23:40
  • You have a QGIS tag but no QGIS library appears to be used in the code snippet that you have presented so this looks like Python rather than GIS to me too. – PolyGeo Oct 30 '15 at 0:03
  • @vince @polygeo I suppose my reasoning for asking this in GIS SE was that, while no QGIS library is used in this snippet of code, it does still implement pyshp, which is a python library for working with shapefiles. Because of this, I suspect my problem may be more familiar to a GIS coding community than a general coding community. However, I understand that this question still sits in a gray area. I'll ask elsewhere. – Alex92 Oct 30 '15 at 3:42

Browse other questions tagged or ask your own question.