Select to view content in your preferred language

Python Final Project Assistance XY points from table to final IDW raster

2258
10
02-15-2014 11:04 AM
annesanta_maria2
Emerging Contributor
Hi,
I am taking an independent study python class and the professor is just learning python as well. For my final project I want to do the following:

1. add xy data from several tables-Make XY events layer-using WGS84 spatial reference
2. convert that data to a permanent shapefile- copy features
3. take those points and list fields-arcpy.listfields
4. run IDW across several fields for all the points

I can run that process for one set of data from table to IDW raster but I cannot seem to figure out how to turn that into a code that automates twenty tables and many fields in those points layers.

Any suggestions on how to start? Essentially I need a script that I can turn into a toolbox for a final project in April. I thought I had this under control until I realized how hard it is for me to grasp python. I am just learning and I DON'T WANT SOMEONE JUST TO TELL ME HOW to do it. I want to really understand.

import arcpy
from arcpy import env

# set workspace
arcpy.env. workspace ="whatever the workspace would be C:/user/etc"
tablelist = arcpy.Listtables()
.....# this is where I get stuck how do take this table list and turn into into several events layers. Do I need to list all the fields in the table. 

for tables table list:
     arcpy.MakeXYEvents layers(enter parameters)


arcpy.CopyFeatures

I guess what I am looking for is the best next step to take. I appreciate any assistance.
Anne
Tags (2)
0 Kudos
10 Replies
XanderBakker
Esri Esteemed Contributor
Hi Anne,

That is a relatively simple thing to do with a ArcGIS toolbox tool. I advise you to read the following Help page:
http://resources.arcgis.com/en/help/main/10.2/index.html#//00150000000n000000

If you scroll to the very end of this page you will see a header "obtained from". This is what it is all about including the "Filter" option and multi value setting.

Create a new toolbox, add a script (name it appropriately), select the location of the script, and in the next screen you have to define your parameters. In this screen select feature layer as a parameter type (let's call it "point features"). In the Filter option (lowe part of dialog) set it to Feature Class and select only point features. The user will not be able to select a layer that isn't a point featureclass.

The next parameter would be of the type field (let's call this one "IDW fields"). Now in the lower part of the dialog set the following things:

  • MultiValue: Yes (this means more than 1 field van be chosen)

  • Filter: Field (in the dialoog with field type select only the appropriate field types for IDW: like Float and Double), so only these field will be shown in your script dialog

  • Obtained from: select your "point features". This means that the field will be obtained from the point feature layer the user selected

With a few simple clicks you have set up (part of) the scrip dialog. Now when you read the fields inside the script (arcpy.GetParameter() or arcpy.GetParameterAsText()), I advise you to read is as text. It will be a single string. Split is using the ';' as split character to obtain a list of the field names.

flds = arcpy.GetParameterAsText(1)
lst_flds = flds.split(';')


Now you have a list of the chosen field names that can be used in the IDW loop.

See attached images to clarify.

[ATTACH=CONFIG]32136[/ATTACH]
Defining the field parameter

[ATTACH=CONFIG]32137[/ATTACH]
The result in the script dialog

Kind Regards,

Xander
0 Kudos