|
POST
|
Or...
List = [value1, value2, value3, value4]
matches = [s for s in List if len(s)==5]
for m in matches:
print m
... View more
06-03-2014
10:02 AM
|
0
|
0
|
1745
|
|
POST
|
Not sure if this is a good idea, but to possibly fix your immediate issue you can try to change this: import os, sys, random, arcgisscripting To this: import os, sys, random, arcgisscripting as gp
... View more
06-03-2014
03:53 AM
|
0
|
0
|
2372
|
|
POST
|
class Timer:
def __enter__(self):
self.start = time.clock()
return self
def __exit__(self, *args):
self.end = time.clock()
self.interval = self.end - self.start
import arcpy
t = Timer()
with t:
#list the things in the workspace
ws_output = r'in_memory'
for fc in arcpy.ListFeatureClasses():
print fc
itemsecs = "Total processing seconds: %.02f secs." % (t.interval)
print itemsecs
... View more
05-30-2014
12:30 PM
|
1
|
0
|
1955
|
|
POST
|
Sounds like the newrastername already exists in the GDB? Something was going on in the .gdb I guess, it was weird. After a quick restart the arcpy.Rename_management seems to work. This def looks like a really useful method!
... View more
05-29-2014
07:32 AM
|
0
|
0
|
1353
|
|
POST
|
If you're importing os anyway, you can also use os.rename() rather than copying the raster. Rest is what James & Adam wrote about getting the name correctly. os.rename() failed on a GDB raster. But I also tried arcpy.Rename_management(ras, newrastername) but it failed with a "table already exists" error.
... View more
05-29-2014
07:19 AM
|
0
|
0
|
1353
|
|
POST
|
The answers above don't take case into account, which is the variation that you mentioned. Good catch, although I didn't get that from the OP. But yep case will need to be handled if it is important to the implementation. One minor change could be made using:
if ras.endswith("_pa") or ras.endswith("_PA"):
... View more
05-29-2014
07:13 AM
|
0
|
0
|
1393
|
|
POST
|
Thanks for the reply! What if the file name is not consistent? For example, one raster in the geodatabase is called York_pa and another is Harrisburg_PA, and I want the command to take care of all file names with _pa as the last 3 characters? Thanks, That's what this does in my solution I provided: arcpy.ListRasters("*_pa") Edit: if you must absolutely ensure that the last 3 characters are evaluated, then you could use the .endswith property. Here's a modified version of my OP: for ras in arcpy.ListRasters(): if ras.endswith("_pa"): basename = ras.split("_pa")[0] newrastername = "pa_" + basename arcpy.CopyRaster_management(ras, newrastername)
... View more
05-29-2014
06:22 AM
|
0
|
2
|
4917
|
|
POST
|
This should get you pretty close to what you need I think.
import arcpy
import os
dir = r'H:\Documents\ArcGIS\Default.gdb'
arcpy.env.workspace = dir
for ras in arcpy.ListRasters("*_pa"):
print ras #original raster name
basename = ras.split("_pa")[0] #strip _pa from original raster name
newrastername = "PA_" + basename
print newrastername
arcpy.CopyRaster_management(ras, newrastername) #create a new raster with the new/updated name
... View more
05-29-2014
06:15 AM
|
0
|
0
|
4917
|
|
POST
|
Hi, I have scripted a process to read a CSV file into a file geodatabase. Then, I want to read this imported file and work on it by adding new fields and calculating values. However, while using the arcpy.ListTables() on the geodatabase does not list the table. I am just confused what is wrong. Any help !! Here is my script-------------------------
outLocation = dbLoc+'\\'+ out_name +'.gdb'
arcpy.env.workspace = where_tables_are # the folder where your tables are
# Make list of all tables in workspace
tables = arcpy.ListTables("GDB*")
print tables
try:
for tb in tables:
# Execute TableToGeodatabase
print "Importing "+tb+ " to gdb: " + outLocation
arcpy.TableToGeodatabase_conversion(tables, outLocation)
env.workspace = os.path.dirname(os.path.dirname(__file__))+'\\'+ out_name +'.gdb'
arcpy.RefreshCatalog(env.workspace)
inTables = arcpy.ListTables() This should work:
import arcpy
import os
inWS = r'H:\Documents' #the directory that contains the .csv files
outGDB = r'H:\Documents\ArcGIS\Default.gdb' #the output Geodatabase
arcpy.env.workspace = inWS
csvlist = arcpy.ListFiles('*.csv')
print csvlist
for csvfile in csvlist:
csvname = os.path.splitext(csvfile)[0]
print "converting " + str(csvname)
arcpy.TableToTable_conversion(csvfile, outGDB, csvname + '_tab')
Edit: To list the imported tables you just need to set the correct workspace
arcpy.env.workspace = outGDB
tables = arcpy.ListTables("*_tab")
for table in tables:
print table
#do the rest of the work here
... View more
05-28-2014
04:30 AM
|
0
|
0
|
635
|
|
POST
|
I used to get this issue quite often (I've now moved to PyScripter and haven't had this issue since). The following always works for me. Highlight the "infected area" > right click > choose Source Code > then click Untabify Region. Works every time for me. No idea what causes this, but it happened dozens of times over the years, while using many different PythonWin versions. Will do. Thanks. Now I am seeing another new thing! What in the world is this white circle next to one of my def()'s? [ATTACH=CONFIG]34040[/ATTACH]
... View more
05-23-2014
06:48 AM
|
0
|
0
|
3082
|
|
POST
|
I think it's an inconsistent indentation error. There are 11 red symbols. You are likely using 4 spaces as an indentation, meaning you should have 12 spaces for 4 levels of indentation. Try adding one space and see if that solves it. No adding a space does not fix it. I've never seen this kind of checking before in my PythonWin environment. Normally if I had an indentation issue it wouldn't check and I would see an error in the status at the bottom, no red lines or some such thing. It's really strange an dI don't know what has changed to have this show up [ATTACH=CONFIG]34038[/ATTACH] Now when I click the Check it displays a "Checking module..." message at the bottom and the Interactive Window shows [ATTACH=CONFIG]34037[/ATTACH] >>> The tab nanny complained, but I cant see where! This is a Citrix install, so did something happen to the environment settings?
... View more
05-23-2014
06:12 AM
|
0
|
0
|
3082
|
|
POST
|
What in my PythonWin settings is causing the line formatting/error/warnings like seen in the attached image? [ATTACH=CONFIG]34035[/ATTACH] This is really frustrating as I don't know what changed to cause this. Thanks for any input.
... View more
05-23-2014
05:56 AM
|
0
|
5
|
5019
|
|
POST
|
My mistake, I read it as MS Excel...instead of MS Access. I haven't implemented it, but there is always the pyodbc library to grab the table(s)!
... View more
05-22-2014
09:41 AM
|
0
|
0
|
2526
|
|
POST
|
get a table from MS ACCESS: http://resources.arcgis.com/en/help/main/10.2/index.html#//001200000027000000 There is no direct way to reference an MS Access Table to run thru the TableToTable_conversion method (I didn't notice it in the doc). Well, at least it didn't work for me just now -- I wonder if this has to do with 64bit and Access Drivers related issues? Anyway, I get a 000732: Input Rows not supported error. Or maybe I am simply not understanding the method and incorrectly applying it below.
intab = r'C:\TestAccessDB\Testdb.mdb\TestTable'
wsout = r'H:\Documents\ArcGIS\Default.gdb'
arcpy.TableToTable_conversion(intab, wsout, "WindOUT")
... View more
05-22-2014
08:41 AM
|
0
|
0
|
2526
|
|
POST
|
If the ObjectID list is crazy huge you may need to chunk it into selection groups with the modulus operator so that the SQL where clause is not excessively large. Then query that group back to a separate layer copy of the input selection layer. The layer copy would be created outside of your loop using the Make Feature Layer operation. This could certainly throw a wrench into the "IN" statement approach --- is there any issues with chunk processing part? One potential alternative idea is to use a Table Variable instead. If the list of OID's is really large you could first run an insert into the table variable then simply JOIN this to the table in your main query. This design approach would be best fit into a StoredProcedure rather than dynamic SQL though (not a bad plan either as the SQL statement will have already been compiled on the server).
... View more
05-22-2014
07:03 AM
|
0
|
0
|
2790
|
| 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
|