AnsweredAssumed Answered

ArcPy imported points not displaying in correct location

Question asked by cnetto on Aug 18, 2014
Latest reply on Aug 19, 2014 by cnetto

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

Outcomes