Select to view content in your preferred language

Setting Environment Settings

703
4
05-29-2012 10:24 AM
nimitz
by
Regular Contributor
Hi all,
I'm trying to wrap my head around a small script to create a Grid Index. Looking at the examples in the ArcGIS 10 help, setting the environment is messing up my script.
>>> ###GridIndexFeatures 
>>> ###import system modules
>>> import arcpy
>>> from arcpy import env
>>> 
>>> ###Set environment settings
>>> arcpy.env.workspace = "C:\Users\RLong\Documents\WestJackson.mdb"
>>> 
>>> ###Set Local Variables
>>> outFeatureClass = "gridIndexFeatures"
>>> inFeatures = "myGrid"
>>> polygonWidth = "1000 feet"
>>> polygonHeight = "1000 feet"
>>> 
>>> ###Execute GridIndexFeatures
>>> arcpy.GridIndexFeatures_cartography("grid", "WestJackson.mdb", "", "", "",
...      "1000 feet", "1000 feet")


My error code is:
Traceback (most recent call last):
  File "<interactive input>", line 2, in <module>
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\cartography.py", line 787, in GridIndexFeatures
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset WestJackson.mdb does not exist or is not supported
ERROR 000398: Value must be positive
ERROR 000398: Value must be positive
ERROR 000892: The numeric value is outside of the valid range.
ERROR 000892: The numeric value is outside of the valid range.
Failed to execute (GridIndexFeatures).

The input features Dataset WestJackson.mdb does not exist or is not supported. This is curious b/c I have the database which has 2 personal geodatabase features "in it".

Can't I use the database WestJackson.mdb? Or do I have to use one of the file geodatabases that are in WestJackson.mdb?

Any help is appreciated. I am using PythonWin 2.6 and trying to save the scripts, but the script will automatically run after I input the last line,
Tags (2)
0 Kudos
4 Replies
MarcinGasior
Frequent Contributor
I suppose you use Interactive Window in PythonWin. Create a standalone python script instead: File->New->Python script

I noticed two things in your code which can cause errors:
1. Define your workspace in one of those ways:
arcpy.env.workspace = r"C:\Users\RLong\Documents\WestJackson.mdb"
or
arcpy.env.workspace = "C:\\Users\\RLong\\Documents\\WestJackson.mdb"
or
arcpy.env.workspace = "C:/Users/RLong/Documents/WestJackson.mdb"


2. In GridIndexFeatures tool you have to provide feature class name, not entire geodatabase. So it may be like:
arcpy.GridIndexFeatures_cartography("grid", "myFeatureClass", "", "", "", "1000 feet", "1000 feet")


If you want to create gdid index for each of your feature classes you can do it automatically:
import arcpy
arcpy.env.workspace = r"C:\Users\RLong\Documents\WestJackson.mdb"

fcList = arcpy.ListFeatureClasses()
for featureClass in fcList:
    arcpy.GridIndexFeatures_cartography(featureClass+"grid", featureClass, "", "", "", "1000 feet", "1000 feet")
0 Kudos
nimitz
by
Regular Contributor
Here is how I tweaked the code so far:

###Script for creating a Grid Index for mapbook
###
import arcpy, os, sys

from arcpy import env

arcpy.env.workspace = "C:/Users/RLong/Documents/WestJackson.mdb"

###Set Local variables
outFeatureClass = "GridIndex"
inFeatures = "WestJackson1983.gdb"
polygonWidth = "1000 feet"
polygonHeight = "1000 feet"
startingPageNum = "1"

###Execute the Grid Index Features
arcpy.GridIndexFeatures_cartography("GridIndex", "WestJackson1983", "", "", "",
                                    "1000 feet", "1000 feet", "", "", "",
                                    startingPageNum)

                            


NOW my error is:


Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Long. Failed to execute (GridIndexFeatures).

The optional variable WestJackson1983.gdb is the culprit, I think. Or, could it be the variables for the polygonWidth/polygonHeight?

Thanks for any help,
0 Kudos
MarcinGasior
Frequent Contributor
There's no need to set local variables when you don't use them to provide tool parameters.

What do you want to specify as in_features (second parameter). Do you have WestJackson1983 feature class in your WestJackson.mdb geodatabase?
If not, provide the name of a feature class on which grid index should be based.

Starting_page_number parameter requires Long datatype. As you provided a string in variable startingPageNum, it may cause error.
As a default for this parameter is already 1, you don't need to specify it.

Try to run the tool with minimum parameters:
arcpy.GridIndexFeatures_cartography("GridIndex", "WestJackson1983", "", "", "", "1000 feet", "1000 feet")
0 Kudos
nimitz
by
Regular Contributor
Gasior, thanks for the help. I got the following script to work successfully:

###Script for creating a Grid Index for mapbook
###
import arcpy, os, sys

from arcpy import env

arcpy.env.workspace = "C:/Users/RLong/Documents/WestJackson.mdb"

###Set Local variables
outFeatureClass = "GridIndex24"
polygonWidth = "1000 feet"
polygonHeight = "1000 feet"
originCoord = "6735482.561 1943416.772"
numberRows = "24"
numberColumns = "24"

###Execute the Grid Index Features
arcpy.GridIndexFeatures_cartography("GridIndex24", "", "", "", "",
                                    polygonWidth, polygonHeight, originCoord, numberRows, numberColumns,
                                    "")

                            


I ran this in PythonWin (outside of Arcmap session) and it worked flawlessly.

Thanks again,
0 Kudos