|
POST
|
You must have a strange installation. The os module works for me without any hacking. My pythonpath is set to C:\arcgis\bin (which I am not all that comfortable with) but I don't seem to need to set it to c:\python25\lib as well to work as a script. The os module behaves at 10 for me as well.
... View more
09-27-2010
03:15 AM
|
0
|
0
|
1577
|
|
POST
|
Load the ElementTree module. This is very helpful to parse XML files of metadata. Here is an example where I read in an old metadata file, fiddle with the dates and rewrite it. # LoadMetadata.py
# with altered dates for current month
# using element tree
# create original Metadata with same name as layer
# run this to alter to name_et.xml
# reload into filegeodatabase
# Note there is no tool to unload metadata
# 15 March 2010
import arcgisscripting,sys,os
import elementtree.ElementTree as ET
import sys,os,datetime
print
print
def alter(xmlfile,edDate,publishDate,createDate) :
"""
read xml file for featureclass or table
change dates to today,loading date and extract date
empty processing logs
write out file with _et suffix
return file name
"""
print xmlfile
tree = ET.parse(xmlfile)
## print tree.getroot().tag, tree.getroot().text,tree.getroot().tail,tree.getroot().attrib
# Edition Date
elem = list(tree.iter("resEdDate"))[0]
# print elem.tag,elem.text
elem.text = edDate
## print elem.text
# Reference Date 001 (Creation)
elem = list(tree.iter("refDate"))[0]
# print elem.tag,elem.text
elem.text = createDate
## print elem.text
# note there may be two of these dates
# DateTypCd 001 and 002
# Reference Date 002 (Publication)
if len(list(tree.iter("refDate"))) > 1 :
elem = list(tree.iter("refDate"))[1]
# print elem.tag,elem.text
elem.text = publishDate
else :
print "skipping publication date",xmlfile
## print elem.text
# clear out lineag if it exists
try :
lin = list(tree.iter("lineage"))[0]
# print lin.tag
lin.clear()
lin.text = "Cleared"
except :
gp.AddMessage("skipping clear lineage")
outfile = xmlfile.replace(".","_et.")
tree.write(outfile)
return outfile
# ---------------------- main ----------------------
try :
publishDate = sys.argv[1]
createDate = sys.argv[2]
if createDate == '#' :
createDate = publishDate
gp.AddMessage(publishDate+type(publishDate))
except :
today = datetime.datetime.now()
firstSat = today.replace(day=1) + datetime.timedelta(5 - datetime.datetime.now().replace(day=1).weekday())
publishDate = firstSat.strftime("%Y%m%d")
createDate = publishDate
# override
publishDate = '20100804'
createDate = '20100710'
gp = arcgisscripting.create(9.3)
os.chdir("e:/crs/metadata")
edDate = str(datetime.datetime.now().date()).replace("-","")
edDate = '20100914'
gp.AddWarning(edDate+" edit date")
gp.AddWarning(publishDate+" publish date")
gp.AddWarning(createDate+" create date")
ws = "e:/crs/corax.gdb"
metasrc = "e:/crs/metadata"
gp.Workspace = ws
os.chdir(metasrc)
print
print ws
print metasrc
print
lstFC = gp.ListFeatureClasses("*")
for fc in lstFC :
# print fc
fcxml = metasrc+"/"+fc+".xml"
if os.path.exists(fcxml) :
etxml = alter(fcxml,edDate,publishDate,createDate)
gp.MetadataImporter_conversion (etxml,fc)
print fc,"updated"
else :
pass
print etxml,"not found"
lstTab = gp.ListTables("*")
for tab in lstTab :
# print tab
tabxml = metasrc+"/"+tab+".xml"
if os.path.exists(tabxml) :
etxml = alter(tabxml,edDate,publishDate,createDate)
gp.MetadataImporter_conversion (etxml,tab)
print tab,"updated"
gp.AddMessage(tab+" updated")
else :
pass
print etxml,"not found"
gp.AddError(etxml+" not found")
... View more
09-27-2010
02:51 AM
|
0
|
0
|
646
|
|
POST
|
I have a rule that any process that takes longer than a "cup of coffee" should be interrupted and a better way found. Multiple ring buffer is a particularly difficult process because it is a script that repeats the problem many times. You problem is likely to be inappropriate data. Can you get a single buffer to work? Buffers can be miss-applied if you have the wrong tolerances and over complex source that you are buffering. You can easily end up with millions of intersections that have to be resolved, and eventually after an hour the process runs out of memory. There is a good presentation by Dale Honeycutt and al "Overlay and Proximity" technical workshop http://proceedings.esri.com/dvd/uc/2009/uc/tws/workshops/tw_715.pdf that explains what happens in a buffer_dissolve. Start with a very simple shape and get that working. Experiment with simplifying the source first and make sure it finishes in seconds. Then try the multiple buffer.
... View more
09-27-2010
02:32 AM
|
0
|
0
|
602
|
|
POST
|
I am told that there was a deliberate decision to not create one for 10.0. We are supposed to use the intellisense for syntax and the help documentation. I miss the 9.3 diagram, I found it a helpful quick reference. Maybe we can set up a request on ideas.arcgis.com and vote for it for 10.1?
... View more
09-18-2010
01:48 AM
|
0
|
0
|
459
|
|
POST
|
You are reinventing ArcGIS in a Python script. There is rarely a need to loop through a set of features to do a selection. You will be running out of memory in double quick time. It is tempting to run a cursor with a few hundred records, but calling a tool while in a cursor is also very slow. I am not sure what your process is, but there must be a command in the toolbox that would do what you appear to be wanting to do with one overlay command that will attach the respective objectids as an attribute in one fast step. I have been doing a similar overlay process this week with 700,000 records on a route system made from 500,000 records and it completes in around 7 minutes. I did avoid CalibrateRoutes and used a modified PointsToPolylines to build a routesystem directly.
... View more
09-18-2010
01:14 AM
|
0
|
0
|
545
|
|
POST
|
pnt = part.Next()
partnum += 1
This doesn't look right either, setting a point object to the next part.
... View more
09-12-2010
04:48 PM
|
0
|
0
|
954
|
|
POST
|
Vertices in Parts are not properly pythonic iterable. You have to use a next() operator or wrap the function in an iterator. See my example on the resources for stepping through parts to find and delete donuts in polygons. The same applies to polylines. http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=C4E10FE5-1422-2418-A06D-33952BB8D1D7
... View more
09-12-2010
04:44 PM
|
0
|
0
|
954
|
|
POST
|
Surely you don't need to iterate the split list? It is already a list after a split print len(fidSet.split(";")) just being economical.
... View more
09-10-2010
06:04 AM
|
0
|
0
|
1444
|
|
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
|
494
|
|
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
|
1043
|
|
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
|
1262
|
|
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
|
1262
|
|
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
|
742
|
|
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
|
1001
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-26-2025 03:48 PM | |
| 1 | 05-08-2025 02:07 PM | |
| 1 | 05-07-2025 05:13 PM | |
| 3 | 04-04-2025 03:16 PM | |
| 2 | 05-07-2025 05:21 PM |
| Online Status |
Offline
|
| Date Last Visited |
10-20-2025
06:39 PM
|