Monday, 18 May 2015

Using PyShp to create polygon shapefiles?


I have a script for creating points shapefiles, but I can not fix it for make a new polyline shp file.


I have obtained the data from a excel file and extract data in three differents lists Lon,lat,label


import shapefile as shp
from openpyxl import load_workbook
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

r = 'myfile.xlsm'


wb = load_workbook(filename= r, data_only=True, use_iterators = True)
ws = wb['Export_Area']
cell_range = ws ['B5:D9']
tuple(ws.iter_rows('B5:D9'))
lista = []
for row in ws.iter_rows('B5:D9'):
for cell in row:

lista.append(cell.value)
Longitud_area = (lista[1:len(lista):3])
latitud_area = (lista[0:len(lista):3])
puntos_area = (lista[2:len(lista):3])


out_file = 'ExportArea.shp'


x,y,id_no=Longitud_area,latitud_area,puntos_area

logic = [True,False,True]
w = shp.Writer(shp.POINT)
w.autoBalance = 1 #ensures gemoetry and attributes match
w.field('X','F',10,5)
w.field('Y','F',10,5) #float - needed for coordinates
w.field('etiqueta','D') #date


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

w.record(k,y[j],puntos_area[j]) #write the attributes


prj = open(out_file +'.prj', 'w')
proyeccion ="GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
prj.write(proyeccion)

It works fine for a point shp file but I can not see how to do the loop for making a poly shp file




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