Eu criei um script python na semana passada (embora não use o ArcPy), que pega pontos que estão criando a geometria das linhas de ônibus (um shp de ponto) de acordo com um campo numérico seqüencial ("SEQ"). Você pode facilmente ajustá-lo para obter a coordenada de um campo do mesmo recurso (usando o valor do campo em vez da geometria).
# -*- coding: utf-8 -*-
###############################################################################
from sys import argv
import osgeo.ogr
import os, os.path
###############################################################################
script, srcSHP = argv
#-- Open source shapefile
shapefile = osgeo.ogr.Open(srcSHP)
layer = shapefile.GetLayer(0)
spatialRef = layer.GetSpatialRef()
#-- Output directory
outDir = os.path.dirname(srcSHP)
outDirName = os.path.basename(outDir)
driver = osgeo.ogr.GetDriverByName("ESRI Shapefile")
outFile = driver.CreateDataSource(os.path.join(outDir,outDirName + "_lines.shp"))
outLayer = outFile.CreateLayer("layer", spatialRef)
#-- Adding fields to the output shapefile
fieldDef = osgeo.ogr.FieldDefn("line_no", osgeo.ogr.OFTString)
fieldDef.SetWidth(12)
outLayer.CreateField(fieldDef)
fieldDef = osgeo.ogr.FieldDefn("From_SEQ", osgeo.ogr.OFTReal)
outLayer.CreateField(fieldDef)
fieldDef = osgeo.ogr.FieldDefn("To_SEQ", osgeo.ogr.OFTReal)
outLayer.CreateField(fieldDef)
#-- Going through each feature, one by one
#-- The last point is the end of the line so I don't want to iterate through that one
for i in range(layer.GetFeatureCount()-1):
lString = osgeo.ogr.Geometry(osgeo.ogr.wkbLineString)
feature1 = layer.GetFeature(i)
feature2 = layer.GetFeature(i+1)
# When it's a new line, the sequential number restart to 1, so we don't want that line
if feature1.GetField("SEQ") < feature2.GetField("SEQ"):
geom1 = feature1.GetGeometryRef()
geom2 = feature2.GetGeometryRef()
geom1x = geom1.GetX()
geom1y = geom1.GetY()
geom2x = geom2.GetX()
geom2y = geom2.GetY()
lString.AddPoint(geom1x, geom1y)
lString.AddPoint(geom2x, geom2y) # Adding the destination point
#-- Adding the information from the source file to the output
feat = osgeo.ogr.Feature(outLayer.GetLayerDefn())
feat.SetGeometry(lString)
feat.SetField("line_no", feature1.GetField("line_no"))
feat.SetField("From_SEQ", feature1.GetField("SEQ"))
feat.SetField("To_SEQ", feature2.GetField("SEQ"))
outLayer.CreateFeature(feat)
print "The End"
Cada par de pontos criará uma única linha. Pode haver uma maneira mais elegante de fazer isso, mas ele criou 3900 linhas em cerca de 15 segundos, para que funcione para mim ...