|
POST
|
fperks;16230 wrote: Heres an easy way to make arcpy non iterable objects usable in a for each loop.
for each in iter(lambda: <your object>.next(), None):
This basically iterates through getting the next element until the termination condition of the element being None is met. Thanks very much. Wonderfully Pythonic!
... View more
06-01-2010
04:27 AM
|
0
|
0
|
656
|
|
POST
|
I haven't really seen any bugs regarding comtypes and ArcObjects, except one: it doesn't wrap the esriSystem.Array object since there's a name clash with ctypes Array. I'd be curious as to what version of comtypes you've been using and what problems you've been seeing. I did notice that in arcpy the Array object is not iterable. I had to use the .next() function. Should I expect it to be iterable?
while row:
feat = row.getValue(shapefield)
qInterior = False
for partNum in range(feat.partCount) :
part = feat.getPart(partNum)
qInterior = False
for ptNum in range(part.count):
pt = part.next()
if pt != None:
arrayOuter.add(pt)
else :
qInterior = True
break # ignore donut vertices
arrayObj.add(arrayOuter)
arrayOuter.RemoveAll()
... View more
05-30-2010
07:09 PM
|
0
|
0
|
656
|
|
POST
|
Yes, its a real pain! Thefull list is in a couple of PDF files buried in the documentation folder in the ArcGIS install location. I have a little text file on my desktop that I can open and cut-and-paste the required transform string.
... View more
05-20-2010
03:17 AM
|
0
|
0
|
780
|
|
POST
|
I see that in one context the domain is included in the spatial reference object. However it is not included in the spatial reference projection file. So I was looking in the wrong place. Unless I looked up the geoprocessing diagram I would not have noticed that it was included. The issue of gp.Merge creating a different domain is still a problem. We are not supposed to have to set these with high precision geodatabases any more. Surely that is a bug?
... View more
05-17-2010
03:44 PM
|
0
|
0
|
624
|
|
POST
|
If the spatial reference of featureclasses are not identical to a dataset then you cannot load them. You get an error message. So you can change the spatial reference and try again. Nope. So export out and compare. Identical. The problem is actually in the DOMAIN values. Since these are now so large a default set is created in "high precision" geodatabases I have ignored these until now.... (Not to be confused with attribute domains) The trouble is that you cannot change the spatial domain once set even it the change would be irrelevant to the data content. Different tools create different default extents depending on the target geodatabase. A cut/paste copy will fail if the domains between the dataset and featureclass differ. The MERGE tool creates a slightly different spatial domain from other tools if merging from coverages to a 9.3 file geodatabase base layer. Then the output featureclass cannot be copied into a default dataset. If the target is a defaultly defined dataset (instead of the top-level geodatabase) then the domain of the featureclass is different and correctly defined to allow the merge to be completed. Suggested bugfixes: Get the error message updated to mention the domain difference if that is the case, instead of blaming the spatial reference. Maybe allow the domain to be altered on copy? Or have a special tool to fix the domain? I hope this is of use to everyone else puzzling about the misleading error message.
... View more
05-16-2010
04:06 PM
|
0
|
3
|
986
|
|
POST
|
When I do a Describe on a field in a featureclass to be able to create a foreign key in a new table you would think that the terms would match those required in AddField but they don't and the alternatives are not accepted in the tool. 'SmallInteger' has to change to 'SHORT' and so on. The only way is to make up a special dictionary as a workaround eg dFixTypeHack = {'SmallInteger": 'SHORT',..}
... View more
05-02-2010
09:28 PM
|
0
|
6
|
3422
|
|
POST
|
ArcGIS 10 puts its own copy of Python26 in a subdirectory of Python26/ArcGIS10.0 (!) When you install your own Python26 it does not copy the link for ArcGIS python extensions move Desktop10.pth and the numpy folder back to C:/Python26/Lib/site-packages and all will be standard and well. You can then delete the whole ArcGIS10.0 folder so that you only have one version of 2.6 installed
... View more
04-29-2010
04:46 PM
|
0
|
0
|
3494
|
|
POST
|
You can define an output projection (and transform) for a cursor and write out projected coordinates. # extent_xy.py
# add extents of parcels in NZMG to a NZTM dataset for backward compatibility
# update to use on the fly projection directly from NZTM layers
# see Werner Flacke's book and script example
# updated for 9.2
# Kim Ollivier 13 April 2007
# input NZTM coverage library, parcel and plabel coverages
# output csv files to load and join back to coverages using AML
# issues solved:
# add spatial reference to SearchCursor
# define a Geographic Transformation that works with a coverage
# because coverages cannot define NZGD2000 use WGS84 definition
# or the transform is ignored
import os,sys,glob,arcgisscripting
gp = arcgisscripting.create()
def parcel(tile) :
print "Parcel",tile
ws = "e:/lib/nztm/tile/t"+str(tile)+"/data"
outfolder = "e:/lib/nztm/tile/t"+str(tile)+"/data"
ds = ws + "/parcel"
f1 = open(outfolder+"/e_parcel.txt","w")
f1.write("par_id,eminx_nzmg,eminy_nzmg,emaxx_nzmg,emaxy_nzmg\n")
gp.Workspace = ds
print ds
# this is a good on-the-fly switch for the searchcursor
# srOut must be a com object, not a file ref or a factory code
rows = gp.SearchCursor(ds+"/polygon",'"PAR_ID" > 0',srOut)
n = 0
rows.Reset()
row = rows.Next()
while row :
print >> f1,"%d,%s" % (row.par_id,row.shape.Extent.replace(" ",","))
row = rows.Next()
n +=1
del rows
print n,"Polygons"
f1.close()
return
def plabel(tile) :
print "Plabel",tile
ws = "e:/lib/nztm/tile/t"+str(tile)+"/data"
ds = ws + "/plabel"
outfolder = "e:/lib/nztm/tile/t"+str(tile)+"/data"
f2 = open(outfolder+"/e_plabel.txt","w")
f2.write("par_id,eminx_nzmg,eminy_nzmg\n")
gp.Workspace = ds
rows = gp.SearchCursor(ds+"/point",'"PAR_ID" > 0',srOut)
n = 0
rows.Reset()
row = rows.Next()
while row :
n += 1
print >>f2,"%d,%s,%s" % (row.par_id,row.shape.Extent.split()[0],row.shape.Extent.split()[1])
row = rows.Next()
del rows
print n,"plabels"
f2.close()
return
# ------ main ----
#
srOut = gp.CreateObject("SpatialReference")
srOut.CreateFromFile("c:/arcgis/nzmg.prj")
# WGS_1984 works for coverages defined with an equivalent custom Transverse projection definition
gp.GeographicTransformations = 'NZGD_1949_To_WGS_1984_3_NTv2' # ;New_Zealand_1949_To_NZGD_2000_3_NTv2'
# but is this being used?
inFC = "e:/lib/nztm/tile/t1009/data/plabel/point"
# not at 9.3?? outFC = "in_memory/dummy1.shp"
outFC = "c:/tmp/dummy1.shp"
outPrj = "c:/arcgis/nzmg.prj" # cannot be a COM object or factory id 43040
geoTrans = "NZGD_1949_To_WGS_1984_3_NTv2" # ;New_Zealand_1949_To_NZGD_2000_3_NTv2"
if gp.Exists("c:/tmp/dummy1.shp") :
gp.Delete("c:/tmp/dummy1.shp")
#
gp.OverwriteOutput = 1
gp.MakeFeatureLayer_management(inFC,"tlayer","PLABEL# < 3")
gp.Project_management("tlayer",outFC,outPrj,geoTrans)
try :
if sys.argv[1].upper() == 'ALL' :
lstTile = range(1001,1013)
else :
lstTile = [ tile for t in sys.argv[1].split(",")]
except :
lstTile = range(1001,1013)
print "begin extent_xy"
for t in lstTile :
print t
parcel(t)
plabel(t)
... View more
04-29-2010
04:42 PM
|
0
|
0
|
2050
|
|
POST
|
I think I can guess what is happening. You will get into trouble deleting records while looping through the same set. The only way to make this safe to delete records is to make a copy of the keys or the full set and use that in the loop.
... View more
04-29-2010
04:35 PM
|
0
|
0
|
1356
|
|
POST
|
Yes, this is a very successful way of creating an SQL query that is efficient. A keyfile type selection is often wanted, and the MakeQueryTable is buggy at 9.3 and has a lot of limitations. You have to have all features in the same geodatabase, complex expressions are not supported in file geodatabase and so on. Here is my workaround: Loop through the first table with a cursor to collect a list of keys. Pass it through a SET structure to remove duplicates. Create a (potentially huge) sql expression Use this expression on the source featureclass to create a layer Process or export the layer to a new featureclass # to make a keyfile
# 26 April 2010 kimo
# much better than MakeQueryTable and it works across geodatabases
# still uses an SQL query but python generates the set for the expression
# will work for tens of thousands of keys (amazing)
# if you want to save the featureclass or table as a layer or view definition
# to use in ArcMap (without making a copy) you MUST have an index on the key field
# or it will be extremely slow to draw.
# see the Keyfile tool in ArcScripts for an alternative method using selection sets in ArcMap
import arcgisscripting,sys,os,datetime,fileinput
gp = arcgisscripting.create(9.3)
def titlekey(title) :
gp.Workspace = ws
# Make a title set to use as a keyfile
lstTitle = []
cur = gp.SearchCursor(title)
row = cur.next()
while row :
lstTitle.append(row.ttl_title_no)
row = cur.next()
del row,cur
return set(lstTitle)
def title_tab(src) :
" use setTitle to export records to a table"
start = datetime.datetime.now()
gp.Workspace = ws
setTitle = titlekey(title)
expTitle = ",".join(["'"+t+"'" for t in setTitle])
sqlQuery = "ttl_title_no in ("+expTitle+")"
gp.MakeTableView_management(src,src+"_view",sqlQuery,wsout)
gp.OverwriteOutput = True
gp.CopyRows_management(src+"_view",wsout+"/"+src+"_sub")
print gp.GetCount(wsout+"/"+src+"_sub").Getoutput(0),"records in "+src+"_sub"
print datetime.datetime.now() - start
# ------------------------- main -------------------------
title = "e:/arrears.mdb/title"
ws = "e:/memo.gdb"
wsout = "e:/arrears.mdb"
# create subsets based on title keys
if not gp.Exists(wsout+"/tta_sub") :
title_tab("tta")
... View more
04-29-2010
04:20 PM
|
0
|
0
|
1470
|
|
POST
|
Not yet in Prerelease 10. Even the 9.3 pdf has been removed, which I think is a mistake, since we will need to support a lot of old style scripts for years. Keep your own copy before uninstalling 9.3! I hope that there will be a new diagram. Not holding out hope for a new book. The authors have moved on to other projects.
... View more
04-29-2010
03:55 PM
|
0
|
0
|
1071
|
|
POST
|
I have an icon on the start menu at Programs>Python 2.6>Pythonwin. Of course I had to hack the Explorer filetypes to set the edit paths properly for .py files, but I have to do that in every training course since 9.1 for all the students. I am still annoyed at the install hijacking the Python 2.6 install directory with another level under C:\Python26\ArcGIS9.4\ . Yuck! a full stop in a directory path? How non-standard is that? This apparently does not happen if Python 2.6 is already installed, so perhaps Python should be installed before ArcGIS, as a prerequisite just like .NET. Then apparently we get ArcGIS to respect the normal structure. I will give it a try to see if I can defeat the odd behaviour at Beta 2 by installing Python again first.
... View more
01-27-2010
12:13 AM
|
0
|
0
|
1134
|
|
POST
|
Hope you might look at these procedures in the future to make contributions from over seas a bit easier... At least for beta testers. Surely the beta team want direct feedback? I am sorry that reporting through the distributor support desk is not worth the effort for me so I just ignore the requests to report a beta bug that way. We know there will be bugs, its not a production issue. If the beta team are not monitoring the beta feedback forums then why bother at all? The agreement requires active testing and feedback.
... View more
12-09-2009
12:52 PM
|
0
|
0
|
3217
|
|
POST
|
I also use mapbook extensively to generate atlases and also to render raster images for an image catalog. This is still hard to get right, I have to revert to page imperial units to match dots-per-inch exactly to get the right number of pixels in a page with no borders etc. An option to export the world file of the page when exporting as an image would save me another painful calculation step in Python, using an index, finding the corners of the page and doing my own transform. When you get down to the details to look at the edges of tiles exported like this it is clear that the X and Y scales are slightly off, so the tiles are not seamless. So yet another external package adjust to rescale, resize and reclip to extract out an accuractly scaled and registered image.
... View more
12-09-2009
11:55 AM
|
0
|
0
|
2470
|
|
POST
|
"The Topo to Raster tool has not been updated for 9.4. Its still the same version of ANUDEM as it is in prior releases." ie 4.5 What a pity, I was hoping for an updated version of ANUDEM, say 5.2, that now uses breaklines and has improved the model in other areas. I find I have to tile up my topo data to build a good DEM but unfortunately there are a lot of artifacts when that is done. 1. You have to handle split lakes separately to find the level and mask them afterwards. 2. Islands in lakes are not handled, so these have to be put back in. 3. Large features on the edge do not get modelled properly unless you have an enormous cell buffer. 4. Floodplains are very hard to get looking plausible especially if you add stream lines that meander. 5. Every now and again there is a spike in the model caused by some unknown issue in the data. 6. Using a file based parameter list does not cut it because the parameters need to be dynamic to handle a series of tiles. 7. There is a limit to the number of tiles that can be merged, so it has to be done in a series of ever larger builds. Replacing a faulty tile is very difficult because of the complicated merge. 8. The limit command does not work to limit the data processed so I have to clip all participating layers for each tile. 9. Hillshade grids will be one pixel short all around the tile, so they cannot be merged later unless you build oversize tiles and then clip again. 10. Some tiles are too sparse to build, for example small islands off the coast, so the tiles have to be combined into a single non-standard tile, processed and then clipped out. The process is extremely complex so I have reverted to a series of AML and Workstation that run to completion.
... View more
12-07-2009
09:44 PM
|
0
|
0
|
2385
|
| 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
|