Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Can anyone help? I created a model-has buffer,clip, selectbylocation.... I exported the model as a script but when i try to run it i get this error:

Executing: IGISprogrammingscript C:\Temp\VirtualCampus\IGIS\Thames.shp "C:\Temp\VirtualCampus\IGIS\Super Output Areas.shp" "C:\Temp\VirtualCampus\IGIS\Points of interest.shp" C:\Temp\VirtualCampus\IGIS\Thames_Buffer.shp C:\Temp\VirtualCampus\IGIS\poi_test.shp C:\Temp\VirtualCampus\IGIS\superoutputareas_clip_test.shp
Start Time: Sun Jul 07 20:35:37 2013
Running script IGISprogrammingscript...

Traceback (most recent call last):
  File "C:\Temp\VirtualCampus\IGIS\IGISprogrammingscript.py", line 28, in <module>
    arcpy.SelectLayerByLocation_management(Points_of_interest, "COMPLETELY_WITHIN", Thames_Buffer_shp, "", "NEW_SELECTION")
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\management.py", line 6585, in SelectLayerByLocation
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).


Failed to execute (IGISprogrammingscript).

Also i have another question related to this, in my model i have several tools like clip,buffer,selectbylocation....when i run my script with the model parameters it only runs a section of the script, do you know why?

Thanks for your help

    # -*- coding: utf-8 -*-
    # ---------------------------------------------------------------------------
    # IGISprogrammingscript.py
    # Created on: 2013-07-07 16:55:49.00000
    #   (generated by ArcGIS/ModelBuilder)
    # Description: 
    # ---------------------------------------------------------------------------

    # Import arcpy module
    import arcpy


    # Local variables:
    Thames_shp = "C:\\Temp\\VirtualCampus\\IGIS\\Thames.shp"
    Super_Output_Areas_shp = "C:\\Temp\\VirtualCampus\\IGIS\\Super Output Areas.shp"
    Points_of_interest = "Points of interest"
    Thames_Buffer_shp = "C:\\Temp\\VirtualCampus\\IGIS\\Thames_Buffer.shp"
    superoutputareas_clip_shp = "C:\\Temp\\VirtualCampus\\IGIS\\superoutputareas_clip.shp"
    Points_of_interest__2_ = "Points of interest"
    poi_shp = "C:\\Temp\\VirtualCampus\\IGIS\\POI.shp"
    poi_cat = "C:\\Temp\\VirtualCampus\\IGIS\\poi_cat"
    pop = "C:\\Temp\\VirtualCampus\\IGIS\\pop"

    # Process: Buffer
    arcpy.Buffer_analysis(Thames_shp, Thames_Buffer_shp, "300 Meters", "FULL", "ROUND", "NONE", "")

    # Process: Select Layer By Location
    arcpy.SelectLayerByLocation_management(Points_of_interest, "COMPLETELY_WITHIN", Thames_Buffer_shp, "", "NEW_SELECTION")

    # Process: Copy Features
    arcpy.CopyFeatures_management(Points_of_interest__2_, poi_shp, "", "0", "0", "0")

    # Process: Summary Statistics
    arcpy.Statistics_analysis(poi_shp, poi_cat, "CATEGORY COUNT", "CATEGORY")

    # Process: Clip
    arcpy.Clip_analysis(Super_Output_Areas_shp, Thames_Buffer_shp, superoutputareas_clip_shp, "")

    # Process: Summary Statistics (2)
    arcpy.Statistics_analysis(superoutputareas_clip_shp, pop, "LSOA_POP SUM", "")

Hi, i've added make feature layer and make table view and i'm still getting an error but it's a different one this time...but still refers to the make feature layer. This is the code:

~# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# IGISprogrammingscript_1.py
# Created on: 2013-07-09 21:39:46.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: IGISprogrammingscript_1 <Thames_shp> <Points_of_interest> <Super_Output_Areas_shp> <Thames_Buffer_shp> <superoutputareas_clip_shp> 
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Script arguments
Thames_shp = arcpy.GetParameterAsText(0)
if Thames_shp == '#' or not Thames_shp:
    Thames_shp = "C:\\Temp\\VirtualCampus\\IGIS\\Thames.shp" # provide a default value if unspecified

Points_of_interest = arcpy.GetParameterAsText(1)
if Points_of_interest == '#' or not Points_of_interest:
    Points_of_interest = "Points of interest" # provide a default value if unspecified

Super_Output_Areas_shp = arcpy.GetParameterAsText(2)
if Super_Output_Areas_shp == '#' or not Super_Output_Areas_shp:
    Super_Output_Areas_shp = "C:\\Temp\\VirtualCampus\\IGIS\\Super Output Areas.shp" # provide a default value if unspecified

