POST
|
Hmm. Would this be able to be turned into a tool so that the professor could put in any set of points and then specify the fields to be used? (I definitely need to take another class in Python. The ArcGIS book is not entirely helpful, but it isn't bad either). I'm not sure about extents right now and cell size, but I am looking into the data some more to see what the area covered is and how much interpolation they are doing outside points etc. So I am waiting on that, but this is super helpful. I really really appreciate it. import arcpy, os arcpy.CheckOutExtension("Spatial") ws_out = #GetParameterAsText(0) env.workspace = # GetParameterAsText(1) arcpy.env.overwriteOutput = True #Set Variables points = GetParameterAsText(2) #Is there a way to set this up so the fields could be selected from a dropdown list in the actual toolbox. Then those would be used to create a list..... l = ['pH', 'Pphate', 'K', 'CA', 'Mg'] ras_prefix = 'ab10' for name in l: outidw = arcpy.sa.Idw(points, name) outidw.save('{0}{1}'.format(ras_prefix, name)) # return the sa license arcpy.CheckInExtension("Spatial")
... View more
03-11-2014
09:14 AM
|
0
|
0
|
663
|
POST
|
Sorry. I am having problems getting the parameters when I create the tool. So I added an input and output file for the tool. The input is set up to read workspaces and the output is set up as an output workspace. I get this error. Traceback (most recent call last): File "C:\Users\Anne\Desktop\Python\finalproj\tabletopoint.py", line 29, in <module> fclass = os.path.join(ws_out, tbl.strip(".dbf")) File "C:\Python27\ArcGIS10.1\Lib\ntpath.py", line 96, in join assert len(path) > 0 TypeError: object of type 'geoprocessing value object' has no len()
... View more
03-10-2014
03:41 PM
|
0
|
0
|
663
|
POST
|
I'm having a lot of trouble getting the parameters as text. For some resone the arcpy.env.workspace is not defined everytime I run. import arcpy, os from arcpy import env ws_in = arcpy.GetParameter(0) ws_out = arcpy.GetParameter(1) arcpy.env.workspace = ws_in arcpy.env.overwriteOutput = True tables = arcpy.ListTables() # Sets local variables xc = "long" yc = "lat" spref = arcpy.SpatialReference(4326) XYeventname = "measurements" #Loops through the table and makes points which are saved to the output location for tbl in tables: arcpy.MakeXYEventLayer_management(tbl, xc, yc, XYeventname, spref) fclass = os.path.join(ws_out, tbl.strip(".dbf")) arcpy.CopyFeatures_management(XYeventname, fclass)
... View more
03-10-2014
03:36 PM
|
0
|
0
|
663
|
POST
|
Hi, Sorry it took so long to say thank you. After working through the tables and the code I finally got it to run properly without any errors. It was amazing. Thank you. I put together this code for the IDW so that someone can select several different fields from the same table and run IDW on the data for that set of points. It's really crude but it works I suppose. Again I want to thank you for all your help. If you have any suggestions on the stuff at the bottom let me know. import arcpy from arcpy import env from arcpy.sa import * arcpy.CheckOutExtension("Spatial") env.workspace = "C:/Users/Anne/Desktop/Python/finalproj" #Set Variables points = "Export_Output.shp" zfield1 = "pH" zfield2 = "Pphate" zfield3 = "K" zfield4 = "CA" zfield5 = "Mg" #First Run outidw1 = Idw(points, zfield1) outidw1.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10ph") #Second Run outidw2 = Idw(points, zfield2) outidw2.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10pphate") #Third Run outidw3 = Idw(points, zfield3) outidw3.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10ll") #Fourth Run outidw4 = Idw(points, zfield4) outidw4.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10ca") #Fifth Run outidw5 = Idw(points, zfield5) outidw5.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10mg")
... View more
03-10-2014
02:50 PM
|
0
|
0
|
663
|
POST
|
Hi, Thank you so much for your assistance 🙂 I am really working on this! I am a grad student and it seems all the jobs post school want python which of course the geography department doesn't teach. So the independent study class is the best option. Right now I am working through Learning Python the Hard Way and the ArcGIS python book. I've attached an example of one of the data sheets I am working with. All of the excel/.dbf files look the same. The end result of the project will be a custom tool so that you can loop through the tables and create event layers and then copy them to a folder and have feature classes created. I think what I will do is leave the looping out of the IDW, just because of complications and because it is probably better if the people I am working with specify what data they want to do IDW on. If that makes sense. So the end result I am working toward is a tool where "they-the users" specify the location of their table, the tool then loops through the tables and creates points layers. Then they specify which table they want to use and the field they want to use for IDW. So mainly I am working through looping with the tables and XY events layers. I have fixed the code so that it does work better than it did last time. Here is an example: >>>import arcpy >>> from arcpy import env >>> env.workspace = "F:/work/python" # once I turn this into a tool it will be changed to GetParameters as text() >>> tables = arcpy.ListTables() >>> xc = "long" >>> yc = "lat" >>> out_layer = "F:/work/python" # once I turn this into a tool it will be changed to GetParameters as text() >>>spref = 4326 #I did this as the hardcode for WGS 84 but there may be a better way. I am still looking. >>> for tbl in tables: ... arcpy.MakeXYEventLayer_management(tbl, xc, yc, out_layer, spref) New error which I checked out. Runtime error Traceback (most recent call last): File "<string>", line 2, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 6348, in MakeXYEventLayer raise e ExecuteError: ERROR 000212: Cannot create XY event source Failed to execute (MakeXYEventLayer) AND I think it has to do with the coordinate system reference that I am using. The next step is to do arcpy.CopyFeatures_management(outlayer, savedlayer) I really appreciate the help and I think I am getting closer to figuring this out and learning python everyday.
... View more
02-19-2014
05:22 AM
|
0
|
0
|
663
|
POST
|
Hi all! IF I wanted to run this same script across many tables with x y coordinates how would I go about doing that? I have to automate the process. I have the script set up as this >>> import arcpy >>> from arcpy import env >>> env.workspace = "C:/Users/Anne/Desktop/Python/final" >>> arcpy.ListTables() [u'AB10_.dbf', u'AB11_.dbf', u'AB15_.dbf', u'CFHMS_.dbf', u'CFMHN_.dbf', u'FA_.dbf', u'HSFHome_.dbf', u'HSFVAN_.dbf', u'KF18_.dbf', u'KF1W_.dbf', u'LASA_.dbf', u'MB_HAck_.dbf', u'PCM10_.dbf', u'PMB28_.dbf', u'pmc9_.dbf', u'SHROCK_.dbf', u'simo09_.dbf', u'SIMO94_.dbf', u'SP150_.dbf', u'sp42_.dbf', u'T13East_.dbf', u'T13West_.dbf', u'TB53_.dbf', u'TB63_.dbf', u'WSFBOW_.dbf', u'WSFDALLAS_.dbf'] >>> tblist = arcpy.ListTables() >>> tb = tblist >>> xc = "Lat" >>> yc = "long" >>> out_layer = "pointlayer" >>> saved_layer = r"C:/Users/Anne/Desktop/Python/final" >>> spRef = r"Coordinate Systems\Geographic Coordinate System\World\WGS 1984" >>> for tablelist in tblist: ... arcpy.MakeXYEventLayer_management(tblist, xc, yc, out_layer, spRef) ... print arcpy.GetCount_management(out_layer) ... And that is the error message I get. Should I be doing something else to the table list? I may be in the wrong place, but I really need help 🙂 Runtime error Traceback (most recent call last): File "<string>", line 2, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 6348, in MakeXYEventLayer raise e RuntimeError: Object: Error in executing tool >>>
... View more
02-16-2014
12:36 PM
|
0
|
0
|
165
|
POST
|
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
... View more
02-15-2014
11:04 AM
|
0
|
10
|
1391
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|