1

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.

Your help is much appreciated.

Many thanks,

Meryloo

enter image description here

3

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] == '0':
            fPoint = [ln[1],ln[2]]
            print 'Start Point', 'X:', ln[1], 'Y:', ln[2]
            FPoint.append(fPoint)
        else: 
            sPoint = [ln[1],ln[2]]
            print 'End Point', 'X:', ln[1], 'Y:', ln[2]
            SPoint.append(sPoint)


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

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. – meryloo May 3 '12 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.