POST
|
Greetings, I am an amatuer when it comes to python so could someone please help with my simple questions: 1) Is the arcpy module available in ArcGIS 9.3 (I think it is 10 / python 2.6) 2) What is the python code to open a shapefile in ArcGIS 9.3 (not using arcpy module)? Thanks, Josh How about this? shapefile = "c://temp//shapefile.shp" That's a joke, kind of. What exactly are you trying to do ? What do you mean by open? Why can't the user add a shapefile to ArcMap and then open its attribute table or what ever it wants to do there? What's the desired process or end result? What does the user need to do with the shapefile once its been opened?
... View more
11-29-2011
12:08 PM
|
0
|
0
|
673
|
POST
|
A syntax error means that you have written it out, tabbed, spelled something incorrectly.
for fc in fcList:
X = arcpy.SelectLayerByLocation_management("Analysis Roads","HAVE_THEIR_CENTER_IN", fc)
highway = X #I think you want highway to = X which is the selection of analysis roads from the previous #operation?
rows = arcpy.UpdateCursor(highway)
for row in rows:
if row is in X:#I dont think this is correct if statement... should be something like if X==ROW
row.STFID = fc.STFID
rows.updateRow(row)
del row #these del row, del rows should be tabbed outside of the loop, not inside
del rows
... View more
11-29-2011
12:03 PM
|
0
|
0
|
469
|
POST
|
Lists, Arrays, and Tuples! I have a complicated script and a complicated problem. I have simplified it down to the following example: I grab a field from a shapefile using updatecursor and input the field values into a list: list = ["111-11-1","222-22-2","333-33-3"] I need to split these lists up into integers so i can do some math on the first column of each string. (need to add 180 if < 180, and need to subtract 180 if > 180.) for l in list:
splitlist.append(l.split("-"))
print splitlist
for segment in splitlist:
print segment
Result:
[['111', '11', '1'], ['222', '22', '2'], ['333', '33', '3']]
['111', '11', '1']
['222', '22', '2']
['333', '33', '3']
So I am able to isolate the values I need to perform the math on, but how do I call them to a variable and then insert them back in? Here is a copy of my full code for this problem, with the third segment being my failed attempt at 2 d arrays. list = ["111-11-1","222-22-2","333-33-3"]
splitlist=[]
for l in list:
splitlist.append(l.split("-"))
print splitlist
records=0
for split in splitlist:
records=records+1
print split
columns=3
for j in range(records):
for i in range(columns):
current = splitlist[[records],[columns]]
splitarray[[records],[columns]].append(current)
print current
print splitarray[[records],[columns]] Error Message: line 25, in <module>
current = splitlist[[records],[columns]]
TypeError: list indices must be integers, not tuple I found an exceptional resource here but it doesn't help with this problem: http://www.astro.ufl.edu/~warner/prog/python.html Any advice?
... View more
11-29-2011
11:16 AM
|
0
|
4
|
1001
|
POST
|
Hello, New to python and writing my first scripts. I am trying to build a loop to generate individual polygon shapefiles from a feature layer which contains a whole series of polygons. Here's the script, which doesn't seem to work as well as the error message. I'd be grateful if anyone has any suggestions... cheers, Johan Import Phython functions import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/GTZ Data/PEN_IUCN/PEN_IUCN" InShapefile = "C:/IUCN Data/AMPHANURA/AMPHANURA_RBS_Clip.shp" try: rows = arcpy.SearchCursor (InShapefile) row = rows.next() while row: id= row.getValue ("FID") outFC=id + ".shp" sel = str('"FID" = ' " ' "+id+" ' ") arcpy.Select_analysis(InShapefile, OutFC, sel) row = rows.next() except: arcpy.AddMessage(arcpy.GetMessages(2)) print arcpy.GetMessages(2) Parsing error <type 'exceptions.IndentationError'>: expected an indented block (line 2) Note also that you are creating shapefiles that will be numeric.shp... starting a shapefile with a number generally makes ArcMap sad. Try also: id= row.getValue ("FID") outFC="shape_" + str(id) + ".shp" sel = str('"FID" = ' " ' "+id+" ' ")
... View more
09-23-2011
01:23 PM
|
0
|
0
|
273
|
POST
|
From the ESRI arcpy.listfields online help:
import arcpy
from arcpy import env
# Set the current workspace
#
env.workspace = "C:/Data/Municipal.gdb"
# For each field in the Hospitals feature class, print
# the field name, type, and length.
fieldList = arcpy.ListFields("Hospitals")
for field in fieldList:
print "%s is a type of %s with a length of %i" % (field.name, field.type, field.length)
I don't know what you are trying to accomplish with the Asterisks ** inside your fieldlist, but if you delete them I figure it should work.
... View more
09-13-2011
11:10 AM
|
0
|
0
|
1069
|
POST
|
For the first question: Yes I think you could automate it with some scripting. I don't work with geocoding though so its above me. As for the second question: 4.As it hits an address, generate an XYZ feature class (point) and ask me to click to place it You want to click to place the point? Generally I would envision an excel file with X and Y columns ( lat and long for instance) associated with the data already. You could easily generate a Point shapefile with the Address attribute attached to the X, Y. Then the Annotations could be automatically generated from this. But I think you want to create a tool that asks you where to place the annotation for an address before knowing the XY.. IE, the user would input the XY manually for each address? I think that is a reverse way of going about this problem. Try creating an ID column in your excel file "addressID" numbered consecutively: 1,2,3,4,5,6 etc... Then create a point shapefile. While in editor mode, click where you would like each address to go an make sure to number the AddressID field on your shapefile the same as on the address excel file. Afterwords you can join the point file to the excel table using the AddressID as your Key. Label the points based on the Address Field(s) Convert to annotation. Maybe this will help you get started?
... View more
09-02-2011
01:15 PM
|
0
|
0
|
252
|
POST
|
jscheirer, You are a hero of our times. I only wish esri still had a star system so you could be rewarded appropriately. I had attempted to use the zip method previously, though for some reason I determined that it didn't work. I suppose I went about it wrong. Thanks again for the help! You can use zip to unify two lists in the way you're looking for. I would rewrite the script like this: symbols = (u'\u00b0', u"'", u"''")
Update_cursor = arcpy.UpdateCursor(feature_class)
for rows in update cursor:
coord = row.latitude
merged_items = zip(coord.split(u"-"), symbols)
merged_value = "".join(x + y for (x, y) in merged_items)
row.new_field = merged_value
Update_cursor.updateRow(row)
... View more
04-14-2011
08:17 AM
|
0
|
0
|
954
|
POST
|
Hello, First my of my experience with python is in 9.3x and I only just started on arc10 and arcpy last week! This means I am Newb all over again. I have a large dataset that contains latitude and longitude fields. These fields are stored as such: 111-22-22, 23-4-55, 33-3-3 etc, For labeling purposes we would like to convert and store these in their standard display format as such: 103°22'77" I have encountered a number of issues and am now doubting if this is possible. I would like to solve how to join two lists, however. Essentially I have done the following: Update_cursor = arcpy.UpdateCursor(feature_class)
For rows in update cursor:
coord = rows.latitude
courd_list = coord.split("-") #This should print something like ["000", "00", "00"]
Symbol_list = ["°", "'", "''"]
So what I would like to do is join the coord_list with the symbol_list but not just join, splice.... In theory it would give me the result I need. I went about it many different ways and when each one failed, I seem to have erased them and moved on to the next which is a shame because I would have liked to have shared with you my process. One method that I think might be the answer is the following which I gleaned from the old forums but I can't remember who suggested it and I have deleted the link already :
symbol = ["°", "'", "''"]
values = ["100-22-111", "12-232-22", "33-3-33", "993-34-7"]
testSet1 = set()
for v in values:
testSet1.add(v)
testSet2 = set()
for s in symbol:
testSet2.add(s)
print set.union(testSet1, testSet2)
PRINTS set(["''", '12-232-22', "'", '\xb0', '100-22-111', '33-3-33', '993-34-7'])
My Problems: This would seem to work EXCEPT even though I asked python to union set1 then set2, it seems to union in reverse. Specifically, the symbols set, set2, is unioned in reverse, putting the ° at the end and the '' at the beginning... I could fix both of these I guess by formatting my code but what if it is not consistant? The character ° does not seem to be supported by python, can anybody confirm this? In my test result , the ° is converted to \xb0. Is there an ascii or some other module to import so that python will support it? Finally, if I am able to ge the lists to properly union, I will need to output them to a single starting from position 1 in the list and moving to the last , before I can re assign this to the new field in the table. For some reason I can't figure out how to output multiple instances in a List to create 1 back to back string. I appriciate any ideas or comments! Thanks James
... View more
04-13-2011
03:25 PM
|
0
|
2
|
1265
|
POST
|
In your case with regards to currency, Perhaps in USD, or EURO, you will want to set the precision and scale when you add the field. Precision denotes the number of number places on the left of the decimal, and scale denotes the number of number places on the right. It is probably a good idea to leave the precision as its default so that the value input can be variable. eg. 1's, 10's 100's 1000's etc. Likely you want to set the scale to only 2. This will limit the decimals to 2 places with a maximum value of 99 cents and a minimum value of 1 cent. Precision and Scale -- See: http://resources.esri.com/help/9.3/arcgisdesktop/com/gp_toolref/data_management_tools/add_field_data_management_.htm
... View more
11-12-2010
09:17 AM
|
0
|
0
|
1172
|
POST
|
Can you provide more information about your problem please? What tool, what exactly you would like to format? Anything else?
... View more
11-12-2010
06:48 AM
|
0
|
0
|
1172
|
POST
|
Try this. It should clean up most of the minor errors.
import arcgisscripting, sys, os
gp = arcgisscripting.create()
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
#workspace
gp.Workspace = "P:\\Proj"
coordsys = "C:\\Program Files\\ArcGISCoordinate Systems\\Projected Coordinate Systems\\National Grids\\British National Grid.prj"
#List all features in gp.workspace
fcs = gp.ListFeatureClasses("", "")
fc = fcs.Next()
for fc in fcs:
gp.defineprojection(fcS, coordsys)
print fc + " is defined."
The directory of your tool box and coordinate file may differ from mine. check that in case of error.
... View more
09-22-2010
08:27 AM
|
0
|
0
|
738
|
POST
|
If I understand correct: your script-tool is supposed to create and populate a field that you will later buffer with? You problem is that when you are creating the model, you want to select the buffer distance from field option, but it is not showing up. It appears blank because the tool has not run and the field does not yet exist in the dataset. You can create a dummy output or copy your data, then run the model ( which runs the tool) to create the field. The model will stop at the buffer tool because it can't go further without knowing which field you want to buffer from. Hopefully then you can complete the model and it will work fine for future iterations.
... View more
09-16-2010
04:44 AM
|
0
|
0
|
273
|
POST
|
step 1 - create new field = rv_type step 2 - create new field = rg_type step 3 - select by attributes features with type = rv step 4 - calculate rv_type = rv step 5 - select by attributes features with type = rg step 6 - calculate rg_type = rg step 7 - union overlapping features step 8 - Select features by attribute... SQL WHERE: rv_type = "rv" AND rg_type = "rg" step 9 - calculate type field = "rv and rg" step 10 - Delete rv_type, Delete rg_type
... View more
09-15-2010
11:16 AM
|
0
|
0
|
340
|
POST
|
I don't know anything about ArcPy or SDE servers, but perhaps you are having difficulties in the way your are populating your lists and the code structure? I might change your code to the following... but thats for python not ArcPy? Are they very different?:
mxd = arcpy.mapping.MapDocument(fullpath)
DFList = []
while arcpy.mapping.ListDataFrames(mxd):
DFinsert = arcpy.mapping.ListDataFrames(mxd)
DFList.append(DFinsert)
lyrList = []
for df in DFList:
lyrInsert = arcpy.mapping.ListLayers(mxd, "", df)
lyrList.append(lyrInsert)
for lyr in lyrList:
if lyr.supports("DATASOURCE"):
#print lyr.dataSource
if lyr.dataSource == r"Database Connections\GIS_USER2PGIS.sde\SDE.Streets\SDE.LISStreetSegment":
lyr.replaceDataSource(r"Database Connections\Test_Carta_LIS.sde", "SDE_WORKSPACE", "Carta.LIS.StreetSegment")
lyr.name = "Carta.LIS.StreetSegment"
... View more
08-20-2010
10:37 AM
|
0
|
0
|
262
|
POST
|
bposthumus: My output path contained all the correct and required slashes, sorry that I did not post it: tempWS = "E:\\FMP_Reports_Tool\\tempWS.mdb\\" _garret_: I originally had used the Value table method but it kept crashing so I switched to creating the string. I followed a number of your ideas, changing all my paths from \\ to /, and using the os.path.join (tempws, tableName)... which didn't work either! Just in a round about sort of trial and error, frustrating , smash my face on the keyboard, way, I started switching some of my inputs back to the way I had before I tried your methods... Some where in the middle it worked! So I have a bit of a spaghetti factory code, all mixed up using various different methods to create the out puts and it works and I don't want to touch a thing. So dirty it will stay. I am still not sure why it wouldn't work though I suspect it possibly could have been the cursor used to create the list or value table, holding a lock on the variable? I dont know. Any way thanks again everybody for the suggestions. Today I am a Happy Gisser!
... View more
08-19-2010
06:16 AM
|
0
|
0
|
577
|
Title | Kudos | Posted |
---|---|---|
1 | 04-26-2022 08:16 AM | |
1 | 04-25-2022 03:01 PM | |
1 | 12-17-2019 02:23 PM | |
1 | 04-08-2021 10:54 AM | |
1 | 04-08-2021 08:07 AM |
Online Status |
Offline
|
Date Last Visited |
06-12-2023
06:44 PM
|