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.

I'm currently studying for a Msc in GIS. In my assignment I have been asked to produce a model, export that model as a script file and then run that script as a stand alone in IDLE. So I have created the model in model builder and exported it as a script and have even had a go at cleaning the script. But whenever I try to run the script I get an error. I have attached a jpeg of my model and have also attached the script file. Does anyone know where I'm going wrong? Im using Arcmap 10.1 and python 3.4

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# floodrisk.py
# Created on: 2014-04-21 11:34:26.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: floodrisk <River_thames> <POI> <SOA> <POI_clipped> <SOA_clipped__6_> 
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
arcpy.env.workspace = "C:\Users\Imran\Documents\MASTER GIS\ASSIGNMENT4\Floodrisk.gdb"
arcpy.env.overwriteOutput = True

# Script arguments
River_thames = arcpy.GetParameterAsText(0)
if River_thames == '#' or not River_thames:
    River_thames = "River_thames.shp" # provide a default value if unspecified

POI = arcpy.GetParameterAsText(1)
if POI == '#' or not POI:
    POI = "POI.shp" # provide a default value if unspecified

SOA = arcpy.GetParameterAsText(2)
if SOA == '#' or not SOA:
    SOA = "SOA.shp" # provide a default value if unspecified

POI_clipped = arcpy.GetParameterAsText(3)
if POI_clipped == '#' or not POI_clipped:
    POI_clipped = "POI_clipped.shp" # provide a default value if unspecified

SOA_clipped__6_ = arcpy.GetParameterAsText(4)
if SOA_clipped__6_ == '#' or not SOA_clipped__6_:
    SOA_clipped__6_ = "SOA_clipped.shp" # provide a default value if unspecified

# Local variables:
River_thames_buffer1 = "River_thames.shp"
SOA_clipped = "River_thames_buffer1.shp"
SOA_clipped__2_ = "SOA_clipped.shp"
SOA_clipped__3_ = "SOA_clipped__2_.shp"
SOA_clipped__4_ = "SOA_clipped__3_.shp"
SOA_clipped__5_ = "SOA_clipped__4_.shp"

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

# Process: Clip
arcpy.Clip_analysis(POI, River_thames_buffer1, POI_clipped, "")

# Process: Clip (2)
arcpy.Clip_analysis(SOA, River_thames_buffer1, SOA_clipped, "")

# Process: Add Field
arcpy.AddField_management(SOA_clipped, "AreaB", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
arcpy.CalculateField_management(SOA_clipped__2_, "AreaB", "!shape.area! ", "PYTHON", "")

# Process: Calculate Field (2)
arcpy.CalculateField_management(SOA_clipped__3_, "AreaB", "[AreaB]/1000000", "VB", "")

# Process: Add Field (2)
arcpy.AddField_management(SOA_clipped__4_, "areaP", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field (3)
arcpy.CalculateField_management(SOA_clipped__5_, "areaP", "[AreaB]/ [AreaSQKM]", "VB", "")

enter image description here

share|improve this question
2  
How are you running the standalone script, and what error message are you receiving? –  artwork21 Apr 21 at 14:15
3  
10.1 ships with Python 2.7. Not sure if that might introduce some inconsistencies. –  Craig Apr 21 at 14:20
6  
I'm not an expert, but part of the problem is probably your Python version. ArcGIS 10.1 uses Python 2.7, any script exported from Modelbuilder will be in Python 2.7. There are some significant differences between Python 2 and Python 3. Try running your script using a Python 2.7 interpreter and let us know the error you're getting. –  Dan C Apr 21 at 14:21
    
You're stating a GDB as your workspace and then pointing the variables at shapefiles. I would think that you need the full path of the shapefiles for this to work. I assume from your post you are not running this as a custom tool. –  ian Apr 21 at 14:27
1  
Could you tell a little bit more about this error? Also try to run script in python 2.7 IDE wich was installed with your ArcGiS. –  dmh126 Apr 21 at 15:20
show 6 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.