|
POST
|
Apologies - I often just write the code out in the forum post without running it! This "should" work: updateRows = gp.UpdateCursor("sfora_2") updateRow = updateRows.Next() while updateRow: newString = "" for word in updateRow.MYFIELD.split(" "): newString = word.capitalize() + " " + newString updateRow.MYFIELD = newString[:-1] updateRows.updaterow(updateRow) #<<< THIS WAS THE MISSING LINE! updateRow = updateRows.Next() del updateRow del updateRows
... View more
01-14-2011
11:04 AM
|
0
|
0
|
1675
|
|
POST
|
Are you using ArcGIS v10 or v9.3? In v10 there is a new raster calculator syntax that I am not up and running with yet. However, even in v10 you can still use the good old MapAlgebra syntax via Python. For example: #EXPAND([Streams_rr2m],10,LIST,1.2) import arcgisscripting gp = arcgisscripting.create(9.3) gp.CheckOutExtension("Spatial") inputGrd = r"C:\temp\input" somaExp = "expand(" + inputGrd + ", 10, 'LIST', 1.2)" outputGrd = r"C:\temp\output" gp.SingleOutputMapAlgebra_sa(somaExp, outputGrd, "") #INT([Ran_Ras] * 10) + 1 import arcgisscripting gp = arcgisscripting.create(9.3) gp.CheckOutExtension("Spatial") inputGrd = r"C:\temp\input" somaExp = "int(" + inputGrd + " * 10 + 1)" outputGrd = r"C:\temp\output" gp.SingleOutputMapAlgebra_sa(somaExp, outputGrd, "") #[Angles] * 57.296 import arcgisscripting gp = arcgisscripting.create(9.3) gp.CheckOutExtension("Spatial") inputGrd = r"C:\temp\input" somaExp = inputGrd + " * 57.296" outputGrd = r"C:\temp\output" gp.SingleOutputMapAlgebra_sa(somaExp, outputGrd, "")
... View more
01-14-2011
09:18 AM
|
0
|
0
|
3669
|
|
POST
|
How many rasters are you processing? Does it always crash on the same raster? And if so, what sets that raster apart from the others that successfully finish? What is that raster's order number (example: is it the 255th in the list?). Some comments on your code: 1. Just check out the SA license once at the top, you code could? be checking out a license on every loop. 2. I see that you are twice resetting the gp.workspace in the loop, however your input raster and output raster BOTH use gp.workspace variable. you really only need to set the gp.workspace when using the gp.list*() commands. Otherwise I would recommend doing something like this: outputDir = r"C:\temp\test" outputRaster = outputDir + "\\rcl_" + rs Another question: Your input files seem to be .tif files with rather long names. Grid format (the naive output of the Spatial Analyst tools) has a name limit of 13 characters. Could it be that you are exceeding the limit using your "rs" variable names?
... View more
01-14-2011
07:29 AM
|
0
|
0
|
1645
|
|
POST
|
Sounds like you need to learn Python... Do you have any specific examples of VBA code you need to convert to Python?
... View more
01-14-2011
07:05 AM
|
0
|
0
|
3669
|
|
POST
|
do i need to start a new thread in flex section? Yes - Your question is more related to Flex syntax/usage than Geoprocessing, and I don't know any Flex!
... View more
01-14-2011
06:53 AM
|
0
|
0
|
3038
|
|
POST
|
Try deleteing the feature layer (the one(s) that reference the shapefile). Use the Delete_managment geoprocessing tool.
... View more
01-13-2011
12:36 PM
|
0
|
0
|
848
|
|
POST
|
Check out: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000m2000000.htm However, since the ZonalStatisticsAsTable tool worked in everything except Flex, that's probably where your problem is... Also, t_t4811\t_t4811? Why is the name duplicated. Could there be a bug?
... View more
01-13-2011
07:06 AM
|
0
|
0
|
3038
|
|
POST
|
Woops.... updateRows = gp.UpdateCursor("sfora_2")
updateRow = updateRows.Next()
while updateRow:
newString = ""
for word in updateRow.MYFIELD.split(" "):
newString = word.capitalize() + " " + newString
updateRow.MYFIELD = newString[:-1]
updateRow = updateRows.Next()
del updateRow
del updateRows
... View more
01-12-2011
12:22 PM
|
0
|
0
|
2499
|
|
POST
|
It would look something like this: updateRows = gp.UpdateCursor("sfora_2")
updateRow = updateRows.Next()
while updateRow:
newString = ""
for word in updateRow.MYFIELD.split(" "):
newString = item.capitalize() + " " + newString
updateRow.MYFIELD = newString[:-1]
updateRow = updateRows.Next()
del updateRow
del updateRows This code would take a field value of "hello world", and trun it into "Hello World". I think I am misunderstanding what you want to do though.... If you have a string "hello world", what do you want it to look like? If you want everything to be upper case (e.g. "HELLO WORLD"), do this: updateRows = gp.UpdateCursor("sfora_2")
updateRow = updateRows.Next()
while updateRow:
updateRow.MYFIELD = updateRow.MYFIELD.upper() #.upper() capitalizes every character
updateRow = updateRows.Next()
del updateRow
del updateRows
... View more
01-12-2011
11:15 AM
|
0
|
0
|
2499
|
|
POST
|
Does your zonal raster have a "raster attribute table" (aka a .vat file)? The zonal statistics tool requires one, else the tool will bomb. Use the BuildRasterAttributeTable to make one if need be.
... View more
01-11-2011
09:41 AM
|
0
|
0
|
3038
|
|
POST
|
You might want to use the Clip_management tool (clips rasters w/ option to use a polygons). Note this is different from the Clip_analysis tool which is for vectors. If your charts are in a color mapped multiband image format (.tif, .jpg, etc), you will find that the the Clip_management tool is much easier to deal with. Also, be sure to use the "gp.snapraster" environment setting to ensure that the output rasters have the same cell alignment as the input rasters. So it might look something like this: import sys, string, os, arcgisscripting
gp = arcgisscripting.create()
try:
gp.CheckOutExtension("spatial")
gp.AddToolbox("C:/Arquivos de programas/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")
gp.workspace = "E:/GIS_Mestrado/Corumbatai/3_Cartas_um_metro"
out_workspace = "E:/GIS_Mestrado/Corumbatai/4_Cartas_Con/"
mascara = "E:/GIS_Mestrado/Corumbatai/Geodados/Grid_Cartas_sem_Grade.shp"
rasters = gp.ListRasters()
raster = rasters.next()
while raster:
gp.extent = gp.describe(raster).extent
gp.snapraster = raster
output = out_workspace + raster + ".tif" #reformat as a .tif or whatever - it's that easy!
gp.Clip_management(raster, gp.extent, output, mascara, "", "CLIPPINGGEOMETRY")
gp.extent = "" #clear the extent
raster = rasters.next()
except:
print "Error in script"
print gp.GetMessages()
... View more
01-11-2011
08:42 AM
|
0
|
0
|
1676
|
|
POST
|
You might want to use the Clip_management tool (clips rasters w/ option to use a polygons). Note this is different from the Clip_analysis tool which is for vectors. If your charts are in a color mapped multiband image format (.tif, .jpg, etc), you will find that the the Clip_management tool is much easier to deal with. Also, be sure to use the "gp.snapraster" environment setting to ensure that the output rasters have the same cell alignment as the input rasters. So it might look something like this: import sys, string, os, arcgisscripting gp = arcgisscripting.create() try: gp.CheckOutExtension("spatial") gp.AddToolbox("C:/Arquivos de programas/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") gp.workspace = "E:/GIS_Mestrado/Corumbatai/3_Cartas_um_metro" out_workspace = "E:/GIS_Mestrado/Corumbatai/4_Cartas_Con/" mascara = "E:/GIS_Mestrado/Corumbatai/Geodados/Grid_Cartas_sem_Grade.shp" rasters = gp.ListRasters() raster = rasters.next() while raster: gp.extent = gp.describe(raster).extent gp.snapraster = raster output = out_workspace + raster + ".tif" #reformat as a .tif or whatever - it's that easy! gp.Clip_management(raster, gp.extent, output, mascara, "", "CLIPPINGGEOMETRY") gp.extent = "" #clear the extent raster = rasters.next() except: print "Error in script" print gp.GetMessages().
... View more
01-11-2011
08:41 AM
|
0
|
0
|
1676
|
|
POST
|
You should also just be able to use this: for dat in datelst:
arcpy.SelectLayerByAttribute_management ("hotspots", "NEW_SELECTION", "date = '" + dat + "'") In arcpy (and also when using gp = arcgisscripting.create(9.3)), you shouldn't need to use the "\" things in SQL expresions anymore. I think your original problem was that you had single quotes ('MY_FIELD') arount your field name, and you don't need to.
... View more
01-06-2011
03:19 PM
|
0
|
0
|
2032
|
|
POST
|
This forum hit the ~100 thread and ~400 post milestone as of today. With an average of 4 posts per thread the Python forum is one of the highest post/thread ratios of all the forum topics (which is a good thing I think). I'd call it a success. Thanks Jim.
... View more
01-06-2011
02:25 PM
|
0
|
0
|
3171
|
|
POST
|
A "session" is however long the .exe (python.exe, ArcMap.exe, whatever.exe) runs... That is, unless you exlicitly delete an in_memory featureclass using the gp.Delete_managment() tool, it will persist until you close the application that created the in_memory featureclass. Usually I just use the same name/variable for the in_memory featureclass (inMemFC = "in_memory\\overwrite_me") and the "gp.overwriteoutput = True" setting so that in a loop I just overwrite the in_memory layer from the previous loop. If you don't choose to overwrite the in_memory featureclass, at least be sure to delete the old one(s) before the end of the loop. If you don't, and you have a lot of loops/data, you can easily fill up your RAM. Feature layers can be overwritten as well (they are just references to data on disk - or datasets in the in_memory workspace). I found that in v9.3 at least, a feature layer will persist a lock on the source FC and prevent you from deleting the FGDB that contains the source dataset that the feature layer references. Delete the feature layer, and then you can delete the FGDB.
... View more
01-06-2011
01:44 PM
|
0
|
0
|
1946
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-25-2014 12:57 PM | |
| 1 | 08-29-2024 08:23 AM | |
| 1 | 08-29-2024 08:21 AM | |
| 1 | 02-13-2012 09:06 AM | |
| 2 | 10-05-2010 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
08-30-2024
12:25 AM
|