0% found this document useful (0 votes)
20 views1 page

Aaaa

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Aaaa

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import os

import csv
import arcpy
from os import path
from arcpy import da
from arcpy import env

env.overwriteOutput = True
env.workspace = 'D:/Basura/Aforos/MNT_EA_SpatialJoin2.shp'

polygon_shp = path.join(env.workspace, 'MNT_EA_SpatialJoin2.shp')


vertex_csv_path = 'D:/Basura/Aforos/poly_vertex.csv'

def getPolygonCoordinates(fc):
"""For each polygon geometry in a shapefile get the sequence number and
and coordinates of each vertex and tie it to the OID of its corresponding
polygon"""

vtx_dict = {}
s_fields = ['OID@', 'Shape@XY']
pt_array = da.FeatureClassToNumPyArray(polygon_shp, s_fields,
explode_to_points=True)

for oid, xy in pt_array:


xy_tup = tuple(xy)
if oid not in vtx_dict:
vtx_dict[oid] = [xy_tup]
# this clause ensures that the first/last point which is listed
# twice only appears in the list once
elif xy_tup not in vtx_dict[oid]:
vtx_dict[oid].append(xy_tup)

vtx_sheet = []
for oid, vtx_list in vtx_dict.iteritems():
for i, vtx in enumerate(vtx_list):
vtx_sheet.append((oid, i, vtx[0], vtx[1]))

writeVerticesToCsv(vtx_sheet)

def writeVerticesToCsv(vtx_sheet):
"""Write polygon vertex information to csv"""

header = (
'oid', 'sequence_id',
'x_coordinate', 'y_coordinate')

with open(vertex_csv_path, 'wb') as vtx_csv:


vtx_writer = csv.writer(vtx_csv)
vtx_writer.writerow(header)

for row in vtx_sheet:


vtx_writer.writerow(row)

getPolygonCoordinates(polygon_shp)

You might also like