|
POST
|
I don't have enough information about your sources, paths and error messages to see what is going wrong.
... View more
06-08-2010
01:11 AM
|
0
|
0
|
3149
|
|
POST
|
Is there a geoprocessing tool that is equivalent to going to the options button on a table and selecting "Related Tables"? If not has anyone written a script that accomplishes the same? Thanks, Jeff Ward Try the keyfile toolbox and script. http://arcscripts.esri.com/details.asp?dbid=16286
... View more
06-03-2010
07:44 PM
|
0
|
0
|
645
|
|
POST
|
1-I want to batch the process. It will be very convenient not to select every filesmuself, but "tell python" where the files are located and let him selecting them. 2-When I run the script I get this message: Failed to execute. Parameters are not valid. The value cannot be a table ERROR 000840: The value is not a Raster Layer. Failed to execute (AddJoin). I don't see where I the raster is involved in my process. The parameter for my arguments are Folder, Feature Class and Table. No raster around??? I am a little bit desperate!! Thanks for your help Steeve AddJoin only takes Layers and Views not featureclasses and tables, odd message but that is likely the reason. Here is my edited version as I think you want to do. Might have to edit it a bit more ################################################## ########################
#Join a table to a feature layer
#Steeve Deschenes
#Carex Canada
#June 2010
################################################## #######################
# Import system modules
import sys, os, arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Load required toolboxes...
## gp.AddToolbox("C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Data Management Tools.tbx")
## no need for system toolboxes
# Local variables...
workingfolder = sys.argv[1]
source = sys.argv[2]
concentration = sys.argv[3]
#Set workspace
gp.Workspace = workingfolder
#Get a list of the feature classes in the input folder
try:
enumFC = gp.ListFeatureClasses()
## fcs.Reset() never actually implemented
fc = enumFC.Next()
i = 0
while fc :
i+=1
print fc
gp.MakeFeatureLayer_management (source, "source_lay")
gp.MakeTableView_management ("NUMR_ECHN", "con_lay")
# have to have Layers or Views for AddJoin not featureclasses or tables
gp.AddJoin_management("con_lay", "NUMR_ECHN", "out_lay", "NUMR_ECHN_LOCL", "KEEP_ALL")
gp.CopyFeatures_management ("out_lay", fc + "_resultat.shp")
fc = enumFC.Next()
except Exception, errmsg:
gp.AddError(gp.GetMessages())
print errmsg,gp.GetMessages
... View more
06-03-2010
07:38 PM
|
0
|
0
|
3148
|
|
POST
|
I've actually tried VB and Python (and every punctuation mark I could think of) and neither works. I ran out of things to try and ended up just doing this in ArcMap. I think the Calculate_Field tool is buggy or something because it works sometimes and othertimes it doesn't. It is more likely that you have data that causes a crash in the expression. If you use the field calculator you do not have the opportunity to trap data errors in a try/except block and its impossible to see what record caused it. Since the CalculateField simply wraps the expression in a cursor, it is much much better to use your own cursor in a script and do the expression inside a try/except block. CalculateField is more useful in interactive processes or models.
... View more
06-03-2010
06:22 AM
|
0
|
0
|
1560
|
|
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
|
771
|
|
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
|
771
|
|
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
|
932
|
|
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
|
769
|
|
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
|
1131
|
|
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
|
3605
|
|
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
|
3739
|
|
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
|
2244
|
|
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
|
1496
|
|
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
|
1622
|
|
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
|
1299
|
| Title | Kudos | Posted |
|---|---|---|
| 3 | Tuesday | |
| 1 | 3 weeks ago | |
| 1 | 03-11-2023 03:54 PM | |
| 1 | 09-15-2024 10:32 PM | |
| 1 | 03-12-2026 01:10 AM |
| Online Status |
Offline
|
| Date Last Visited |
Tuesday
|