Friday 21 October 2016

python - CSV to shapefile missing file


I transform a csv file into a shapefile using the following script:


import shapefile as shp  
import csv
import tkinter.filedialog
import urllib.request
import os

a = 'csvFiletoTransform.csv'


filename = 'C:/TEMP/ToscaAuxiliar.csv'
urllib.request.urlretrieve(a,filename)

out_file = tkinter.filedialog.asksaveasfilename()

nombre,codigo,y,x,time=[],[],[],[],[]



with open('C:/TEMP/xxxx.csv', 'r') as csvfile:
r = csv.reader(csvfile, delimiter=',')
for i,row in enumerate(r):
if i > 0: #skip header
nombre.append(row[0])
codigo.append(row[1])
y.append(float(row[2]))
x.append(float(row[3]))
time.append(str(row[4]))



w = shp.Writer(shp.POINT)
w.autoBalance = 1 #ensures gemoetry and attributes match
w.field('Longitud','F',10,8)
w.field('Latitud','F',10,8)
w.field('Date','D')
w.field('Date / Time','C',50)
w.field('ID','N')


for j,k in enumerate(x):
w.point(k,y[j]) #write the geometry
w.record(k,y[j],codigo[j], time[j], nombre[j])

os.remove('C:/TEMP/xxxx.csv')
w.save(out_file)

it works, but the .prj file is lost.


It creates only the .dbf .shp & .shx files.


How can I do to create the prj file also ?





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...