|
POST
|
I need a script to check the attribute indexes of every feature class in a geodatabase, to delete or create the indexes to fit my needs. I've used the ListIndexes arcpy function but it lists not only attribute indexes but also spatial indexes. Is there a way to list only attribute indexes? import arcpy
fields = "OBJECTID"
index_name = "FDO_OBJECTID"
unique_vals = "UNIQUE"
order = "ASCENDING"
FSO_OID = False
try:
gdb = arcpy.GetParameterAsText(0)
arcpy.env.workspace = gdb
fdatasets = arcpy.ListDatasets()
for fdataset in fdatasets:
arcpy.AddMessage("Feature dataset: " + fdataset)
arcpy.AddMessage('-' * 40)
fcs = arcpy.ListFeatureClasses('','',fdataset)
for fc in fcs:
indexes = arcpy.ListIndexes(fc) # ----> Lists both attribute and spatial indexes!!!
for index in indexes:
if (index.name <> index_name):
arcpy.RemoveIndex_management(fc, index.name)
else:
FSO_OID = True
if FSO_OID == False:
arcpy.AddIndex_management(fc, fields, index_name, unique_vals, order)
except:
arcpy.GetMessages(2) What I don't know is if *all* spatial indexes have the word "Shape" in them. If so, then you can just test for this string value in the index name:
'skip over any index name with string Shape in it
if not "Shape" in index.name:
arcpy.RemoveIndex_management(fc, index.name)
Or alternatively, can you just skip over the ObjectID field to check for attribute indexes? (I am not sure if that is sufficient because I don't know if all spatial indexes are found on that field).
'describe each featureclass and build a list of indexes on each
for fc in fcs:
dsc = arcpy.Describe(fc)
listOfIndexes = [idx.name for idx in dsc.Indexes][1:]
I question the validity of simply skipping over the OID field as this. When I look at the properties of a FeatureClass and see it's spatial index name "FDO_Shape", it also shows up in the listOfIndexes list when run. So, it appears to not catch it by simply skipping over the OID. Sorry for a non-direct answer, but maybe you can sort it out from here.
... View more
11-21-2013
04:12 AM
|
0
|
0
|
1949
|
|
POST
|
From http://resources.arcgis.com/en/help/main/10.2/index.html#//002z00000021000000 "The object will return a list of lists in the case where the statement returns rows from a table; for statements that do not return rows, it will return an indication of the success or failure of the statement (True for success, None for failure)." So I suspect that since you are not returning rows, you are evaluating something else as a result. Edit: try this and see if it produces your expected value...
sqlresults = connSQL.execute(sql)
for result in sqlresults:
print result
... View more
11-20-2013
08:59 AM
|
0
|
0
|
5336
|
|
POST
|
James, Yes, the sequence does exists and I get an integer value back when I run the SQL in SQL*PLUS. The second part of the question deals calling a PL/SQL function from arcpy. If so, we can go that route. I do not get an ORA error from the code but the return value is giberish and unusable, as clearly I did not get the sequence value back from the call. In the meantime, I will look into cx_oracle but like I said I am useasy about hardcoing login credentials into code like the examples I have seen. That is why I would prefer to do this using arcpy because the credentials are obtained from the users sde files which are used connect to the database when they pick their input feature classes in the GP tool interface. -Jim I'm fairly new to Oracle, but lots of RDBMS development work on other systems (SQL Server), so the sequence thing is new for me. But that doesn't seem to be the problem and I suspect it has to do with ArcSDESQLExecute inability to determine just what the heck is going on. Here's hoping you can find a way 🙂 You can use a DSN or TNS name for the cx_Oracle connection parameters and you should have no problem interfacing with your Stored Procedures. We use the cx_Oracle library and it works very well for us (and we are in a Citrix envrionment too).
... View more
11-20-2013
08:48 AM
|
0
|
0
|
5336
|
|
POST
|
James, When you execute the SQL in SQL Developer, Toad or whatever database tool/UI, what is the result? I copied your sql "SELECT ID_SEQ.CURRVAL FROM DUAL" into a SQL Developer query window and ran it and it returned the error: "ORA-02289: squence does not exist" Cause: the sequence does not exist or the user does not have the required privilege to perform this operation Action: make sure the sequence name is correct, and that you have the right to perform the desired operatoin on this sequence. Vendor code 2289Error at Line: 1 Column 7 If you can run the statement on your SQL developer without error, then you may want to implement cx_Oracle Python library to execute your sql commands.
... View more
11-20-2013
03:51 AM
|
0
|
0
|
5336
|
|
POST
|
Hi, thanks for your reply. I assumed something like this. the solution with the raster paths sounds good, unfortunately it wouldn't work in my case. in my situation it is very important to query the raster properties directly in the mosaic dataset. i have to do that because i changed the reference system (define projection) of the raster datasets after i added them to a mosaic. the problem is, if i first add the rasters to a mosaic and afterwards change their reference system, the mosaic doesn't recognize the change. i found out that i have to do a synchronize that the changes are recognized. after synchronizing i would have run this python script to ensure, that really the raster properties are up to date. From what I understand, the Mosaic is just a reference pointing to the actual Raster Datasets that are used to populate it. That is, I usually have a File Geodatabase as a workspace that contains both the Mosaic and the individual raster datasets that are added to it. So, if you change/alter the projection information on the individual raster datasets that were originally added to the Mosaic, you should see the change in the properties of the individual rows of the raster field found in the Attribute table of the mosaic. I am uncertain how to reset or redefine the coordinate properties of the Mosaic itself. Use this to check the spatial reference of the individual raster datasets:
env.workspace = r'your path to the worspace containing the raster datasets'
for raster in arcpy.ListRasters():
print raster
desc = arcpy.Describe(raster)
print("Spatial reference name: {0}:".format(desc.spatialReference.name))
I use this to redefine the spatial reference of all raster datasets contained in a workspace. Note: I make this script the source for a Toolbox script/tool and set two parameters (a workspace parameter and a spatial reference parameter)
import arcpy
from arcpy import env
from arcpy.sa import *
prjfile = arcpy.GetParameter(1)
env.workspace = arcpy.GetParameter(0)
for raster in arcpy.ListRasters():
arcpy.AddMessage(str(raster))
arcpy.DefineProjection_management(raster, prjfile)
arcpy.AddMessage("defined projection")
... View more
11-18-2013
04:55 AM
|
0
|
0
|
3418
|
|
POST
|
Are you sure these .dat files are actually rasters? (I have never used/seen a .dat file extension for a raster)
# Process: Copy Raster-- does nothing but convert to tiff
arcpy.CopyRaster_management(indat, outtif, "", "", "256", "NONE", "NONE", "", "NONE", "NONE")
From http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000094000000 CopyRaster_management (in_raster, out_rasterdataset, {config_keyword}, {background_value}, {nodata_value}, {onebit_to_eightbit}, {colormap_to_RGB}, {pixel_type}, {scale_pixel_value}, {RGB_to_Colormap}) You are passing in the .dat as the first parameter (which is expecting a raster) but I suspect you are not doing that. Maybe I don't understand what are the .dat files.
... View more
11-12-2013
03:56 AM
|
0
|
0
|
1569
|
|
POST
|
I have plenty of memory, but I am not seeing any increase in performance 😞 My workflow consists of creating a new table in memory, adding the fields and indexes, appending the data in, and then performing about 7 field calculations using data cursors. I have runt he process both in memory and regular, and they are both running at around 23 hours to complete. I have seen that once your dataset gets a to a certain size, you lose your in memory performance gains. I guess that I am seeing that with my data set. Thanks for all your help! Clinton This may or may not help (maybe just confuse the approach), but I wanted to mention that the in_memory is definitely a performance gainer as long as the RAM is available. The other performance gain is achieved by performing the tabular operations on non-ESRI specific objects. So, we heavily use Pandas Data Frame objects to join/merge tabular data as well as populate new fields with math/statistic operations. We simply convert back and forth between esri and pandas objects using NumPyArrayTo..FeatureClass/Table and FeatureClass/Table..ToNumpyArray Just something to think about as it may provide the performance you require.
... View more
11-06-2013
05:15 AM
|
0
|
0
|
3962
|
|
POST
|
I have gotten some massive performance gains using in_memory over HDD workspaces, especially if you don't use RAID/SSD drives. I did some benchmarking a while back but can't find the results. Depending on the task it could be twice as fast to 20 times faster. Cursors on in_memory tables were the most gains IIRC. And yes, the caveat, you also have to keep on eye on the size of data you are writing to memory. I've crashed machines not being diligent about what is in memory and clearing unneeded data. 64-bit geoprocessing won't help you when trying to commit 64GB of data to memory. x2! Here's a def I use in most of my Python tools/implementations that I am using in_memory. I will insert a call to this before executing the rest of the code.
def clearINMEM():
""" clear out the IN_MEMORY workspace of any featureclasses, rasters and tables """
try:
arcpy.env.workspace = "IN_MEMORY"
fcs = arcpy.ListFeatureClasses()
tabs = arcpy.ListTables()
rasters = arcpy.ListRasters()
### for each FeatClass in the list of fcs's, delete it.
for f in fcs:
arcpy.Delete_management(f)
arcpy.AddMessage("deleted: " + f)
### for each TableClass in the list of tab's, delete it.
for t in tabs:
arcpy.Delete_management(t)
arcpy.AddMessage("deleted: " + t)
### for each Raster in the workspace, delete it
for r in rasters:
arcpy.Delete_management(r)
arcpy.AddMessage("deleted " + str(r))
except:
arcpy.AddMessage("The following error(s) occured attempting to clear WS " + arcpy.GetMessages(2))
return
... View more
10-23-2013
12:51 PM
|
1
|
2
|
3294
|
|
POST
|
I can't believe I am struggling with this as I have other implementations doing this exact same thing but for some reason my join is not working correctly or as expected. The process peforms a join between a FeatureClass in a FGDB and an "in_memory" table. The table(s) is created with ExtractValuesToTable_ga, so I have a "SrcID_Feat" field that matches up to the FeatureClass' "OBJECTID_1" field. If I output the table(s) to disk and perform the exact same join it works just fine. However, with the same exact parameters defined using arcpy.AddJoin_management the join fails. Well, it joins just fine but the joined fields are empty and no errors. I am wondering if there is some difference in field names? If I print out the field names during runtime, they all look good (exactly as they are if they are coming from the tables on disk). Stuck.
gridLyrName = "gridFC"
if arcpy.Exists( r"C:\Extract.gdb\Transects_Selector"):
glyr = r"C:\Extract.gdb\Transects_Selector"
arcpy.MakeFeatureLayer_management(glyr, gridLyrName)
arcpy.env.workspace = "in_memory"
arcpy.env.overwriteOutput = True
tabs = arcpy.ListTables()
for t in tabs:
if "tab" in t:
memtab = "trans_" + t
arcpy.MakeTableView_management(t, memtab)
arcpy.AddJoin_management(gridLyrName, "OBJECTID_1", memtab, "SrcID_Feat", "KEEP_ALL")
arcpy.CopyFeatures_management(gridLyrName, r"C:\Extract.gdb\\" + memtab)
arcpy.RemoveJoin_management(gridLyrName)
FeatClass fields: OBJECTID_1 OBJECTID Shape row column_ delx dely area transectID Shape_Length Shape_Area Table(s) fields: OID Value SrcID_Feat SrcID_Rast Warning
... View more
10-18-2013
07:03 AM
|
0
|
1
|
1215
|
|
POST
|
Here's what I've come up with:
origapp = sys.executable
if "ArcMap" in origapp:
arcpy.AddMessage("...The python script is being executed from ArcGIS/Toolbox")
elif "Pythonwin.exe" in origapp:
print "...The python script is being executed from PythonWin"
... View more
10-01-2013
11:56 AM
|
0
|
0
|
1230
|
|
POST
|
I think I can use sys.stdout to do this... This code, executed from PythonWin prints "pwin.framework.interact.InteractiveView at..."
value = sys.stdout
print value
This code, executed from an ArcToolbox script with the .py as source prints "geoprocessing sys.stdout object object at..."
value = sys.stdout
arcpy.AddMessage(str(value))
Any other ideas are appreciated!
... View more
10-01-2013
11:08 AM
|
0
|
0
|
1230
|
|
POST
|
I have an interesting requirement and looking for comments... In order to reduce duplication of modules/def's in our codebase, I need a way to determine WHERE something is being executed from. That is, our requirement is users will have the ability to execute a process from an ArcToolbox OR from a command line (both with args/params). Is there a way to detect/test if it is being executed from Command line or from an ArcToolbox? The reason is that I will need to set variables in the script with the command line args or toolbox (GetParameter). Thanks, j
... View more
10-01-2013
10:50 AM
|
0
|
4
|
2846
|
|
POST
|
Okay here's a solution I've arrived at: 1. I use the calculated date field (it can be whatever as long as it is in sequence) 2. Use another attribute field (in my case I have the name of the raster) from the raster catalog layer. Turn on labels for that guy. 3. Remove the "Display date" from the animation (found on the time slider options menu). I still struggle with how the sequence is set correctly in the final output/export. It never seems consistent and I can never document how I am able to get it to export the frame-by-frame correctly (sometimes it wants to skip frames at irregular intervals for example). I dunno, I just shut down, restarted the .mxd and reset things and amazingly it exports as intended --- incredibly frustrating to not be able to nail down why. Anyway -- I over-thought a lot of things on this one. But the time-slider just gets me sometimes and pushes me in a direction that appears to be what I need but clouds what it is that really needs to be done! Only thing left is to figure out how to position the label -- it sits directly in the middle of the raster.
... View more
09-23-2013
12:04 PM
|
0
|
0
|
1383
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|