#------if the fields in the output layer need to be changed do it here------#
def convertor(newPoints, outputShape):
global newPointsPath, newPointsPath
arcpy.env.overwriteOutput = True
# arcpy.env.overwrite = True
print 'Setting up Schema'
#-----This adds all the fields needed for the XY Event Layer to be exactly the same as surveyor.SLCOSU.PLSS_Control_Points---#
out = outputShape
arcpy.AddField_management(out, "doc_id", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "vault_id", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "security", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "date_added", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "POINT_NAME", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "GRID_ADDRE", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "MAILING_AD", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "TOWNSHIP_R", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "SECTION", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "NORTHING", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "EASTING", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "ELEVATION_", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "ELEVATION1", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "MAP_SCALE", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "CONVERGENC", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "MON_TYPE", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "MON_DESCRI", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "MON_NOTES", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "MON_STATUS", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "GCDB", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "REMARKS", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "COMBINED_S", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "PUBLISH", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "MON_RESET_", "DATE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "DATE_DIFF_", "DATE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "VERIFIED", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "PLATTED", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "VALIDATION", "DATE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "CONTROL_US", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "job_done", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "GEOID_USED", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
#Change back to date later#
arcpy.AddField_management(out, "DATE_LAST_", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "LATITUDE", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "LONGITUDE", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "GRID_NS", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "DIR_NS", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "GRID_EW", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(out, "DIR_EW", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.DeleteField_management(out, ["Field1", "Field2", "Field3", "Field4", "Field5"])
#----Sets up our iterators---#
arcpy.MakeFeatureLayer_management(quarterSectionFile, 'ToSelectedQuarters')
arcpy.SelectLayerByLocation_management('ToSelectedQuarters', "CONTAINS", out)
arcpy.FeatureClassToFeatureClass_conversion('ToSelectedQuarters', output, 'SelectedQuarters')
newQuaterPath = output + '\\' + 'SelectedQuarters'
quarterSections = arcpy.UpdateCursor(newQuaterPath)
quarterSection = quarterSections.next()
arcpy.MakeFeatureLayer_management(pointsFile, 'ToSelectedPoints')
#----Sets current date to a string----#
now = datetime.datetime.now().strftime("%m-%d-%y")
#-----This while loop will get the highest point name in the section then assign all default values and known values to the given attribute table----#
it = 1
if not quarterSection:
print 'nothing selected'
print 'Adding Feilds'
for quarterSection in quarterSections:
highestPoint = 0
#------Gets the highest point name in section-----#
arcpy.CreateFeatureclass_management(output, 'TempQuarter')
tempQuartPath = output + '\\' + 'TempQuarter'
insert = arcpy.InsertCursor(tempQuartPath)
insert.insertRow(quarterSection)
arcpy.SelectLayerByLocation_management('ToSelectedPoints', "WITHIN", tempQuartPath)
arcpy.FeatureClassToFeatureClass_conversion('ToSelectedPoints', output, 'SelectedPoints')
newPointsPath = output + '\\' + 'SelectedPoints'
points = arcpy.UpdateCursor(newPointsPath)
for point in points:
if CornerCheck(point.POINT_NAME):
continue
else:
pointName = point.POINT_NAME
pointTM = pointName[0]
pointM = pointName[1]
pointHT = pointName[2]
pointTT = pointName[3]
pointT = pointName[4]
pointH = pointName[5]
pointTen = pointName[6]
pointO = pointName[7]
pointNumber = int(pointTM)*10000000 + int(pointM)*1000000 + int(pointHT)*100000 + int(pointTT)*10000 + int(pointT)*1000 + int(pointH)*100 + int(pointTen)*10 + int(pointO)
if pointNumber > highestPoint:
highestPoint = pointNumber
layerRows = arcpy.UpdateCursor(out)
for key in newPoints.keys():
layerRow = layerRows.next()
# --This will standardize our data to add into the attribute table---#
id = newPoints[key]['id']
northing = newPoints[key]['Northing']
easting = newPoints[key]['Easting']
elevation = newPoints[key]['Elevation']
type = newPoints[key]['Description'].split(' ')[0]
northingAddress = newPoints[key]['Description'].split(' ')[1]
northingDirection = newPoints[key]['Description'].split(' ')[2]
eastingAddress = newPoints[key]['Description'].split(' ')[3]
temp = newPoints[key]['Description'].split(' ')[4]
eastingDirection = temp.split('-')[0]
mon_descript = temp.split('-')[1]
Grid_ad = '%s %s %s %s' % (northingAddress, northingDirection, eastingAddress, eastingDirection)
Mailing_ad = newPoints[key]['Mailing']
lastshot = newPoints[key]['Date_Shot']
geoid = newPoints[key]['Geoid']
if highestPoint is 0:
tempNumber = str(quarterSection.getValue('Area')) + str(quarterSection.getValue('SECTION')) + str(quarterSection.getValue('Quarter_Num')) + str('000')
highestPoint = int(tempNumber)
highestPoint += 1
tempNum = str(highestPoint)
else:
highestPoint = int(highestPoint) + 1
tempNum = str(highestPoint)
# ----Updates the rows in our atribute table with the values in the dictionary---#
layerRow.setValue("doc_id", None)
layerRow.setValue("vault_id", None)
layerRow.setValue("security", None)
layerRow.setValue("date_added", now)
layerRow.setValue("POINT_NAME", tempNum)
layerRow.setValue("GRID_ADDRE", Grid_ad)
layerRow.setValue("MAILING_AD", Mailing_ad)
layerRow.setValue("TOWNSHIP_R", quarterSection.getValue('TOWN_RANGE'))
layerRow.setValue("SECTION", quarterSection.getValue('SECTION'))
layerRow.setValue("NORTHING", northing)
layerRow.setValue("EASTING", easting)
layerRow.setValue("ELEVATION_", None)
layerRow.setValue("ELEVATION1", elevation)
layerRow.setValue("MAP_SCALE", None)
layerRow.setValue("CONVERGENC", None)
layerRow.setValue("MON_TYPE", type)
layerRow.setValue("MON_DESCRI", mon_descript)
layerRow.setValue("MON_NOTES", None)
layerRow.setValue("MON_STATUS", None)
layerRow.setValue("GCDB", None)
layerRow.setValue("REMARKS",None)
layerRow.setValue("COMBINED_S", None)
layerRow.setValue("PUBLISH", None)
layerRow.setValue("MON_RESET_", None)
layerRow.setValue("DATE_DIFF_", None)
layerRow.setValue("VERIFIED", None)
layerRow.setValue("PLATTED", None)
layerRow.setValue("VALIDATION", None)
layerRow.setValue("CONTROL_US", None)
layerRow.setValue("job_done", None)
layerRow.setValue("DATE_LAST_", lastshot)
layerRow.setValue("LATITUDE", None)
layerRow.setValue("LONGITUDE", None)
layerRow.setValue("GRID_NS", northingAddress)
layerRow.setValue("DIR_NS", northingDirection)
layerRow.setValue("GRID_EW", eastingAddress)
layerRow.setValue("DIR_EW", eastingDirection)
layerRow.setValue("GEOID_USED", geoid)
layerRows.updateRow(layerRow)
del newPoints[key]
points.reset()
arcpy.Delete_management(tempQuartPath)
if newQuaterPath:
arcpy.Delete_management(newQuaterPath)
if newPointsPath:
arcpy.Delete_management(newPointsPath)
del layerRow, layerRows, quarterSections, quarterSection