ArcPy imported points not displaying in correct location

I'm using Python to read the points and add them to an existing shape file. The problem is that the all the points are in the same location and no where the location they are supposed to be. NOTE: If I calculate the X and Y fields, all the correct coordinates are displayed. If export the data and import back in, the points are in the correct location. Does anyone have any suggestions on fixing this?

import arcpy
arcpy.overwriteoutput = True
out_path = r"M:\work\nettoc\MAS201300311\PythonModule\import_data"
pointFC = r"M:\work\nettoc\MAS201300311\PythonModule\import_data\POI.shp"
geoType = "POINT"
StructurePoints = open(r"M:\work\nettoc\MAS201300311\PythonModule\import_data\TEST2.txt", "r")
coordList = []
# Parse the exported text file and create a list that Python can read
# figure out position of the lat and long in the header
headerLine = StructurePoints.readline()
valueList = headerLine.split(",")
latValueIndex = valueList.index('"SURF_LATITUDE"')
longValueIndex = valueList.index('"SURF_LONGITUDE"')
planValueIndex = valueList.index('"PLAN"')
typeValueIndex = valueList.index('"PLAN_SITE_TYPE"')
ancRadiusValueIndex = valueList.index('"ANCHOR_RADIUS"')
# Read line in the file and append to coordinate list
for line in StructurePoints.readlines():
# need to say what the seperating value is, in this case its the ","
segmentedLine = line.split(",")
# only append the value (index) indicated... we could have used "segmentedline[2]", but if lat changes position in the header list
# we would have to change the index number.
coordList.append([segmentedLine[planValueIndex], segmentedLine[typeValueIndex], segmentedLine[ancRadiusValueIndex], segmentedLine[longValueIndex], segmentedLine[latValueIndex]])
# Loop and delete any existing features in the shapefile
rows = arcpy.UpdateCursor(pointFC)
for row in rows:
rows.deleteRow(row)
del rows, row
print "Prepairing shape file..."
# Loop through new created coordlist and insert the the points in the existing shape file
rowInserter = arcpy.InsertCursor(pointFC)
#Loop through each coordinate in the list
for coordinate in coordList:
# Grab a set of coordinates from the list and assign them to a point obejct
longValue = float(coordinate[3])
latValue = float(coordinate[4])
pointGeometry = arcpy.Point(longValue,latValue)
# use the insert cursor to put in the point object in the feature class
newPoint = rowInserter.newRow()
newPoint.Shape = pointGeometry
newPoint.DESCR = coordinate[0] + ", " + coordinate[1]
newPoint.ANCHOR_RAD = coordinate[2]
rowInserter.insertRow(newPoint)
del rowInserter
print "The following points were created"
print coordList

Hmm, I cannot see anything obviously wrong with your code so it might be something about your data.

Did you verify that your longValue and latValue variables contain what you would expect for example using a print statement?

Below is your code where the inserting uses the InsertCursor in the data access module (but haven't tested it). If you have ArcGIS 10.1 and above, try it.

Filip.

import arcpy
arcpy.env.overwriteOutput = True
out_path = r"M:\work\nettoc\MAS201300311\PythonModule\import_data"
pointFC = r"M:\work\nettoc\MAS201300311\PythonModule\import_data\POI.shp"
geoType = "POINT"
StructurePoints = open(r"M:\work\nettoc\MAS201300311\PythonModule\import_data\TEST2.txt", "r")
coordList = []
# Parse the exported text file and create a list that Python can read
# figure out position of the lat and long in the header
headerLine = StructurePoints.readline()
valueList = headerLine.split(",")
latValueIndex = valueList.index('"SURF_LATITUDE"')
longValueIndex = valueList.index('"SURF_LONGITUDE"')
planValueIndex = valueList.index('"PLAN"')
typeValueIndex = valueList.index('"PLAN_SITE_TYPE"')
ancRadiusValueIndex = valueList.index('"ANCHOR_RADIUS"')
# Read line in the file and append to coordinate list
for line in StructurePoints.readlines():
# need to say what the seperating value is, in this case its the ","
segmentedLine = line.split(",")
# only append the value (index) indicated... we could have used "segmentedline[2]", but if lat changes position in the header list
# we would have to change the index number.
coordList.append([segmentedLine[planValueIndex], segmentedLine[typeValueIndex], segmentedLine[ancRadiusValueIndex], segmentedLine[longValueIndex], segmentedLine[latValueIndex]])
# Loop and delete any existing features in the shapefile
rows = arcpy.UpdateCursor(pointFC)
for row in rows:
rows.deleteRow(row)
del rows, row
print "Prepairing shape file..."
# Loop through new created coordlist and insert the the points in the existing shape file
with arcpy.da.InsertCursor(pointFC, ["SHAPE@", "DESCR", "ANCHOR_RAD"]) as rowInserter:
#Loop through each coordinate in the list
for coordinate in coordList:
# Grab a set of coordinates from the list and assign them to a point obejct
longValue = float(coordinate[3])
latValue = float(coordinate[4])
pointGeometry = arcpy.Point(longValue,latValue)
descr = coordinate[0] + ", " + coordinate[1]
andchor_rad = coordinate[2]
newrow = [pointGeometry, descr, anchor_rad]
rowInserter.insertRow(newrow)
del rowInserter
print "The following points were created"
print coordList

Or something like that anyway. Get the SR from the Describe object of the created feature class.

This has been a source of some confusion for me in the past in that arcpy has 2 sorts of "point" geometries.

Those created by arcpy.Point(X,Y) which can be inserted into polyline or polygon geometries (at which point the SR is applied), and those created by arcpy.PointGeometry(arcpy.Point([X,Y]), SR). The help files are not particularly good at explaining the difference.