Select to view content in your preferred language

Points to Lines

1049
4
04-19-2010 01:22 AM
neilwebster
Emerging Contributor
Hi All,

I have a dbf file with from and to points.  I'm trying to use the python examples to generate a polyline  but it is defeating me!

The script I have been using is below.  Whenever it is run it generates one visible line and creates attribute table entries for the other rows in the input table.

Can anybody suggest what is going wrong?

Cheers,  Neil.

Code (the indentation might not be correct on the posting):

import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = True


Out = r"C:\Test_Out.shp"
In = r"C:\In.dbf"

gp.workspace = os.path.dirname(Out)
gp.CreateFeatureclass(os.path.dirname(Out), os.path.basename(Out), "POLYLINE")

cur = gp.InsertCursor (Out)
Searchrows = gp.SearchCursor(In)
Searchrow = Searchrows.Next()
while Searchrow:
row = cur.NewRow()

LineArray = gp.CreateObject("Array")
pnt = gp.CreateObject ("Point")

pnt.x = Searchrow.GetValue("From_Lon")
pnt.y = Searchrow.GetValue("From_Lat")
LineArray.add(pnt)
 
pnt.x = Searchrow.GetValue("To_Lon")
pnt.y = Searchrow.GetValue("To_Lat")
LineArray.add(pnt)

print Searchrow.GetValue("To_Lon"), Searchrow.GetValue("To_Lat")
row.shape = LineArray
cur.InsertRow(row)

Searchrow = Searchrows.Next()


del row, cur
0 Kudos
4 Replies
BradPosthumus
Frequent Contributor
I tested this script and it produced the lines expected, using a test dbf. When you run it, are you getting multiple copies of the same line? What values are you getting for from this print statement:

print Searchrow.GetValue("To_Lon"), Searchrow.GetValue("To_Lat")
0 Kudos
neilwebster
Emerging Contributor
Thanks for the reply.

The line mentioned outputs the cordinates of the to nodes, as per the input file. 

However no line is created.  The only line created is for the first line of the input file.

Any ideas
0 Kudos
JonathanBaarda
Emerging Contributor
I just tried your code myself on a test dbf and got the right output. I would take a look at your test file. Maybe the points are identical?
0 Kudos
Jan_ToreKyrdalen
Occasional Contributor
Dont you allso need to give the points an id?

changing:

pnt.x = Searchrow.GetValue("From_Lon")
pnt.y = Searchrow.GetValue("From_Lat")
LineArray.add(pnt)

pnt.x = Searchrow.GetValue("To_Lon")
pnt.y = Searchrow.GetValue("To_Lat")
LineArray.add(pnt)


to:

pnt.id = some_counter
pnt.x = Searchrow.GetValue("From_Lon")
pnt.y = Searchrow.GetValue("From_Lat")
LineArray.add(pnt)

pnt.id = some_counter
pnt.x = Searchrow.GetValue("To_Lon")
pnt.y = Searchrow.GetValue("To_Lat")
LineArray.add(pnt)
0 Kudos