0

I have a polyline shapefile consisting of several line segment features. I want to do a merge operation if the line segment features endpoints are connected, and if the features are disconnected do not merge it. Put it in separate.

So my Logic is -

fetch the co-ordinates of the vertices from the ROADS feature class & then using Polyline method and Insert Cursor create a new feature which will create a new road having all the co-ordinates; but I am getting an error.

Here is my code to fetch the co-ordinates & make new polyline

import arcpy

arcpy.env.workspace = r'C:\Users\Drona_Maps\Desktop\Office Work\Python task\Geodatabase\Road_Geodatabase.gdb\Road_featuredataset\ROAD'
arcpy.env.overwriteOutput = True
fc = r'C:\Users\Drona_Maps\Desktop\Office Work\Python task\Geodatabase\Road_Geodatabase.gdb\Road_featuredataset\ROAD'

with arcpy.da.SearchCursor(fc, ['OID@', 'SHAPE@']) as cursor:
    for row in cursor:
        array1 = row[1].getPart()
        for vertice in range(row[1].pointCount):
            pnt = array1.getObject(0).getObject(vertice)
            listOfCoordinates = [pnt.X,pnt.Y]
            print (listOfCoordinates)


array2 = arcpy.Array([arcpy.Point(listOfCoordinates)])

spatial_reference = arcpy.SpatialReference(4326)
singlepart_polyline = arcpy.Polyline(array2, spatial_reference)

cursor.insertRow([singlepart_polyline])

The Error I am facing is:

[-144.37499999999997, -63.020833332999985]
[-109.54166666699996, -26.812499999999943]
[-109.54166666699996, -26.812499999999943]
[-15.583333332999928, 26.354166667000072]
[-15.583333332999928, 26.354166667000072]
[104.50000000000006, 61.18750000000006]
[112.75000000000011, 64.85416666700007]
[163.16666666700007, 100.14583333300004]
Traceback (most recent call last):
  File "C:/Users/Drona_Maps/Desktop/Office Work/Python task/Initial try/2nd Method.py", line 16, in <module>
    array2 = arcpy.Array([arcpy.Point(listOfCoordinates)])
  File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\arcobjects\mixins.py", line 1082, in _init_
    setattr(self, attr, value)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\arcobjects\_base.py", line 89, in _set
    return setattr(self._arc_object, attr_name, cval(val))
RuntimeError: Point: Input value is not numeric

Process finished with exit code 1

I am doing this in Pycharm using Python version 2.7 and arcpy module and using ArcGIS Desktop 10.4.

5
  • 2
    Have you tried exploring the Dissolve Tool and the unsplit_lines/multi_part parameters? This tool may do it all for you?
    – Hornbydd
    Jan 19, 2021 at 12:11
  • @Hornbydd Yeah dissolve tool does all the work very easily. But I am looking for some other way from the scratch. Like to extract coordinates of the vertices and then convert into a new polyline with the help of Insert Cursor. Jan 20, 2021 at 5:58
  • 1
    Shouldnt the array be created from a list of points? You are trying to create one point from a list of coordinates, then pass this to the array. (Im not sure)
    – BERA
    Jan 20, 2021 at 9:13
  • @GeoSharp can you please comment on this. Jan 21, 2021 at 6:29
  • Im trying to tell you this (untested): array2 = arcpy.Array([arcpy.Point(*c) for c in listOfCoordinates])
    – BERA
    Jan 23, 2021 at 11:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.