black2013

Problem with ArcGIS Script to read from polygon vertices

Discussion created by black2013 on May 1, 2013
Latest reply on May 13, 2013 by timdine
Hello

I have a little problem with an ArcGIS script. The script transforms a polygon into his vertex points and save this into the txt file.

My problem is, the skript transforms all points from polygon into the txt file. The first and the last point from polygon is identical in the txt file. And I would like to prevent. I have already tried the number of counted points of a multipart features (part count = feat.partcount) to reduce by one so that just the last point when read is always left off but somehow it does not work for me.

Can not afford a little help someone you like? In Python, I am of not very good .....


Here is the script:

import string, os, sys, locale, arcgisscripting
gp = arcgisscripting.create()
gp.overwriteoutput = 1

msgNotEnoughParams = "Incorrect number of input parameters."
msgUseValidDecimalPointSep = "Please use one of the valid decimal point separators."

try:

if len(sys.argv) < 4: raise Exception, msgNotEnoughParams
inputFC = sys.argv[1]
outFile = open(sys.argv[2], "w")

arg3poss = ['default python output', 'locale decimal point', 'comma', 'period', '$sep$']
if sys.argv[3].lower() not in arg3poss: raise Exception, msgUseValidDecimalPointSep

if sys.argv[3].lower() == arg3poss[1]:
locale.setlocale(locale.LC_ALL, '')
sepchar = locale.localeconv()['decimal_point']
elif sys.argv[3].lower() == arg3poss[2]: sepchar = ','
elif sys.argv[3].lower() == arg3poss[3]: sepchar = '.'
elif sys.argv[3].lower() == arg3poss[4]: sepchar = '$SEP$'
elif sys.argv[3].lower() == arg3poss[0]: sepchar = ""

inDesc = gp.describe(inputFC)

inRows = gp.searchcursor(inputFC)
inRow = inRows.next()
outFile.write("X" + ";" + "Y" + ";" + "Z" + ";" + "M" + ";" + "Order" + ";" + inDesc.ShapeType+ "\n")

while inRow:
feat = inRow.GetValue(inDesc.ShapeFieldName)
partnum = 0
partcount = feat.partcount
while partnum < partcount:
part = feat.getpart(partnum)
part.reset()
pnt = part.next()
interiorring_count = 0
pnt_count = 0
while pnt:
outLine = str(pnt.x) + ";" + str(pnt.y) + ";" + str(pnt.z) + ";" + str(pnt.m) + ";" + str(pnt_count) + ";" + "'" + str(inRow.GetValue(inDesc.OIDFieldName)) + "_" + str(interiorring_count) + "'" + "\n"
if sepchar == "": outFile.write(outLine)
else: outFile.write(outLine.replace(".", sepchar))
pnt = part.next()
pnt_count += 1
if not pnt:
pnt = part.next()
if pnt:
pnt_count = 0
interiorring_count += 1

partnum += 1
inRow = inRows.next()
outFile.flush()
outFile.close()

except Exception, ErrorDesc:
gp.AddError(ErrorDesc[0])
if outFile: outFile.close()
gp.AddError(gp.getmessages(2))

Outcomes