POST
|
Well, I'm not sure what is going on with the last couple of attempts - the error suggests that the script couldn't find the file (either the .csv or .xls) so you'll want to make sure you have the path and file name correct. As for the other errors you encountered it I think its because you are including a reference to a Z. In your table you have a column for Z coordinates but the data values are Null. When I try the makexy tool like this it works just fine: tb = r'C:\Documents and Settings\cthompson\My Documents\pythonstuff\testdata\test_data.csv'
xc = 'X'
yc = 'Y'
spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj"
xytab = arcpy.MakeXYEventLayer_management(tb,xc,yc,'csv_tab',spRef) but when i try it while referencing the Z column in that table it bombs out: tb = r'C:\Documents and Settings\cthompson\My Documents\pythonstuff\testdata\test_data.csv'
xc = 'X'
yc = 'Y'
zc = 'Z'
spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj"
xytab = arcpy.MakeXYEventLayer_management(tb,xc,yc,'csv_tab',spRef,zc) So, try your code without the Z - you don't have to account for optional arguments in the tool. See if that helps. And again, make sure everything is where it should be and is named as you reference it in the script.
... View more
10-15-2012
05:18 AM
|
0
|
0
|
1199
|
POST
|
i'll take a look at this and see.. since we are heading into the weekend i probably won't get back to you until Monday.
... View more
10-12-2012
11:20 AM
|
0
|
0
|
1199
|
POST
|
Can you attach a portion of your .csv file so we can see what it looks like?
... View more
10-12-2012
07:04 AM
|
0
|
0
|
1199
|
POST
|
both of these examples make use of VBScript as the default parser Since ESRI seems fully on the Python bandwagon, I'm wondering if longer term we will see this go away or loss of support for VBscript just as we have seen VBA support vanish. The consequence of this of course would be that Python suddenly becomes more more integral to ArcGIS than it is currently. Since the OP raised the spectre of his concern being tied to security issues, I'm curious if there are any documented security breaches that have been linked to ArcGIS install of Python. I browsed a few of the Bulletins randomly to see what issues there are with python but didn't find any references to python. A search of the website discovered a bulletin dated to 2008 identifed an issue, but nothing more recent. If there are indeed cyber security issues related to a python install, what specifically are those and what rational measures (removing it completely seems a bit extreme) are recommended for mitigating those issues? Has ESRI paid any attention to such concerns?
... View more
10-11-2012
12:58 PM
|
0
|
0
|
580
|
POST
|
Failed to execute. Parameters are not valid. ERROR 000728: Field x-coord does not exist within table ERROR 000728: Field y-coord does not exist within table ERROR 000728: Field z-coord does not exist within table Take a look at your csv - did you rename those fields as i'd suggested to do away with the hyphens? The errors indicate that there isn't a field of the name (i.e. x-coord) in your csv file. Make sure that the names you give on the right side of the statements below exactly match the names of the fields in your CSV. It could also be that the hyphen is causing a problem as those are not usually valid characters in a field name. x_coords = "x-coord"
y_coords = "y-coord"
z_coords = "z-coord"
... View more
10-11-2012
12:32 PM
|
0
|
0
|
1199
|
POST
|
Thanks for the reply. I'm using MakeQuery Layer_managemen Crap.. my bad.. I shouldn't respond to these things near the end of the day when my brain is jelly.
... View more
10-11-2012
08:39 AM
|
0
|
0
|
1898
|
POST
|
in this line 'Database Connections\my_database.sde' you're referencing an SDE connection or a workspace.. not a table.. the arguments for the MakeQueryTable command indicate that first argument should be a reference to a table so maybe something like: 'Database Connections\my_database.sde\table_name' would work instead? MakeQueryTable_management (in_table, out_table, in_key_field_option, {in_key_field}, {in_field}, {where_clause})
... View more
10-10-2012
12:44 PM
|
0
|
0
|
1898
|
POST
|
first thing you need to do is call the env module -you do that by first importing arcpy then importing the env module from arcpy like this: import arcpy from arcpy import env then you set the workspace by using the env.workspace function like this; env.workspace = 'your file path' In your case it would look like the following: import arcpy
from arcpy import env
env.workspace = r'C:TEMP\BS_Test.gdb' you will have to refer to the .csv file by using its full pathname, typically its convenient to set a variable equal to this to avoid having to type out long pathnames frequently. That would look like: my_csv = r'C:\TEMP\WritingGeometries\sc12points.csv' As far as your other two questions: 2a) yes, sc12points.csv is your in_table though given above you could change in_table to my_csv. Both of these approaches end up with the same result: my_csv = r'C:\TEMP\WritingGeometries\sc12points.csv'
arcpy.MakeXYEventLayer_management(my_csv, x_coords, y_coords, out_Layer, spRef, z_coords)
is the same as:
arcpy.MakeXYEventLayer_management(r'C:\TEMP\WritingGeometries\sc12points.csv'
, x_coords, y_coords, out_Layer, spRef, z_coords) where the first method wins is when you are making many references to that table - its basically short cut notation to refer to it. 2b) in the example the names x_coords and y_coords are references to the names of the fields in the table which are "Point_X" and "Point_Y". In your case it looks like your fields are named x-coord and y-coord so that bit of code would look like this instead: x_coords = "x-coord"
y_coords = "y-coord" That said, the hyphens in your field names (x-coords) MAY give you fits as its generally recommended not to unclude special characters or spaces in a field name. So you may want to stick with the example and use an underscore instead.
... View more
10-10-2012
12:02 PM
|
0
|
0
|
1199
|
POST
|
Here is one approach that works on a single workspace. It creates a list of features in a user provided workspace, creates a dictionary from the list where the dictionary KEY is the list index, prints the key and values to the IDE screen (IDLE, PythonWin, etc.) so the user can see those, then prompts the user to input a list of the dictionary keys to perform the selection on. The list that is created from from this (clip_list) can then be the input to your clipping routine. Adding functionality to this to work on multiple workspaces would be simple enough - the user could input a comma delimited list of workspaces, and then the tool could iterate through those. In theory anyway :cool: To run, save the script to a file with a .py extension, then navigate to that and open it with the IDE of your choice, and run. It works for me but possibly YMMV. import arcpy,sys
from arcpy import env
ws = raw_input('Copy/paste the pathname of the folder containing feature classes to select from): ')
env.workspace = ws
feats = arcpy.ListFeatureClasses()
# function prints text to the IDE window
def prn_screen(txt):
sys.stdout.write(txt+'\n')
sys.stdout.flush()
feat_dict = {} #creates an empty dictionary
# populates above dictionary from the list of features, where the key is
# essentially the index of the featureclass in the list
for x in range(len(feats)):
feat_dict = feats
#simply prints the dictonary keys and associated values so the user can see these
for key,value in feat_dict.iteritems():
display = str(key) + " : " + str(value)
prn_screen(display)
# entering a number is easier than typing featureclass names, avoiding seplling errors :)
clip_keys = raw_input('Enter the number for each featureclass you want to clip, commas separating each entry: ')
idx_list = []
#converts the raw_input string to a list of numbers that match the dictionary keys
idx_list += map(int,clip_keys.split(','))
clip_list = []
for idx in idx_list:
clip_list.append(feat_dict[idx])
... View more
10-10-2012
07:47 AM
|
0
|
0
|
1108
|
POST
|
absolutely.. in fact, you should be able to use the same methods with your point file as with the polygon.
... View more
10-10-2012
03:38 AM
|
0
|
0
|
780
|
POST
|
"Ignorant" is sort of a harsh term... even if its an honest ignorance.. you're obviously moving in the right direction.. the problem with learning programming languages is the same as with any other language.. the vocabulary. You might know how to put together the sentence, if you just knew the words 🙂 Don't be shy about asking - it can save you hours or days sometimes so ask away!
... View more
10-09-2012
01:38 PM
|
0
|
0
|
363
|
POST
|
You can use the GetCount_management tool that returns the number of rows in a table, featureclass, or layer. Use that value in an if, else statement to execute different processes based on there either being a count > 0 or count = 0.
... View more
10-09-2012
01:17 PM
|
0
|
0
|
363
|
POST
|
Dan's suggestions about looking at Search Cursors is valuable, also look at the tools for working with tables and table views. If you need to work through a table, fitting values from fields into formulae and then updating other fields in the same or another table look up the help topics on Update and Insert Cursors as well. Those are probably the key things for what you want to do. Reading and writing geometries are a bit different though still operate well using cursors.
... View more
10-09-2012
12:53 PM
|
0
|
0
|
780
|
POST
|
I'm not sure what you mean by 'read' the shapefile.. are you trying to get at the values in the attribute table? gather the geometry, or do something else?
... View more
10-09-2012
08:41 AM
|
0
|
0
|
780
|
Title | Kudos | Posted |
---|---|---|
1 | 07-25-2012 04:41 AM | |
1 | 03-15-2016 09:15 AM | |
1 | 07-30-2013 11:02 AM | |
1 | 09-28-2015 04:16 AM | |
6 | 09-23-2015 04:48 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|