|
POST
|
This only returns/prints info on the FeatureClass for me but it is slow: fcList = arcpy.ListFeatureClasses()
for fc in fcList:
desc = arcpy.Describe(fc)
print '{0} {1}'.format(desc.name, desc.dataType) This zips right through very quickly and returns the same list of only FeatureClasses: fcList = arcpy.ListFeatureClasses()
for fc in fcList:
print fc
... View more
01-17-2014
05:30 AM
|
0
|
0
|
1764
|
|
POST
|
There are some other options however they will require some 3rd party libraries to get it done. NumPy (actually I think that gets installed with ArcGIS 10.1/2 installs) and Pandas. We do lots of raster processing converting back and forth between GDB tables, arrays and back to tables using arcpy.da.TableToNumPyArray, RasterToNumPyArray, and FeatureClassToNumPyArray, etc... do our processing then return results back to GDB formats. To your OP, the pandas library has a DataFrame method .melt that does what you want (flip/transpose). Here's a quick example of using pandas and arcpy's NumPy methods.
import arcpy
import pandas as pd
import numpy as np
import sys
#in table
tab = r'C:\MyGDB.gdb\tabElev'
#out table
tabout = r'C:\MyGDB.gdb\tabElev_out'
#delete the out table if it already exists or code will fail
if arcpy.Exists(tabout):
arcpy.Delete_management(tabout)
#convert the in table to a NumPyArray using all of its fields
tmptab = arcpy.da.TableToNumPyArray(tab, "*")
#convert the array to a pandas data frame
df = pd.DataFrame(tmptab)
#tranpose columns-to-rows using 3 fields (an id field, a decimal field and a TEXT field)
df2 = pd.melt(df, id_vars=['TheIDField', 'TheDecimalField', 'TheTEXTField'])
#convert the pandas data frame back into a NumPyArray so that we can get it back into ESRI/GDB table
newnumpyar = np.array(df2.to_records(), np.dtype([('TheIDField', np.int32),('TheDecimal', '<f8'), ('TheTEXTField', '|S50')]))
#convert the NumPyArray to a GDB table
arcpy.da.NumPyArrayToTable(newnumpyar, tabout, ('TheIDField', 'TheDecimalField', 'TheTEXTField'))
print "finished...no error."
sys.exit()
... View more
01-17-2014
04:49 AM
|
0
|
0
|
1879
|
|
POST
|
This works on a Feature Layer. See if it will work for you! rowcount = int(str(arcpy.GetCount_management("DerivedLayer"))) if rowcount > 0: 'we have rows, do something with them! else: 'no rows in the DerivedLayer, I guess exit? return
... View more
01-09-2014
06:21 AM
|
0
|
0
|
1114
|
|
POST
|
I think I have narrowed down the problem to the Area of Interest parameter. 1. In my script, I dynamically create a polygon feature class that is the same extent of the footprint/boundary of the mosaic. This FC does reside in the same FGDB as the mosaic, but is its own feature class. 2. Running Calculate Statistics toolbox script (which successfully adds classified symbology property) auto-populates the Area of Interest parameter with: CalculateStatistics::area_of_interest and adds an empty polygon fc to the Table of Contents. So, there is something going on there with the tool adding CalculateStatistics::area_of_interest that I am not understanding. Any additional input is appreciated. j
... View more
01-03-2014
05:50 AM
|
0
|
0
|
1381
|
|
POST
|
Hi James, I've noticed after a mosaic dataset is created and statistics are calculated using a script, they will not show until you restart ArcMap. You may want to follow up with Tech Support on this. Also, you can simplify your script: def calcStatsMOSAIC(t):
arcpy.env.workspace = ws_output
mosaic_name = "ConcMosaic" + str(t)
arcpy.CalculateStatistics_management(mosaic_name, 1, 1) Try the following: 1. Create your mosaic dataset 2. Run the script 3. Restart ArcMap 4. Add the mosaic dataset to ArcMap and see if you 'Classified' for a symbology type Thanks for your input, Jake, I ran the script/.py from PythonWin and from a Toolbox Script, both have the same result even after restarting ArcMap. Also, I appreciate the simplification suggestion. I need to iterate over raster datasets as shown because there are both mosaic's and individual rasters, which I just need to acquire the mosaic to calc the statistics.
... View more
01-02-2014
08:48 AM
|
0
|
0
|
1381
|
|
POST
|
#set the mosaic dataset ws_mosaic = r'C:\MyFolder\MyGDB.gdb\MosaicDS' # add the date field arcpy.AddField_management (ws_mosaic, "_calcDate", "DATE") print "Date field added" # calcuate the date field ras = str(ws_mosaic) fld = "_calcDate" cursor = arcpy.UpdateCursor(ras, '', '', '', 'Name') # in this case, the actual date to start from was not important startDate = datetime.datetime(1901,1,1) step = datetime.timedelta(days=1) d = startDate # now populate the date field for row in cursor: retVal = datetime.datetime.strptime(str(d), '%Y-%m-%d %H:%M:%S') row.setValue(fld, retVal) cursor.updateRow(row) d += step
... View more
12-20-2013
03:44 AM
|
0
|
0
|
1374
|
|
POST
|
Check all of your string references. This will likely fail:
DS3 = "C:\GIS\DS.gdb"
Change it to:
DS3 = r'C:\GIS\DS.gdb'
... View more
12-16-2013
08:51 AM
|
0
|
0
|
3680
|
|
POST
|
I am attempting to calculate statistics on mosaic datasets in a FGDB. It appears to work correctly however it runs and I add the mosaic to the TOC and access the symbology properties of the Mosaic dataset, it does not allow for Classified type (only Stretched and Discrete color are available). I am expecting to be able to apply a classified renderer on the mosaic, which it works as expected if I manually run the Calculate Statistics from the "Enhance" menu (by right clicking on the mosaic in the catalog tree and accessing this menu option there). Is there any reason why I can access the classified symbol property after running calculate stat from the Enhance menu, but not from the code below? Thanks, j
def calcStatsMOSAIC(t):
try:
arcpy.env.workspace = ws_output
bndy_mosaic = str(ws_output) + "\\rasext" + str(t)
mosaic_name = "ConcMosaic" + str(t)
ws_mosaic = str(ws_output) + "\\" + str(mosaic_name)
tr = "*Mosaic*"
rasters = arcpy.ListDatasets(tr)
for r in rasters:
##CALC STATISTICS
arcpy.CalculateStatistics_management(ws_mosaic, 1, 1, "#", "OVERWRITE", bndy_mosaic)
... View more
12-16-2013
04:28 AM
|
0
|
4
|
1615
|
|
POST
|
James, tested this code :
# test sa.sample
import sys, os, arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
InputFGDB = "c:/Data/ESRI-SA/ArcForums/TestData.gdb"
env.workspace = InputFGDB
RasList = arcpy.ListRasters()
print RasList
inPnts = "SamplePnts"
outTab = "in_memory/sampTbl"
Sample(RasList, inPnts, outTab, "NEAREST")
env.workspace = "in_memory"
tbl = arcpy.ListTables()[0]
recs = arcpy.GetCount_management(tbl).getOutput(0)
print "Table {} records {}".format(tbl, recs)
listFields = arcpy.ListFields(tbl)
for f in listFields:
print f.name
which gave me this....
>>>
[u'IP_bi', u'RES_bi']
Table sampTbl records 200
OBJECTID
SamplePnts
X
Y
IP_bi
RES_bi
>>>
So no errors on my side. No answer for you, sorry. Cheers, Neil Well now that is just entirely frustrating. I copied your simple setup/code, replacing the sources and get the same error I was before. ArcGIS 10.1 SP1 (Build 3143) Citrix Deployment Also, I ran this from PythonWin as well as a source script executed from a Toolbox. Thanks again!
... View more
12-12-2013
02:02 AM
|
0
|
0
|
1829
|
|
POST
|
Sample is a really old tool that dates back to ArcInfo Workstation GRID. Have you tried Extract Values To Points or Extract Multi-Values To Points instead? My guess is the newer tools may play nicer with the in_memory workspace. I tend to reserve the in_memory workspace for things that I know will be very small datasets, to make sure I don't bollux up my RAM if I am not successful in cleaning up scratch data. With the new scratchGDB environment (guaranteed writable scratch location) it's a lot easier to implement scratch files on disk, and file GDB is pretty fast. Thanks for the input, Curtis. Actually, I started this implementation using arcpy.gp.ExtractValuesToTable_ga() but that meant processing individual rasters at a time. So, I looked at the arcpy.sa.Sample() method to allow me to pass in the entire set of rasters in the hopes of gaining some performance --- and I did! It takes approx 1/2 the time to process which is huge gains. So... I hoped to use the in_memory space for even more performance. Since the output of this is a table, I wasn't completely worried about filling up the RAM --- I make sure to remove intermediate results/outputs as quickly as possible. That output converts quickly to a numpy array (arcpy.da.TableToNumPyArray) for additional processing. My experience with in_memory has been good and I tend to look for opportunities to use it as much as I can BUT now you are making me question that if you worry about unsuccessful cleanup! Anyway -- I will try the other methods you mention.
... View more
12-11-2013
10:22 AM
|
0
|
0
|
1829
|
|
POST
|
Thanks for the reply, Neil. That was an oversight on my part in my haste to post up the problem code. It definitely appears that the output of sa.Sample cannot be set to the in_memory space --- can you or anyone confirm this? All of these fail with the same ERROR 999999:
elevrasname = "tabElev"
ws_inmem = "in_memory"
outelevtab = ws_inmem + "\\" + elevrasname
arcpy.sa.Sample(rasters, transect_in, outelevtab)
outelevtab = "in_memory\\tabElev"
arcpy.sa.Sample(rasters, transect_in, outelevtab)
outelevtab = r'in_memory\tabElev'
arcpy.sa.Sample(rasters, transect_in, outelevtab)
arcpy.sa.Sample(rasters, transect_in, "in_memory\\tabElev")
Thanks for the os.path.join idea. I will get that into my py lexicon more! Unfortunately it has the same error 999999:
elevrasname = "tabElev"
ws_inmem = "in_memory"
outelevtab = os.path.join(ws_inmem, elevrasname)
arcpy.sa.Sample(rasters, transect_in, outelevtab)
This succeeds:
elevrasname = "tabElev"
ws_output = r'\\NetworkPath\GDB\Conc.gdb'
outelevtab = ws_output + "\\" + elevrasname
arcpy.sa.Sample(rasters, transect_in, outelevtab)
... View more
12-11-2013
02:07 AM
|
0
|
0
|
1829
|
|
POST
|
Devloping an implementation that will build a GDB table from the raster cell values of a series of input raster datasets using the sa.Sample(). It works exactly as intended when I specify the output table to a File Geodatabase on disk but it fails if I try to write this table to the in_memory space. Please highlight the obvious thing I am missing here. This succeeds if FGDB is on disk:
ws_output = r'\\NetworkPath\GDB\Conc2.gdb'
elevrasname = "tabElev"
outelevtab = ws_output + "\\" + elevrasname
arcpy.sa.Sample(rasters, transect_in, outelevtab)
This fails:
outelevtab = "in_memory"
elevrasname = "tabElev"
outelevtab = ws_output + "\\" + elevrasname
arcpy.sa.Sample(rasters, transect_in, outelevtab)
Fails with: "\\mypath\asc2raster.py", line 700, in extract_raster_values arcpy.sa.Sample(rasters, transect_in, r'in_memory\tabElev') File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py", line 1350, in Sample resampling_type) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Utils.py", line 47, in swapper result = wrapper(*args, **kwargs) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py", line 1344, in wrapper resampling_type) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) ExecuteError: ERROR 999999: Error executing function.
... View more
12-10-2013
08:20 AM
|
0
|
7
|
2254
|
|
POST
|
I know this is an old thread, but can anyone provide an updated status on this "enhancement"? NIM048192 I'm trying to write a python script that copies feature classes and relationships across from one GDB to another. But without access to the KEY fields on the relationship, I can't recreate the relates... Have you reviewed any of these? http://forums.arcgis.com/threads/64318-Detect-Relationship-in-Feature-Class-or-Table http://gis.stackexchange.com/questions/50846/copy-two-datasets-that-particpate-in-the-same-relationship-class http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000015s000000
... View more
11-25-2013
03:10 AM
|
0
|
0
|
3103
|
|
POST
|
Now I have a new problem related to the attribute indexes based on the OBJECTID field. I can't delete any attr. index based on that field. I'm getting an error message. 😕 In fact, I can't add an attribute index based on the OBJECTID field either. :(( Probably this is because the index already exists. Try dropping it first... From http://resources.arcgis.com/en/help/main/10.1/index.html#/Add_Attribute_Index/00170000005z000000/ If an index name already exists, it must be dropped before it can be updated.
... View more
11-21-2013
08:46 AM
|
0
|
0
|
1949
|
| 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
|