Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a python script which converts csv data to shapefiles. It converts but won't get angle from csv.

Can anyone help me?

The CSV data looks like this:


And the Python script is:

import shapefile as shp
import csv
import os
import sys

fileToOpen = open('test.csv', "rb")

#Set up blank lists for data

#read data from csv file and store in lists
with open(fileToOpen, 'rb') as csvfile:
    print "File found and will be now converted"
    r = csv.reader(csvfile, delimiter=";")
    for i,row in enumerate(r):
        print row
        if i > 0: #skip header

#Set up shapefile writer and create empty fields
w = shp.Writer(shp.POINT)
w.autoBalance = 1 #ensures gemoetry and attributes match

#loop through the data and write the shapefile
for j,k in enumerate(x):
    w.point(k,y[j]) #write the geometry
#Save shapefile"Resultat/" + out_file3)
print "Done!"
share|improve this question
what do you mean when you say: 'wont get angle from csv'? – Devdatta Tengshe Nov 21 '12 at 11:11

You need to ensure that the angle read from the csv is cast as an integer and not a string as it may be at present. To do this change the line: angle.append(row[3]) to: angle.append(int(row[3]))

The second thing to correct is that you have not specified a length of the angle field, which can cause pyshp some problems, so specify a length, in this case 4 should be suitable:


These two fixes should allow the data to be written to the angle field of the attribute table.

share|improve this answer

The problem I think is that you created four attributes


but you tried to put six things on it


It should just be


If you want to add k and y[j] then you'd have to create the corresponding attributes/fields.

share|improve this answer
the geometry should be fine, your suggestion would also work but the value k is an iterator through the list x, so will give the correct coordinates. – sgrieve Nov 21 '12 at 11:46
Oops. That's rather embarrassing. Thanks for catching that :) – R.K. Nov 21 '12 at 11:51
No worries, I didn't notice the 6 attributes being written into 4 fields :) – sgrieve Nov 21 '12 at 11:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.