|
POST
|
To update the shape field you have to create an array and assign it to the shape in the buffer before you write the buffer out. You have created a pnt object and updated that, but have not written it back into the row. If the feature is a polyline or polygon then the object needs to be an array of arrays of points to handle multiparts. row.feat = pnt curA.updateRow(row) Also in your search cursor you are mixing the old and new methods, the for loop automatically interates the cursor. either row = cur.next() while row : .... process ....row = cur.next() or for row in cur : ....process
... View more
09-10-2010
05:57 AM
|
0
|
0
|
696
|
|
POST
|
How hard could it be?? Unfortunately this example script is read-only at 9.3. You will have to upgrade to arcpy to insert dates as I have found to my cost. 1/08/2010 <type 'unicode'> Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\eudora\Attachdir\datetest93.py", line 16, in <module> row.timestamp = row.timestamp + datetime.timedelta(hours=10,minutes=30,seconds=15) TypeError: coercing to Unicode: need string or buffer, datetime.timedelta found # datetest93.py
# convert to 9.3 after a problem
import arcgisscripting,datetime
gp = arcgisscripting.create(9.3)
ws = "d:/workspace/datetest.gdb"
gp.workspace = ws
rows = gp.UpdateCursor("fcdate")
row = rows.next()
while row :
print row.timestamp,type(row.timestamp)
if row.timestamp == None:
row.timestamp = datetime.datetime.now() ## fails
pass
else :
row.timestamp = row.timestamp + datetime.timedelta(hours=10,minutes=30,seconds=15) ## fails
pass
rows.updateRow(row)
row = rows.next()
del row,rows
... View more
08-31-2010
12:42 AM
|
0
|
0
|
1200
|
|
POST
|
You could look at the MakeQueryTable tool. This will effectively join a number of tables very efficiently. I have tried it with extremely large tables that would fail with a Join. Haven't tried a cursor on the resulting layer....
... View more
08-26-2010
01:40 AM
|
0
|
0
|
1665
|
|
POST
|
You don't need all the complications of defining a function as a string. Just create the function in the codeblock and use a simple expression that uses the function. Indents and extra lines will be honoured. Calculator is very bad at handling data errors. If your expressions result in an exception, then you won't get any feedback. Better to use a cursor in a script and trap the errors so you can see the faulty data. It is just as fast, because a cursor implements your expression anyway. codeblock that goes in the box : def getvalue(string):
valuelist=string.split(',')
valueset=set(valuelist)
value=str(valueset)[5:-2]
value.replace('"','') # not sure what you are trying to replace - a double quote?
return value expression in the box: getvalue(!parce_test_spatial_join.FLD_ZONE!) Maybe a python script equivalent:
import arcpy
cur = arcpy.UpdateCursor("parce_test_spatial_join")
try:
for row in cur:
value = row.fld_zone
valuelist=string.split(',')
valueset=set(valuelist)
value=str(valueset)[5:-2]
value.replace('"','')
row.target_field = value # enter your own field here
cur.updateRow(row)
del cur
except :
print "failure on ",value
... View more
08-25-2010
12:55 AM
|
0
|
0
|
1665
|
|
POST
|
ArcPy is minimalist in philosophy. It is not a VBA/ArcObjects replacement (yet). You can only change a few basic properties of map elements that are in the properties dialog for an element, such as position. The suggestion is to keep a range of objects off the page in the MXD template and move the required one on to the map. If you are a wizard at ArcObjects, then anything is possible if you load the comtypes module and call ArcObjects directly. See Mark Cederholm's excellent examples. http://www.pierssen.com/arcgis/upload/misc/python_arcobjects.pdf
... View more
08-17-2010
12:15 AM
|
0
|
0
|
1261
|
|
POST
|
A very interesting thread which is raising a number of topics. 1. Storing a shape object in a dictionary I wondered how to do this too to be able to compare shapes to create a 'delta' list. I eventually used a simple property such as centroid, length or area. Bruce Harold has gone the whole hog and converted the shape to gml, after rounding all vertices, then compressing it using binascii. See his just posted ChangeDetector. http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=351BEE10-1422-2418-8815-82074A3E6B6C( By the way I challenge anyone to find this script themselves using the seach or browsing the circular menus) 2. Sorting is all very well but getting the sort field populated is the hard part. I need to have a sort field for a polyline featureclass that is to be exported to KMZ. Otherwise the tree is randomly exported after edits. So I need a route system first to be able to traverse, and even then I need to get access to the measures. This is very clumsy. My method is to build a new route (which goes into a NEW layer with no attributes -aagh) then create a new temp midpoints layer, then find the measures from the temporary route, then join that back to the original sections, so I finally have a sort field. There may be a few shortcuts at 10 to use featuresets.
... View more
08-07-2010
10:58 PM
|
0
|
0
|
1521
|
|
POST
|
I wanted to gp.Delete("table_rel") but the Delete() function or Exists() function does not even see them. I see a note that suggests that I set OverwriteOutput = True when writing them, but that doesn't clean them out of a file geoadatabase. The only option looks like a GeeWiz Basic style "poke" using ArcObjects, remember those? Can someone give me that syntax?
... View more
07-29-2010
03:19 PM
|
0
|
0
|
2657
|
|
POST
|
Which gave me the idea to try a cursor on a featureset, and that worked too! # latlong.py
# get a point from NZTM and convert to lat/long
#
import arcgisscripting
gp = arcgisscripting.create(9.3)
inFeatSet = gp.GetParameter(0)
row = gp.SearchCursor(inFeatSet,"","c:/arcgis/nzgd2000.prj").next()
lat = row.shape.centroid.Y
long = row.shape.centroid.X
gp.AddMessage(str(lat)+" "+str(long))
del row
... View more
07-28-2010
03:02 AM
|
0
|
0
|
509
|
|
POST
|
Well I suppose an in_memory featureclass is OK latlong.py
# get a point from NZTM and convert to lat/long
#
import arcgisscripting
gp = arcgisscripting.create(9.3)
inFeatSet = gp.GetParameter(0)
gp.OverwriteOutput = True
inFeatSet.Save("in_memory/pointer")
row = gp.SearchCursor("in_memory/pointer","","c:/arcgis/nzgd2000.prj").next()
lat = row.shape.centroid.Y
long = row.shape.centroid.X
gp.AddMessage(str(lat)+" "+str(long))
del row
... View more
07-28-2010
02:54 AM
|
0
|
0
|
509
|
|
POST
|
If you use the tool form setting to collect an interactive point as a featureset you get the coordinates in the current projection. I want to turn that into a WGS84 lat/long to query a web service that requires that format. The only way I can see to do this is by setting an output projection and using a cursor to write a table, then open it up again to see what happened. But the whole point of featuresets is to avoid exactly that sort of inefficiency. There (was), IS an AML function to project a point returned by &Getpoint &Map. Here is the Workstation help snippet [SHOW CONVERT <in_units> <xy> <out_units>] Returns the converted x,y coordinates from units in one specified coordinate space to units in another specified coordinate space. UNITS can be PAGE, MAP, PROJECTEDMAP, or GRAPH. The respective MAPEXTENT, MAPPROJECTION and GRAPHEXTENT must be set first.
... View more
07-28-2010
02:17 AM
|
0
|
2
|
652
|
|
POST
|
Meanwhile, someone could help us here. The ESRI help has example scripts in C# and Vb.NET that could be converted to Python using the comtypes module as demonstrated by Mark Cederholm. http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002w1000000 This could be made into a simple script or module that would do the zooming for us until 10.1 arrives. An excellent little example of extending ArcPy using ArcObjects.
... View more
07-25-2010
02:49 AM
|
0
|
0
|
2841
|
|
POST
|
I ended up using the tool in catalog to set it all up. I just went back and did a find-replace to change the file paths. Much quicker than typing all of it. I have a spatial join in one script that is 20685 characters long, most all of it is field mapping. I wrote papers shorter than that in college. That is how I create field maps too, but you can set the workspace to shorten the paths to fit the fieldmap string into one line.
... View more
07-13-2010
01:44 AM
|
0
|
0
|
2238
|
|
POST
|
An interesting problem that is glossed over in the help. I solved this by creating a table with a date field, populating it and then reading them with a SearchCursor. When Python reads/writes a date field using a cursor it expects a date object using the datetime module. So I found that you have to create and manipulate dates as datetime objects. The datetime module is actually very convenient and cursors work for everything except NULL values.
# datetest
import arcpy,datetime
ws = "c:/home/python/datetest.gdb"
arcpy.env.workspace = ws
rows = arcpy.UpdateCursor("fcdate")
for row in rows :
print row.timestamp,type(row.timestamp)
if row.timestamp == None:
row.timestamp = datetime.datetime.now()
else :
row.timestamp = row.timestamp + datetime.timedelta(hours=10,minutes=30,seconds=15)
rows.updateRow(row)
del row,rows Here is an example featureclass with an existing date field. It had a few dates and a null record. Note that you can read the dates and print them because a date object has a default 'representation'. It is not a string, you can just print the object as a string without casting. Note how you increment a date, using a timedelta object. You also have to trap null dates. I have used a file geodatabase (not a shapefile) because I expected it to handle a full datetime not just a date as in dBase or INFO. More help in the pythonwin help for python for the datetime module.
... View more
07-13-2010
01:35 AM
|
0
|
0
|
1200
|
|
POST
|
Regrettably there are some differences in running scripts in IDLE, Pythonwin, ArcCatalog and ArcMap that cause some things to just not run. I just open up my scripts in Pythonwin and run them from there, since that is where they were debugged. It may be worth changing to 9.3 format if you have later versions. It may be related to the gp processor not releasing locks, especially the AddField tool. There used to be a gp.RefreshCatalog(database) command that might help, this has mysteriously disappeared in documentation in later version because its 'not needed', but you might try that before you open the ODBC cursor. There are bugs in Python modules too, so upgrading to the latest version of ArcGIS forces an upgrade of Python as well.
... View more
06-25-2010
03:16 AM
|
0
|
0
|
5549
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-15-2024 10:32 PM | |
| 1 | 03-12-2026 01:10 AM | |
| 1 | 03-13-2026 08:30 PM | |
| 1 | 03-13-2026 05:17 PM | |
| 1 | 03-12-2026 05:14 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-13-2026
05:04 PM
|