-1

I am new to ArcGIS. I am trying to do a lot downscale the data using IDW tool in ArcGIS. I have one shapefile. In this shapefile, I have multiple columns. Each column corresponds to each year. I want to iterate through each year using IDW tool. I am using ArcPy for this. Unfortunately, I am getting an error at the end.

My code is following:

import arcpy
shp = "T:\\Samarth\\project\\prjairtemp.shp"
shp_field_name = [f.aliasName for f in arcpy.ListFields(shp, "Year_20*", "Double")]
prjairtemp = "T:\\Samarth\\project\\prjairtemp.shp"
test = "T:\\Samarth\\Studyarea\\test.shp"

for field in shp_field_name:
    try:
        if not field.required:
        IDWname = "T:\\Samarth\\IDW\\" + str(field.name) + ".tif"
        arcpy.Idw_3d(prjairtemp, field, IDWname, "10000", "2", "VARIABLE 12", "")
        clipIDW = "T:\\Samarth\\Clip_IDW\\" + str(field.name) + ".tif"
        arcpy.Clip_management(IDWname, "-1008952.43359909 3275056.34237466 553101.562858121 4949773.07466453", clipIDW, test, "", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
        final = "T:\\Samarth\\rastertopoint\\" + "airtemp" + str(field.name) + ".shp"
        arcpy.RasterToPoint_conversion(clipIDW, final, "Value")
        except:
            print arcpy.GetMessages()

I get the following error message.

Parsing error SyntaxError: invalid syntax (line 10)

I tried running second code to see if changing the code might help. Same error message at the same line. Here is the second code.

import arcpy

try:
    shp = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\Seaicefrac\\projection\\prjseaicefrac.shp"
    shp_field_name = [f.aliasName for f in arcpy.ListFields(shp, "Year_20*", "Double")]

    prjairtemp = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\Seaicefrac\\projection\\prjseaicefrac.shp"

    test = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\studyarea_downscaled\Dump\\test.shp"

    for field in shp_field_name:
        IDWname = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\\Seaicefrac\\tiff\\IDW" + str(field.name) + ".tif"
        arcpy.Idw_3d(prjairtemp, field, IDWname, "10000", "2", "VARIABLE 12", "")
        clipIDW = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\\Seaicefrac\\tiff\\clip" + str(field.name) + ".tif"
        arcpy.Clip_management(IDWname, "-1008952.43359909 3275056.34237466 553101.562858121 4949773.07466453", clipIDW, test, "", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
        final = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\\Seaicefrac\\master\\seaicefrac" + str(field.name) + ".shp"
        arcpy.RasterToPoint_conversion(clipIDW, final, "Value")

except:
        print "Script failed to complete"
        print arcpy.GetMessages(2)

Here is the error message.

Parsing error SyntaxError: invalid syntax (line 13)
  • Your title seems to assert ArcPy is at fault, not your formatting. – Vince Aug 13 '17 at 15:28
  • 2
    If you remove your try/except while testing and from the code you present here there is likely to be a more informative error message seen. – PolyGeo Aug 13 '17 at 20:01
  • Hey PolyGeo, I tried that but than my result folder stays empty. Nothing happens. – Cricketer Aug 14 '17 at 12:49
  • Thank you Vince for your comment. I tried running the code with same format as Gob Tron but I get the same error. – Cricketer Aug 14 '17 at 13:00
  • 1
    @Samarth you have indentation problems in your both first and second examples. Use 4 spaces as indent for each level, put try and except on the same level and so on. – Serge Norin Aug 16 '17 at 13:09
1

By having a quick look at your code, the first thing I see is an indentation problem.

import arcpy

try:
  shp = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\Seaicefrac\\projection\\prjseaicefrac.shp"
  shp_field_name = [f.aliasName for f in arcpy.ListFields(shp, "Year_20*", "Double")]

  prjairtemp = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\Seaicefrac\\projection\\prjseaicefrac.shp"

  test = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\studyarea_downscaled\Dump\\test.shp"

  for field in shp_field_name:
      IDWname = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\\Seaicefrac\\tiff\\IDW" + str(field.name) + ".tif"
      arcpy.Idw_3d(prjairtemp, field, IDWname, "10000", "2", "VARIABLE 12", "")
      clipIDW = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\\Seaicefrac\\tiff\\clip" + str(field.name) + ".tif"
      arcpy.Clip_management(IDWname, "-1008952.43359909 3275056.34237466 553101.562858121 4949773.07466453", clipIDW, test, "", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
      final = "C:\\Users\\Lab-User\\Documents\\fourth_chapter_PC\\Summary_10km\\Seaicefrac\\master\\seaicefrac" + str(field.name) + ".shp"
      arcpy.RasterToPoint_conversion(clipIDW, final, "Value")

except:
  print "Script failed to complete"
  print arcpy.GetMessages(2)
  • I tried with your version too. Still the same error message. – Cricketer Aug 14 '17 at 12:51

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.