0

I'm trying to convert multiple lines to points so I typed the code bellow but it keeps on showing me this error:

Parsing error SyntaxError: invalid syntax (line 2)

liste_ligne =["E1_H20A_H35_D21E","E1_I_H16A_H18B","E1_K_D16A_D18B","E1_L_H14_H16B","E1_H2_D70_D40C","G1_D50_D55_H40C","E1_H1_D60_D65_H70","E1_M_D12_H12","E1_Bbis_H45","E1_C_H18A","E1_C_H40","E1_D20A_D21A_D35","E1_E_D18A","E1_E_H50","E1_Bbis_D20E1","E1_G2_D21C_H60_H65","E1_LM_LoisirMoyen","E1_Bbis_D20E","E1_F2_D40_D45","E1_LL_LoisirLong","E1_ABIS_H20E_H21A","E1_F1_H55_H21C","E1_Lbis_D16B_D14"]
# loop the elements on the list
for ligne in liste_ligne: 
# link to shapefile to join
inFeatures = "E:\shapes\"+ligne+".shp"
# link to output
outFeatureClass = " E:\E1TracesPoints\+ligne
# Execute FeatureVerticesToPoints
arcpy.FeatureVerticesToPoints_management(inFeatures, outFeatureClass, "MID")

What have I done wrong?

  • The code that you have presented seems to have an indentation error. Where are you running it from? – PolyGeo May 28 at 12:07
3

You have some issues:

  1. Your indentation after for line is incorrect.
  2. Use os.path.join to combine path and filenames.
  3. Use raw syntax for paths, for example r'E:\somefolder' or backslashes can cause problems.
  4. You cant enclose the variable ligne in quotes. That will make it a string and not the variable holding your list value.

Example:

import arcpy, os

liste_ligne =["E1_H20A_H35_D21E","E1_I_H16A_H18B"]
shapefolder = r'E:\shapes'
outfolder = r'E:\E1TracesPoints'

for ligne in liste_ligne:
    inFeatures = os.path.join(shapefolder,ligne+'.shp')
    outFeatureClass = os.path.join(outfolder,ligne+'.shp')
    arcpy.FeatureVerticesToPoints_management(inFeatures, outFeatureClass, "MID")
  • i tested the code that you proposed and it showed no ERROR but it hasn't gave me the results that i was expecting. the results that i expected is multiple points that replaces the polyline, but whith your code i only get one single point. it's odd because when i use the tool vertices to point manually it gives me the result i expect but with the code i only get one single point. do you have any suggestions for me? – Wiem Belhadj May 28 at 14:24
  • @WiemBelhadj that is what you get with "MID" option, remove it to get all vertices – BERA May 28 at 17:42

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.