|
POST
|
MakeTableQuery does not do anything in 2 seconds, it just creates a query definition (and validates it?). As soon as you use it to open the table it will run out of memory. No geoprocessing tools in ArcMap work in human time with more than about a million records. It either runs out of memory and hangs in seconds forever or produces nothing. I do notice that at 10.1 there are some tools that clearly run a partitioning strategy behind the scenes to improve the scalability of some tools. If a single process does not finish in the time it takes to drink a cup of coffee, interrupt the process and find a better way. Don't even wait for lunch! I did manage to process file geodatabase tables (with only a tenth of your numbers) by partitioning into 12 parts and it only took a few minutes for each part after hanging on full queries to total 32 minutes. The first option surely would be to open up the native database admin tools and run an SQL query there. You do not say what it is. Or you could upgrade to 10.1 which has a faster data_access module. If you want to persist with geoprocessing tools, Python dictionaries work really well instead of a join, but pre 10.1 the UpdateCursor is too slow and will sabotage the effort. To get around that it can be quicker to dump the table as a CSV file in Python and load it back again. I have seen a cool solution using SQLite inside a Python script (SQLite is built into Python) instead of using a file geodatabase as an intermediate database. Index Everything. Make sure that the keys have an attribute index.
... View more
07-02-2012
06:06 PM
|
0
|
0
|
1810
|
|
POST
|
Debug it in the console as well. Use Pythonwin because it is easier to check the syntax is correct and debug. Check if it exists again there. If the path contains backslashes then they have to be handled as escape characters in a string. Use forward slashes instead, or a raw tag r"C:\path" or two backslashes "c:\\path". Put the script in a python file and execute that. You must have a really simple error that is so obvious that you cannot see it. Maybe the path is to an empty geodatabase because you are looking at different users. Browse to it using ArcCatalog and look there to see if there is anything there. The path on my machine to the default.gdb is
r"C:\Users\kimo\My Documents\ArcGIS\Default.gdb"
... View more
07-02-2012
05:30 PM
|
0
|
1
|
1515
|
|
POST
|
You have a missing r tag to make the path work as a raw string with backslashes, but that is not the issue. The help clearly says that it will append _1 if the file exists, so it obviously does not honour the environment setting. So just check if it exists and delete it yourself. arcpy.env.workspace = "destination_folder"
if arcpy.Exists(x):
arcpy.management.Delete(x)
arcpy.conversion.FeatureClassToShapefile(x,"destination_folder")
... View more
07-02-2012
05:16 PM
|
0
|
0
|
3020
|
|
POST
|
Create a list of indexes for a table using Describe and then delete them using the geoprocessing tool. Since you can supply a list, then that is done in one step. Ignore the first index on the objectid. arcpy.env.workspace = "e:/crs/mobile/mobile.gdb"
dsc = arcpy.Describe("sap")
lstIndex = [i.name for i in dsc.Indexes][1:]
print lstIndex
arcpy.management.RemoveIndex("sap",lstIndex)
... View more
07-02-2012
05:00 PM
|
0
|
0
|
1113
|
|
POST
|
The case I have found does not use an input featureclass. I am creating a featureclass from an interactive featureset. It seems that the 'relative' option on the tool properties does not handle unexpected root paths. Maybe the template needed for this datatype is not being parsed properly. I try to make all my own 'home' calculations by parsing the location of the script using python functions. home2 = os.path.dirname(os.path.dirname(sys.argv[0])).replace("\\","/")
domain = os.path.basename(home)
arcpy.AddWarning(domain)
basews = home+"/base.gdb"
scratchws = home+"/scratch.gdb" Using a layer source only applies if you are running tools interactively and in process in ArcMap. I want to also run tools for debugging, and in ArcCatalog. try:
lay = arcpy.mapping.ListLayers(mxd,"Domain")[0]
if lay.supports("DATASOURCE"):
source = lay.dataSource
home = os.path.dirname(os.path.dirname(source)).replace("\\","/")
except :
if source:
home = os.path.dirname(os.path.dirname(source)).replace("\\","/")
else:
arcpy.AddError("Domain layer missing in MXD, cannot find Domain location")
sys.exit()
This lack of robustness for paths is a serious impediment to distribution of reliable tools and models. I know that it is very hard for Esri to support relative paths when Microsoft only provides grudging support to be POSIX compliant. It is a problem with COM or .NET or Python? It would be helpful to know to avoid and build reliable workarounds.
... View more
06-30-2012
03:56 PM
|
0
|
0
|
1113
|
|
POST
|
The convention that you do not use spaces or other special characters in pathnames is long standing but flouted by Microsoft users. Special characters are "legal" in many operating systems, but by convention are not used in unix, and could not be used in MS DOS. Because Apple has a "fork" for file names (an alias) there was pressure on MS to allow file names to be full sentences in Windows 3.1. Hence the "Program <space> Files" that broke all previous DOS code, and allowed ridiculous file names for Word documents. I suppose it was to provide some rudimentary metadata functionality in the absence of full text searching and even the concept of metadata. So we all know this and observe the convention, because if we don't, strange unrelated crashes regularly occur. We kept ARC/INFO Workstation executables out of 'Program Files" and even Python avoids this path on Windows. Databases have further restrictions for table names and field names, particularly not starting with a digit. Starting with a digit will still cause crashes if you are using any GRID functions. Using a source shapefile with paths containing spaces will fail in geoprocessing tools. My problem now is to 'bullet-proof' models or tools that are intended to be distributed where the path names are no longer under control of the developer. I have discovered one workaround to the input problem, use a list even if there is only one input. This seems to insulate the path. lstFC = [r"E:\05 CCAMLR GIS\Circumpolar_shapefiles\Benthic_regionalisation_DelCano_Crozet_level2.shp"] My second problem is the installation of the tool. The suggested template A_structure_for_sharing_tools only works for me if the "toolshare" path is without punctuation or starting with a digit. Do you have strange path names in your system? How do you get the tools to work in this environment?
... View more
06-29-2012
02:16 PM
|
0
|
2
|
1525
|
|
POST
|
Setting a workspace is just a variable, it does not test if the workspace exists. Try a test first to debug your path. I got the same null response when using XP because of course the path is different. >>> import arcpy
>>> arcpy.env.workspace = "c:/users/kimo/documents/arcgis/default.gdb"
>>> arcpy.ListFeatureClasses()
[]
>>> arcpy.env.workspace = r"C:\Documents and Settings\kimo\My Documents\ArcGIS\Default.gdb"
>>> arcpy.ListFeatureClasses()
[u'sea1_Buffer', u'amenity2_EliminatePolygonPar']
>>> ws = r"C:\Documents and Settings\kimo\My Documents\ArcGIS\Default.gdb"
>>> if arcpy.Exists(ws):
... arcpy.ListFeatureClasses()
... else:
... print "Workspace not found"
...
[u'sea1_Buffer', u'amenity2_EliminatePolygonPar'] The path does not have to be unicode u"path" but you do have to be careful with path separators.
... View more
06-29-2012
01:35 PM
|
0
|
0
|
1515
|
|
POST
|
What a challenge to an old school surveyor's assistant! An array of coordinate pairs is what we always had after reducing a traverse, when we had to calculate the parcel area. This was hard to do with only an adding machine and 10 figure log book. Hence the Double Difference Area method: Consider each segment is a trapezoid above the X axis. The area is half times the average of the Y of each side times the difference of the X values. Sum these areas and that is the net area. Wait until the end to halve the Y values once. As you go around the polygon, coming in reverse has negative values under the polygon. I'm not quite sure why Esri gets a different result (1 in a million), must be the round off of the precision. # area of multiparts
import arcgisscripting
gp = arcgisscripting.create(9.3)
infc = "C:/path.gdb/multipolyfc"
dsc = gp.Describe(infc)
shapefieldname = dsc.ShapeFieldName
rows = gp.SearchCursor(infc) #,"multipart = 2")
row = rows.Next()
while row:
feat = row.getValue(shapefieldname)
partnum = 0
partcount = feat.PartCount
partArea = 0
cumArea = 0
print partcount ,feat.area
# iterate through each part of a multipart feature
while partnum < partcount:
arrayPoly = feat.GetPart(partnum)
# iterate through each vertex of the array
# use old pre-computer Double Difference Area survey trick
pt = arrayPoly.next()
x0 = pt.x
y0 = pt.y
pt = arrayPoly.next()
partArea = 0
while pt:
partArea += (pt.x - x0) * (pt.y + y0)
x0 = pt.x
y0 = pt.y
pt = arrayPoly.next()
partnum += 1
partArea = partArea / 2.0
print partnum,partArea
cumArea += partArea
print "count %d,cum %f, feat %f diff (%12.8f) " % (partcount, cumArea,feat.area ,(feat.area - cumArea)/100)
# break
row = rows.Next()
del row
del rows
... View more
06-13-2012
01:57 AM
|
0
|
0
|
1434
|
|
POST
|
I used to have this problem with ArcStorm Libraries. How to stop unreasonable requests from even starting. My solution was to add a spatial index of my own that has a summary feature count. This is selected first and if there are too many tiles or too many features then the command is not run. The tiles can be a quartered pattern in size just like ArcStorm to allow for rural and urban density differences. It might take a little time to experiment on the tile sizes and count the features, but it does not need to be updated for normal editing because it will be near enough. ArcStorm automated the quartered tile building, but I cannot see it would take much to replicate in a python script, or use the Google tile pattern perhaps.
... View more
05-30-2012
12:40 AM
|
0
|
0
|
1551
|
|
POST
|
Open the tool and run it interactively. After it has run, open up the results and right-click to 'Copy as python snippet' to get a successful command to paste into a script as a template.
... View more
05-30-2012
12:27 AM
|
0
|
0
|
738
|
|
POST
|
What about using SQLite inside Python? This might manage data better and you can run an SQL query to do the matching instead of a dictionary. SQLite is built into python and there are no 2GB size limits. Does it load everything into memory? Attached is an example using SQLite to find duplicates in a large database where python dictionaries overflowed. (Not written by me)
... View more
05-30-2012
12:08 AM
|
0
|
0
|
4212
|
|
POST
|
The error message came back when I installed the patch for the overlay bug introduced in 10.0 SP 4. It took me a while to remember... Delete C:\Python26\ArcGIS10.0 folder. (Empty except for a Desktop10.pth) Start up the Python 2.6.6 installer python-2.6.6.exe and choose repair 2.6.6 Everything now back to normal.
... View more
05-29-2012
01:25 AM
|
0
|
0
|
1834
|
|
POST
|
You can interactively create a sketch in a tool using a featureset type. This is then passed into the script as a feature which you can manipulate just like any other feature. Here is an example where I get a polygon drawn in ArcMap, get an autoincrement number and write it out to a featureclass. This is available from 9.3+ mpa = gp.GetParameter(0)
# get the id and name from first record if set
cur = gp.SearchCursor(mpa)
row = cur.next()
MPAName = row.MPAName
mpaid = row.mpaid
del row,cur
if MPAName == None and mpaid == None :
MPAName = "MPA"
mpaid = 0
elif mpaid > 0 and MPAName == None:
MPAName = "MPA"+str(mpaid)
elif mpaid == None and MPAName != None :
# keep override name
mpaid = int(MPAName[3:])
else :
gp.AddWarning(MPAName)
gp.AddWarning(mpaid)
# rename all parts with a unique name for a dissolve
# increments to highest number or blank or zero
if not gp.Exists("MPA") :
gp.CopyFeatures("template_mpa","MPA")
if not gp.Exists("MPA0") :
gp.CopyFeatures("template_mpa","MPA0")
fcName = gp.CreateUniqueName(MPAName,ws)
fcName = os.path.basename(fcName)
MPAName = fcName # update
mpaid = int(MPAName[3:])
## gp.AddWarning(str(mpaid)+" "+MPAName)
cur = gp.UpdateCursor(mpa)
row = cur.next()
while row:
row.MPAName = fcName
row.mpaid = mpaid
cur.updateRow(row)
row = cur.next()
del row,cur
... View more
05-20-2012
12:38 AM
|
0
|
0
|
1072
|
|
POST
|
Oddly I did notice that arcpy.AddMessage does print if you run the script from the CMD window! Which is very frustrating if you have doubled up with print messages, you get the messages twice.
... View more
05-20-2012
12:31 AM
|
0
|
0
|
3209
|
|
POST
|
Optional parameters are passed as a # character so that place counting is preserved. So you could test for the value being == '#' to see if it was not set.
... View more
05-13-2012
01:32 PM
|
0
|
0
|
1074
|
| 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
|