# arcpy: creating polyline features from the following text file format

I am looking into a way of reading the following file format with python, where

0 0, 0 1, 0 2, ect... is the polyline object number and 0(1) 464736.1645 260940. 098377 are x, y coordinates of polyline feature start/end.

How I can scan through this text file to read a polyline object and correspsonding start/end coordinates.

PS. CreateFeaturesFromTextFile ESRI script tool does not work properly in arcpy (arcgis 10) hence the need to create polylines from text file.

Many thanks,

Meryloo this question or answer is not directly related to gis. but i have write sth. which will solve your problem. in python, you can make lots of way out for your problem as this example code. you can get results with another way which changes to your standpoint.

i have assumed that your locations are all in polyline.txt file.

file = open("polyline.txt", 'r')
FPoint = [] # Start Points Array
SPoint = [] # End Points Array
finalArray = [] # Final Array with Start and End Points

for line in file:
ln =  line.rstrip().split(' ')
if len(ln) > 2:
if ln == '0':
fPoint = [ln,ln]
print 'Start Point', 'X:', ln, 'Y:', ln
FPoint.append(fPoint)
else:
sPoint = [ln,ln]
print 'End Point', 'X:', ln, 'Y:', ln
SPoint.append(sPoint)

# Appending Last Array
for a in range(len(FPoint)):
finalArray.append([[FPoint[a], FPoint[a]],[SPoint[a], SPoint[a]]])

print finalArray


in last array, you can get line from something like this scheme :

[['Start Point 1', 'End Point 1'], ['Start Point 2', 'End Point 2']]

End the result:

Start Point X: 464736.164805 Y: 260940.098387
End Point X: 464707.179968 Y: 260900.098387
Start Point X: 464728.067242 Y: 260945.96605
End Point X: 464699.082405 Y: 260905.96605
Start Point X: 464719.969679 Y: 260951.833714
End Point X: 464690.984842 Y: 260911.833714
[[['464736.164805', '260940.098387'], ['464707.179968', '260900.098387']],
[['464728.067242', '260945.96605'], ['464699.082405', '260905.96605']],
[['464719.969679', '260951.833714'], ['464690.984842', '260911.833714']]]


i hope it helps you...

• Many thanks! That is exactly what I was looking for. May 3, 2012 at 14:20