Rather that getting the user to change the order/style of the points it would be best to change the code to suit the input.. I would imagine when you need to write a script to import points you'd have a lot of them..
I would try to split the lines using string.split and if I tried a few possible delimiters and still ended up with a list of 1 then skip the line:
Point <- skip, only one element
0 347172.2 4269952.7 60.9090909091 <- do this one, 4 elements
1 337172.8 4278952.4 85.7334909091 <- do this one, 4 elements
2 344572.3 4547952.2 123.909673091 <- do this one, 4 elements
3 347532.8 8777952.8 456.467809091 <- do this one, 4 elements
END <- skip, only one element
This is fairly easy to code for:
import os, sys, arcpy
InFile = sys.argv[1]
OutShp = sys.argv[2]
EPSG = sys.argv[3]
try:
SR = arcpy.SpatialReference(int(EPSG))# create a spatial reference from EPSG definition
except:
arcpy.AddWarning(arcpy.GetMessages())
arcpy.AddError("Unable to create spatial reference with code %s" % EPSG)
sys.exit(0)
#break up OutShp to folder and name
OutFolder = os.path.dirname(OutShp)
OutName = os.path.basename(OutShp)
# Create the output feature class
arcpy.CreateFeatureclass_management(OutFolder,OutName,"POINT",has_z="ENABLED",spatial_reference=SR)
# add fields to store the values
arcpy.AddField_management(OutShp,"PntID","INTEGER")
arcpy.AddField_management(OutShp,"Xcoord","DOUBLE")
arcpy.AddField_management(OutShp,"Ycoord","DOUBLE")
arcpy.AddField_management(OutShp,"Zcoord","DOUBLE")
with open(InFile,'r') as srcFile:
with arcpy.da.InsertCursor(OutShp,["SHAPE@","PntID","Xcoord","Ycoord","Zcoord"]) as InsCur:
for fileLine in srcFile:
# split the line up into a list
# 1 337172.8 4278952.4 85.7334909091 becomes [1,337172.8,4278952.4,85.7334909091]
# try a few common delimiters: tab, space, comma, pipe..
lSplit = fileLine.split("\t")
if len(lSplit) == 1:
lSplit = fileLine.split(" ")
if len(lSplit) == 1:
lSplit = fileLine.split(",")
if len(lSplit) == 1:
lSplit = fileLine.split("|")
if len(lSplit) > 1:
# more than just one word on the line
pointsOK = True
try:
ID = int(lSplit[0])
Xcoord = float(lSplit[1])
Ycoord = float(lSplit[2])
Zcoord = float(lSplit[3])
except:
arcpy.AddWarning("Unable to translate points")
pointsOK = False
if pointsOK:
# create a point geometry from the 3 coordinates
newGeom = arcpy.PointGeometry(arcpy.Point(Xcoord,Ycoord,Zcoord))
newGeom.spatial_reference = SR # set spatial reference
# you could project here using newGeom.projectAs(SpatialRef)
# if you needed them in a different spatial reference
InsCur.insertRow([newGeom,ID,Xcoord,Ycoord,Zcoord])# insert this point into the feature class
Arcpy insert cursor (arcpy.da.InsertCursor) does not allow "SHAPE@XYZ", but you can address this using "SHAPE@" and using a geometry object in arcpy. This is especially handy if you have the coordinates in a different spatial reference and need to project on the way in.
inTxt
andstrms
? What error or other symptom is seen when you run that? Please use the edit button to provide a more detailed description of what you have tried and where you are stuck. I wondered what your last line was about and found resources.arcgis.com/en/help/main/10.2/index.html#//… - linking to help associated with any lesser known functions that you are using can be a good way to help potential answerers help you.