I am trying to convert polygon geometry from one feature class to a 2 point line feature in another feature class. I am reading the data for the polygon(Anno) feature class with a Search Cursor and using an Insert cursor to add the update feature to the line feature class. The logic here basically work within ArcMap and ArcGIS Pro. But I want to run as a standalone script and it errors out when preforming the inscursor.insertRow(nrow). Not really sure what I am missing. The data is stored in an Enterprise database with the connection saved in the script's folder. Any help or suggests would be greatly appreciated.
import arcpy
import datetime
# Local variables:
web_esmtanno = "GISadmin to WebRandolph.sde\\WebRandolph.GISADMIN.esmtanno"
web_lotanno = "GISadmin to WebRandolph.sde\\WebRandolph.GISADMIN.lotanno"
web_LotAnnoLine = "GISadmin to WebRandolph.sde\\webrandolph.GISADMIN.TaxAnnotation\\webrandolph.GISADMIN.LotAnnoLine"
web_EsmtAnnoLine = "GISadmin to WebRandolph.sde\\webrandolph.GISADMIN.EsmtAnnoLine"
DB = "GISadmin to WebRandolph.sde"
arcpy.env.workspace = DB
def AnnotoLine(AnnoFS, LineFS):
try:
msg = arcpy.Describe(LineFS).baseName + " - " + arcpy.Describe(LineFS).dataType
print(msg)
msg = arcpy.Describe(AnnoFS).baseName + " - " + arcpy.Describe(AnnoFS).dataType
print (msg)
print (arcpy.Describe(AnnoFS).catalogPath)
inscursor = arcpy.da.InsertCursor(LineFS,['SHAPE@','TEXTSTRING','PID'])
cursor = arcpy.da.SearchCursor(AnnoFS,['OID@','SHAPE@','TextString'])
for row in cursor:
#print("In row cursor")
pntcnt = 0
ID = row[0]
poly = row[1]
txt = row[2].strip()
if poly.type == 'polygon':
poly1 = poly.getPart(0)
for pnt in poly1:
# print("Point: " + str(pntcnt))
if pntcnt == 0:
spoint = pnt
pntcnt += 1
# print(str(ID) + "(" + str(pntcnt) + ")-" + str(spoint.X) + "," + str(spoint.Y))
else:
if pntcnt < 4:
epoint = pnt
pntcnt += 1
# print (str(ID) + "(" + str(pntcnt) + ")-" + str(epoint.X) + "," + str(epoint.Y))
spref = poly.spatialReference
parray = arcpy.Array([spoint,epoint])
pline = arcpy.Polyline(parray,spref)
nrow = ([pline,text,ID])
inscursor.insertRow(nrow)
print (ID + ": was processed.")
else:
print (ID + ": shape invalid.")
except:
print("Error Inserting Rows" + arcpy.GetMessages(2))
finally:
del nrow, inscursor
del row, cursor
print ("Start time: " + datetime.datetime.now().strftime("%m/%d/%Y %I:%M%p"))
### Process: Update Parcel Annotation
try:
arcpy.DeleteFeatures_management(web_EsmtAnnoLine)
print "Cleared EsmtAnnoLine"
AnnotoLine(web_esmtanno,web_EsmtAnnoLine)
except:
##print "!! Could not update Annotation!!!"
msg = "Error updating Parcel Annotation!!!" + '\n'
msg += arcpy.GetMessages(2) + '\n'
print(msg)
##email_msg.sendmsg(msg,"Error UpdateWebAnno.py")
print "Finish time: " + datetime.datetime.now().strftime("%m/%d/%Y %I:%M%p")