Thames_Buffer_shp = arcpy.GetParameterAsText(3)
if Thames_Buffer_shp == '#' or not Thames_Buffer_shp:
    Thames_Buffer_shp = "C:\\Temp\\VirtualCampus\\IGIS\\Thames_Buffer.shp" # provide a default value if unspecified

superoutputareas_clip_shp = arcpy.GetParameterAsText(4)
if superoutputareas_clip_shp == '#' or not superoutputareas_clip_shp:
    superoutputareas_clip_shp = "C:\\Temp\\VirtualCampus\\IGIS\\superoutputareas_clip.shp" # provide a default value if unspecified

# Local variables:
Pointsofinterest_Layer__2_ = Thames_Buffer_shp
poi_cat = Pointsofinterest_Layer__2_
poi_cat_View = poi_cat
Pointsofinterest_Layer = Points_of_interest
pop = superoutputareas_clip_shp
pop_View = pop

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Points_of_interest, Pointsofinterest_Layer, "", "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;CATEGORY CATEGORY VISIBLE NONE;NAME NAME VISIBLE NONE")

# Process: Buffer
arcpy.Buffer_analysis(Thames_shp, Thames_Buffer_shp, "300 Meters", "FULL", "ROUND", "NONE", "")

# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(Pointsofinterest_Layer, "COMPLETELY_WITHIN", Thames_Buffer_shp, "", "NEW_SELECTION")

# Process: Summary Statistics
arcpy.Statistics_analysis(Pointsofinterest_Layer__2_, poi_cat, "CATEGORY COUNT", "CATEGORY")

# Process: Make Table View
arcpy.MakeTableView_management(poi_cat, poi_cat_View, "", "", "CATEGORY CATEGORY VISIBLE NONE;FREQUENCY FREQUENCY VISIBLE NONE;COUNT_CATEGORY COUNT_CATEGORY VISIBLE NONE")

# Process: Clip
arcpy.Clip_analysis(Super_Output_Areas_shp, Thames_Buffer_shp, superoutputareas_clip_shp, "")

# Process: Summary Statistics (2)
arcpy.Statistics_analysis(superoutputareas_clip_shp, pop, "LSOA_POP SUM", "")

# Process: Make Table View (2)
arcpy.MakeTableView_management(pop, pop_View, "", "", "Rowid Rowid VISIBLE NONE;FID FID VISIBLE NONE;FREQUENCY FREQUENCY VISIBLE NONE;SUM_LSOA_POP SUM_LSOA_POP VISIBLE NONE")~

This is the error i get:

  Traceback (most recent call last):
  File "C:\Temp\VirtualCampus\IGIS\IGISprogrammingscript_1.py", line 43, in <module>
    arcpy.MakeFeatureLayer_management(Points_of_interest, Pointsofinterest_Layer, "", "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;CATEGORY CATEGORY VISIBLE NONE;NAME NAME VISIBLE NONE")
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5774, in MakeFeatureLayer
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000733: Output Layer: Same as input C:\Temp\VirtualCampus\IGIS\Super Output Areas.shp
Failed to execute (MakeFeatureLayer).
share|improve this question
    
Welcome to GIS.SE! –  Paul Jul 7 '13 at 18:39
add comment

2 Answers 2

Select layer by location (or attributes for that matter) must be run on a layer. It's possible that when you exported it, some files were moved around that resulted in this error message. But without seeing the rest of the code, it's difficult to say. Could you edit your first post to include everything up to line 28?

You might find this helpful.

Edit:

For starters, both of your "Points_of_interest" variables are referring to the same layer. Unless they already exist on disk, they are not being created when you run the script. If they do already exist, note my above where select layer by location has to be run on a layer, not a shapefile. It appears that you are trying to run it on a shapefile, which would result in an invalid data error.

share|improve this answer
    
Many thanks, i've added my code to the post and also another question. –  user19831 Jul 7 '13 at 19:42
    
I meant the actual script code that details all of the steps. For readability, please use backticks (under the tilde ~ key) around your code. –  Paul Jul 7 '13 at 19:54
    
think i got it right this time, did you mean the python script? –  user19831 Jul 7 '13 at 20:31
    
Yes, I've edited my post accordingly. –  Paul Jul 7 '13 at 23:01
add comment

Be sure to take note of the following from the Exporting a model to a Python script online help:

There are instances when your exported model will not work...

  • If your model used layers or table views that weren't created within the original model, those layers or table views will have to be created in the script using tools such as Make Feature Layer and Make Table View.

The advice from @Paul is steering you in the right direction.

share|improve this answer
    
Hi, i've added make feature layer and make table view and i'm still getting an error but it's a different one this time...but still refers to the make feature layer. I've added the new error code to the above message. Many thanks –  user19831 Jul 9 '13 at 21:06
    
If it is a different error then I think you should Accept answer from @Paul and then post the new code/error as a new question. Expanding your question to include new code and errors does not fit well with the Q&A format of GIS SE. –  PolyGeo Jul 10 '13 at 6:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.