1

I have a table with ~12000 rows like:

NOMBRE     LAT     LONG      FECHA                INT
AL011900    15  -42.1   1900-08-27T00:00:00Z    18.0054
AL011900    15.2    -43.4   1900-08-27T06:00:00Z    18.0054
AL011900    15.3    -44.7   1900-08-27T12:00:00Z    18.0054
AL011900    15.4    -45.6   1900-08-27T18:00:00Z    18.0054
AL021900    19  -59.3   1900-09-13T12:00:00Z    33.4386
AL021900    19.5    -60 1900-09-13T18:00:00Z    36.0108
AL021900    20  -60.6   1900-09-14T00:00:00Z    38.583
AL041905    36.3    -48.6   1905-10-10T18:00:00Z    46.2996
AL041905    37.9    -47.9   1905-10-11T00:00:00Z    43.7274
AL041905    39.6    -47.1   1905-10-11T06:00:00Z    41.1552
AL041905    41  -46 1905-10-11T12:00:00Z    41.1552

Fecha is "date time" and the table is already sorted using it.

I will like to create lines between sequential points per each NOMBRE, keeping in the attribute of each line the INT values of the first point of each line. Please note that there are several INT per NOMBRE and that's the reason why I need to create lines for each consecutive pair of points.

That will be: the line from point 1 to point 2 will have the INT attribute of point 1. The line from point 2 to point 3 will have the INT value of point 2. And so on for each of the NOMBRE.

  • Convert points to line using nombre field as line id. Split line at vertices. Transfer from node attribute using gis.stackexchange.com/questions/125090/… – FelixIP Aug 22 '18 at 18:54
  • Please do not comment on your own question. These comments should be edits, to the question itself. – Vince Aug 22 '18 at 22:51
  • 1
    Further to @Vince's comment, please edit your post with the information you've added in the comments. In addition, if you're using ArcPy, then it would be better to show arcpy code rather than R code. – Fezter Aug 23 '18 at 0:00
  • please ask questions for either QGIS or ArcGIS (or another software). If needed you can ask several questions for the different softwares. – radouxju Aug 23 '18 at 8:36
3

With arcpy you can do:

import arcpy
from collections import defaultdict
arcpy.env.workspace = r'C:\Default.gdb' #Change. Input table need to be here
table = r'nombre' #Change
fields = ['NOMBRE','LAT','LONG_','FECHA','INT_'] #Change to match your field names
out_fc = r'nombrelines' #Output fc, will be created in script
epsg = 4326 #Change to match the epsg of your coordinate system

#Create polyline fc and add fields
arcpy.CreateFeatureclass_management(out_path=arcpy.env.workspace, out_name=out_fc, geometry_type='POLYLINE', spatial_reference=arcpy.SpatialReference(epsg))
for field in [('NOMBRE','TEXT'),('INT','DOUBLE')]:
    arcpy.AddField_management(in_table=out_fc, field_name=field[0], field_type=field[1])

#List all rows in table
all_rows = [i for i in arcpy.da.SearchCursor(table,fields)]
all_rows = sorted(all_rows,key=lambda x: (x[0],x[3])) #Sort by nombre and fecha

#Insert rows
icur = arcpy.da.InsertCursor(out_fc,['NOMBRE','INT','SHAPE@'])
d = defaultdict(list)
for row in all_rows: #Group togehter rows by nombre using defaultdict
    d[row[0]].append(row[1:])
for k,v in d.iteritems(): #d.items() in py3/ArcGIS Pro
    for pair in zip(v,v[1:]):
        array = arcpy.Array([arcpy.Point(pair[0][0],pair[0][1]),arcpy.Point(pair[1][0],pair[1][1])])
        polyline = arcpy.Polyline(array,arcpy.SpatialReference(epsg))
        icur.insertRow((k,pair[0][-1],polyline))
del icur

enter image description here

  • I think there is an issue somewhere when putting together the coordinates because I get the wrong location of the lines. I think LONG is being plotted as LAT and viceversa. Can you please double check that? Line with vertices that should be LONG -33, LAT 7 is displayed as LONG 7 , LAT -33 – Guillermo.D Aug 23 '18 at 13:23
  • Just swap the indexes off array line to: array = arcpy.Array([arcpy.Point(pair[0][1],pair[0][0]),arcpy.Point(pair[1][1],pair[1][0])]) – BERA Aug 23 '18 at 13:27

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.