POST
|
I'm getting an error that says: "Index Error: list index out of range' Any ideas? I don't know how to do it besides using raw_inputs? and I also don't know how to have an alternative scenario if they type the wrong file name, apologies for my ignorance, I'm very new to Python.
... View more
07-24-2013
11:46 AM
|
0
|
0
|
545
|
POST
|
Hi all, I have a piece of code where I want the user to be able to specify the rasters that will be used in the mosaic tool etc but I'm having a bit of trouble. Could anybody please point me in the right direction regarding what I'm doing wrong and how to get the user to be able to input the rasters below. Thank you. # Prints the length of sys.argv and the first argument
print 'Number of Arguments = ', len(sys.argv)
print 'First Argument sys.argv[0] = ', sys.argv[0]
if len(sys.argv)==1:
Workspace = raw_input("Please enter the folder path of your workspace")
Raster_1 = raw_input("Please enter the path to the first raster")
Raster_2 = raw_input("Please enter the path to the second raster")
Raster_3 = raw_input("Please enter the path to the third raster")
Raster_4 = raw_input("Please enter the path to the fourth raster")
BufferDistance = raw_input("Please enter the required buffer distance")
else:
Workspace = sys.argv[1]
Raster_1 = sys.argv[2]
Raster_2 = sys.argv[3]
Raster_3 = sys.argv[4]
Raster_4 = sys.argv[5]
BufferDistance = sys.argv[6]
#User enters the workspace path
arcpy.env.workspace = out_path = Workspace
print 'Workspace Set'
# Create Raster Dataset
out_name = "R_Dataset"
# Run the Create Raster Dataset Script
arcpy.CreateRasterDataset_management (out_path, out_name, "", "8_BIT_UNSIGNED", "", "1", "", "PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP", "128 128", "LZ77", "")
# Mosaic Rasters into the Raster Dataset
Raster_inputs = (sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
# Set the target to the Raster Dataset that was already created
... View more
07-24-2013
11:15 AM
|
0
|
7
|
1314
|
POST
|
Sounds like either your gdb hasn't been created yet...or the name is wrong. (Or the path to it is wrong.) Not sure of your workflow - do you want to set the workspace to an existing gdb? ...or create the gdb 'dynamically'? EDIT: Post your entire code. Thanks for all your help so far, I want to set the workspace to the gdb that will be created at the start of the script and will have shps imported into it!
... View more
07-21-2013
08:43 AM
|
0
|
0
|
457
|
POST
|
Sure. The out_path parameter for this tool can be a workspace or raster catalog...so to set this to your file gdb, typically with the way you've already set things up in your description (not apparent in your code snippet), do something like this: import os #typically this statement is at the beginning of your script # then if you have a statement similar to this to set the workspace to a dir: arcpy.env.workspace = arcpy.GetParameterAsText(0) # ...you can follow up with this to 'append' the file gdb: out_path = os.path.join(arcpy.env.workspace, out_path) Or...if you set the workspace to an already existing gdb, then the out_path param in the tool would simply be the workspace. Hope that helps, Wayne Thanks Wayne, I tried the below based on your advice: out_path = os.path.join(arcpy.env.workspace, Prog_Assign.gdb)
out_name = "R_Dataset"
# Run the Create Raster Dataset Script
arcpy.CreateRasterDataset_management (out_path, out_name, "", "8_BIT_UNSIGNED", "", "1", "", "PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP", "128 128", "LZ77", "") But I get an error in the script tool stating: out_path = os.path.join(arcpy.env.workspace, Prog_Assign.gdb) NameError: name 'Prog_Assign' is not defined Is my synthax perhaps messed up? Thanks
... View more
07-21-2013
07:34 AM
|
0
|
0
|
457
|
POST
|
Hi all, I've successfully managed to set my workspace as a 'arcpy.GetParameterAsText(0)'. I then created a file GDB and I'm now trying to create a rasterdataset in this file GDB. The rasterdataset wants an 'out_path' to be set. I tried what I have below: # Create Raster Dataset
out_path = "Prog.gdb"
out_name = "R_Dataset"
# Run the Create Raster Dataset Script
arcpy.CreateRasterDataset_management (out_path, out_name, "", "8_BIT_UNSIGNED", "", "1", "", "PYRAMIDS -1 NEAREST DEFAULT 75 NO_SKIP", "128 128", "LZ77", "")
# Mosaic Rasters into a the Raster Dataset
inputs = arcpy.ListRasters("", "TIF")
# Set the target to the Raster Dataset that was already created
target = "R_Dataset"
# Run the Mosaic tool
arcpy.Mosaic_management (inputs, target, "LAST", "FIRST", "", "", "NONE", "0", "NONE")
# Set local variables
in_raster = "R_Dataset"
in_mask_data = "Study_area_extent"
#Extract by Mask
outExtractByMask = arcpy.sa.ExtractByMask (in_raster, in_mask_data) I want to know is there anyway for the original workspace to become part of the out_path when another user runs the code, so it would be something like 'Workspace + Prog.gdb". Thanks
... View more
07-21-2013
06:13 AM
|
0
|
5
|
645
|
POST
|
Hi all, I've got a question. I'm trying to write a python script. As I want to automate as much as possible, I'm just wondering would it be possible to make the workspace a variable so that all that the person has to do is input the workspace location and script will then find the necessary files? Basically, I was wondering just by setting the workspace and the output file names would it be possible to then the script to work? For example, is it possible to tell Python to use the workspace as the default out location or 'out folder path' in the case of creating the file geodatabase? The script is rather long but here is the first bit if anybody has any ideas: # Create file Geodatabase
# Import ArcGIS modules
import arcpy
print arcpy.ProductInfo()
# Check out the ArcGIS Spatial Analyst Extension
arcpy.CheckOutExtension("spatial")
# Need to be able to OverWrite Outputs
arcpy.env.overwriteOutput = True
# Set workspace
arcpy.env.workspace = "C:/Prog_Data"
# Set up variables
out_folder_path = "C:/Prog_Data"
out_name = "Prog.gdb"
# Execute CreateFileGDB
arcpy.CreateFileGDB_management(out_folder_path, out_name)
# Set local variables before importing shapefiles to Geodatabase
inFeatures = ["Points.shp", "Extent.shp", "Rivers.shp", "Population.shp"]
outLocation = "Prog.gdb"
# Execute shapefile to Geodatabase
arcpy.FeatureClassToGeodatabase_conversion(inFeatures, outLocation) I'm relatively new to Python so hopefully the above makes sense! Thanks
... View more
07-20-2013
10:45 AM
|
0
|
1
|
1522
|
POST
|
Thanks very much, that worked a treat, I couldn't figure out where I was going wrong!
... View more
07-12-2013
01:21 AM
|
0
|
0
|
1364
|
POST
|
Hi all, I'm having a bit of trouble with using the Extract by Mask functionality. I have a Python code that creates a file GDB and then I import shapefiles to the GDB. I then create a new raster dataset within the file GDB and then mosaic 4 .tiff into it. The problem occurs when I try to 'Extract by Mask' using the new raster dataset as the input and a polygon as the mask. I get an error stating that: 'AttributeError: 'module' object has no attribute 'ExtractByMask'' I have imported the spatial analyst extension and below is the code that I'm trying to use: # Set local variables in_raster = "C:/Users/D/Prog_Assign.gdb/R_Dataset" in_mask_data = "C:/Users/D/Prog_Assign.gdb/Study_area_extent_shp" #Extract by Mask arcpy.ExtractByMask (in_raster, in_mask_data) # Save the output outExtractByMask.save("C:/Users/D/Prog_Assign.gdb/T_Mask") Any help or advice would be greatly appreciated!
... View more
07-11-2013
01:14 PM
|
0
|
2
|
3987
|
POST
|
Hi all, I have a question that I'm hoping somebody will be able to help me with. I have 4 layers that I want to reclassify to feed into a weighted overlay tool. Three of them I can reclassify no problem to scales of 1-10 but the fourth is open space and it doesn't need to reclassifed to 1-10 as it's all extremely suitable. I was wondering would it be possible to make this all a '10' and do it that way? Apologies if I haven't explained myself very well, thanks in advance. Dónal
... View more
04-06-2013
04:45 PM
|
0
|
0
|
344
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|