How can I convert an excel spreadsheet (.xls) to a shapefile programmatically?

fmark picture fmark · Jul 5, 2010 · Viewed 11.2k times · Source

I have an excel spreadsheet I want to convert to an ESRI shapefile programmatically. It contains X and Y coordinates in two columns, as well as a variety of attribute data in other columns. The spreadsheet is in excel 97 format (i.e. not .xlsx).

I would like to be able to convert this to a point geometry shapefile, with each row's x,y pair representing a point. Ideally, I would like to have a third column specifying the coordinate system of the x,y coordinate pair, and have the excel file contain heterogenous coordinate systems.

How can I convert this excel spreadsheet (.xls) to a shapefile programmatically? Preferably in Python, but other implementations will be accepted.

Answer

ebt picture ebt · Jul 5, 2010

something like this?

import xlrd
book = xlrd_open_workbook("data.xls") 
sheet = book.sheet_by_index(0)  
data = [] #make a data store
for i in xrange(sheet.nrows):
  row = sheet.row_values(i)
  x=row[0]
  y=row[1]
  data.append(x,y)

import point_store
point_store.save('points-shifted.shp', [data], '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')