Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to study a range of data using the same technique in ArcMAP (it will take too much time to do it one by one ;) !). I've been just recently playing with ArcMAP and Python (which can help me to generate an automatic sequence).

I also read that it is easier to import .csv file into ArcMAP.

I'm importing the csv file using csv.reader (just coordinate of points without header, two colums x and y) like:

file = csv.read(...)

Then I didn't managed to print the file, because i obtained this message:

<_csv.writer object at 0x1426F7B0>

And I want to put the first column in the x coordinate and the second column in the y coordinate in a point shapefile?

I read a lot of information how to create file. But I'm stuck in taking the first and second column of my file.

Can you give me some advices?

TA

share|improve this question

2 Answers 2

up vote 4 down vote accepted

For this CSV file, simple-csv.csv:

34.79038,-96.80871,"4/13/1983"
34.93032,-96.44490,"2/5/1967"
34.95507,-96.92268,"12/23/2001"
34.95689,-96.92263,"8/9/1999"
34.92559,-96.68021,"8/25/1954"

This code will open it up and print it out:

>>> # import csv module
>>> import csv
>>> # open and read the csv file into memory
>>> file = open(‘C:/testing/simple-csv.csv’)
>>> reader = csv.reader(file)
>>> # iterate through the lines and print them to stdout
>>> # the csv module returns us a list of lists and we
>>> # simply iterate through it
>>> for line in reader:
...     print line
...
[‘34.79038’, ‘-96.80871’, ‘4/13/1983’]
[‘34.93032’, ‘-96.44490’, ‘2/5/1967’]
[‘34.95507’, ‘-96.92268’, ‘12/23/2001’]
[‘34.95689’, ‘-96.92263’, ‘8/9/1999’]
[‘34.92559’, ‘-96.68021’, ‘8/25/1954’]

If you wanted to only get the first and second columns, do something like:

for line in reader:
    print line[0], line[1]
share|improve this answer
4  
And if your CSV file has a header row I would recommend using the DictReader instead, that way you can reference row values by header name instead of index. It will also automatically skip the first row for you in the returned iterable. –  blah238 Feb 21 '12 at 5:10

Here is a link that shows how to create point shp from a table.

http://nrm.salrm.uaf.edu/~dverbyla/nrm638/labs/memory_scripts/Excel_to_Merged_Points.py

You could also use the Make XY Event Layer tool/python code to create a point feature layer, which could then be exported out as a new shp.

share|improve this answer

Your Answer

 
discard

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.