|
POST
|
Is the "IS NULL" being passed with quotes? That will break an IS NULL query. Maybe something like this:
import arcpy
field = "RMS"
sql = "{0}".format(arcpy.AddFieldDelimiters(fc,field)) + " IS NULL"
cursor = arcpy.da.UpdateCursor(fc, field, sql)
for row in cursor:
row[0] = ""
cursor.updateRow(row)
del row, cursor.
R_
... View more
07-30-2013
09:02 AM
|
0
|
0
|
1915
|
|
POST
|
OIC, it's not actually running and generating that string, it is merely printing what you assigned it to. Did you try any of the changes I posted above, they are working for me just fine. I did notice that you have quite a few errors in your script, and, without the error reporting, it just errors out and doesn't tell you why. The code in my other post is working correctly, it is the "other" errors in your script that is throwing the exceptions. Notice the print statements, best to get away from using "+" in print statements as you were trying to concatenate (that's what the plus sign means) a number and a string. Gives an error, but without it reporting the error, just says Problem executing SQL. Use commas in print statements and you wont run into this problem. No need to iterate through a list of SQL statements as you are "splitting" your string by ";" as there are no semicolons in your string, so you end up with an empty list. Think you got this code from the example which is showing how to deal with the getParametersAsText() when passing from a script tool. In this case, if allow multiple inputs, they would come across as a semicolon separated string that would be parsed to the list. In this case, you are defining your "single" sql statement. Try this code, it is working. If it doesn't work for you, I'd suggest grabbing the snippet from the bottom of my earlier post and have it print the fields for you, and make sure fields in the SQL statement are correct (check CasE also, as that may sometimes matter). Anyway, cleaned out some of the error issues and the loop. Try this, get it to work, then add all the "other" stuff in there after it is working correctly. R_
import arcpy
from arcpy import *
import sys
arcpy.env.workspace = (r"c:\connectionFiles\conntop10sig.sde")
try:
SQLStatement = ("select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.ABCBNIVL.TYPECBN = 3")
sdeConn = arcpy.ArcSDESQLExecute(r"c:\connectionFiles\conntop10sig.sde") # vital part you are missing....
print "Execute SQL Statement: ", SQLStatement
try:
# Pass the SQL statement to the database.
#
print "connecting to dba"
sdeReturn = sdeConn.execute(SQLStatement)
print "Number of rows returned by query: ", len(sdeReturn)
except Exception, ErrorDesc:
print "ErrorDesc",ErrorDesc ## added this to actually print what the error is
sdeReturn = False
# If the return value is a list (a list of lists), display each list as a row from the
# table being queried.
if isinstance(sdeReturn, list):
print "Number of rows returned by query: ", len(sdeReturn), "rows"
for row in sdeReturn:
print "row"
print "\n"
else:
# If the return value was not a list, the statement was most likely a DDL statment.
# Check its status.
if sdeReturn == True:
print "SQL statement: ", SQLStatement , " ran sucessfully."
print "\n"
else:
print "SQL statement: ",SQLStatement ," FAILED."
print "\n"
except:
print "Problem executing SQL."
This should work as long as the workspace.sde connection includes a table named "TOP10_SIG.DBO.ABCBNIVL", and that table has a numeric field named "TYPECBN" R_
... View more
07-30-2013
08:30 AM
|
0
|
0
|
2919
|
|
POST
|
Hi Robert, Have you been having issues with event themes and this widget? I seem to be able to utilize them just fine, even the uniquevaluesfromfield works for me through database connections to Oracle table. It is the only "FC" in the map document/service. R_
... View more
07-29-2013
05:33 PM
|
0
|
0
|
1965
|
|
POST
|
hi rzufelt: the output of : print "Execute SQL Statement: " + sql is Execute SQL Statement: SELECT * FROM TOP10_SIG.dbo.ABCBNIVL WHERE TOP10_SIG.dbo.ABCBNIVL.TYPECBN = 3 This looks like what you "want" your sql to look like, but I can't figure any way you got that from the attached code. Are you running a different snippet than you posted? R_
... View more
07-29-2013
05:24 PM
|
0
|
0
|
2919
|
|
POST
|
hi, i'm trying to execute this SqlStatement to establish an sql query in sql server 2008 with an arcsde connection (arcsde personel use) but there is no result. the sql statement is : Execute SQL Statement: (SELECT * FROM [TOP10_SIG].[dbo].[ABCBNIVL] WHERE [TOP10_SIG].[dbo].[ABCBNIVL].[TYPECBN] = 3) an idea please ! I use ArcGIS 10.0 Arcsde personal use Code:
import arcpy
arcpy.env.workspace = (r"c:\connectionFiles\conntop10sig.sde")
sql= "select * from TOP10_SIG.DBO.ABCBNIVL where TOP10_SIG.DBO.TYPECBN = 3" # don't use the brackets here
# SQLStatementList = SQLStatement.split(";") # this is doing nothing as you end up with empty list.
sdeConn = arcpy.ArcSDESQLExecute(r"c:\connectionFiles\conntop10sig.sde") # need to define your connection
sdeReturn = sdeConn.execute(sql)
print "number records selected ",len(sdeReturn)
for ret in sdeReturn:
print ret
You need to establish the sdeConn connection using the ArcSDESQLExecute(). The above code will select all fields in the table where TYPECBN = 3 (assuming this is a numeric field) as long as the table/field names are correct. Also, need to make sure you have the table names correct. This snippet will give you the list of tables and the proper names for them:
>>> tables = arcpy.ListTables()
>>> for table in tables:
print(table)
R_ More info here, but it looks like you have already extracted "some" snippets from here. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00000021000000
... View more
07-29-2013
05:21 PM
|
0
|
0
|
2919
|
|
POST
|
You didn't say why you want to select (I.e., what is the purpose) these features. Is there some reason you can't just use arcpy.SelectLayerByLocation_management to make the selection? This will select all the features as well as the table attributes. R_ Also, what is the output of this line that you have in there? print "Execute SQL Statement: " + sql
... View more
07-29-2013
12:33 PM
|
0
|
0
|
2919
|
|
POST
|
Note:The Raster Calculator tool is intended for use in the ArcGIS for Desktop application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available in the ArcPy Spatial Analyst module. Note:In Python, Map Algebra expressions should be created and executed with the Spatial Analyst module, which is an extension of the ArcPy Python site package. See Map Algebra in Spatial Analyst to learn about how to perform your analysis in Python. http://resources.arcgis.com/en/help/main/10.1/index.html#//00p600000002000000 R_
... View more
07-29-2013
12:30 PM
|
0
|
0
|
1012
|
|
POST
|
Which would give you the line, then you could use StackProfile_3d to get your profile. R_
... View more
07-29-2013
11:40 AM
|
0
|
0
|
3986
|
|
POST
|
for field in fields:
sql_dict[arcpy.AddFieldDelimiters(lyr, field)] = arcpy.GetParameterAsText(fields.index(field))
# construct where clause
whereClause = ' AND '.join("{0} = '{1}'".format(k,v) for k,v in sql_dict.iteritems())
I had to give you a point for this one. Great example (both syntax and useage) of using a dict AND join... R_
... View more
07-29-2013
10:28 AM
|
0
|
0
|
2160
|
|
POST
|
Dear Experts, I am new to this forum and want your help to solve my problem. I am using ArcGIS 10 and my problem states as: I have a set of 46 monthly rainfall rasters 1. i want to extract the maximum and minimum pixel value from the the stack of 46 raster as MAX and MIN 2. Then using the equation shown in attached figure [ATTACH=CONFIG]25148[/ATTACH] I have to calculate the cumulative probability of each x 3. where x is each individual raster (total 46) 4. I have already calculated the values of "a" also in the form of a raster and would like the program to pick these values from that respective raster. 5. The summation equation should run from n=1 to n=Max repeatedly I would highly appreciate of a python expert who writes a few lines script for me to solve this Should be pretty straight forward. First, I'd use ListRasters to get a list of all your rasters (unless you hard coded them to a list) then iterate through the rasters and using arcpy.GetRasterProperties can get the max and min values Then, plug the info into your equation on each iteration. Since you are working with rasters, and have the "a" values as a raster, I'm guessing you will need to use map algebra for this. http://resources.arcgis.com/en/help/main/10.1/index.html#/What_is_Map_Algebra/00p600000002000000/ R_
... View more
07-29-2013
10:25 AM
|
0
|
0
|
1262
|
|
POST
|
I been looking for the code to convert an excel into a csv? I also look in ArcHelp for code that can convert excel into a xy event but they require csv. So, if I there no way to convert the code to a csv is there a way to make an excell file into a xy event? Do you really need a csv file, or are you just trying to create the xy event theme? As pointed out earlier, you can use the excel sheet as input to the create xy event theme, the do NOT require a csv.
# Import arcpy module
import arcpy
# Local variables:
Sheet1 = "D:\\Book1.xls\\Sheet1$"
Output_Location = "D:\\"
Sheet1Layer = "Sheet1$Layer"
# Process: Make XY Event Layer
arcpy.MakeXYEventLayer_management(Sheet1, "Easting", "Northing", Sheet1Layer, "", "")
This make an even layer just fine using xls as input (docs say xlxs supported also). R_
... View more
07-29-2013
09:47 AM
|
0
|
0
|
4192
|
|
POST
|
da is the set of data access arcpy functions introduced in 10.1. Didn't realize I left that in my import as it is not needed for this script. Normally needed for the new Cursors. As far as a tool, I'm not the one to help with that. I do everything stand alone, but would start here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001500000006000000.htm R_ Figured there was a typo there. Funny, it is the typo you are coding to fix :rolleyes:
... View more
07-29-2013
07:38 AM
|
0
|
0
|
1402
|
|
POST
|
Sure, unfortunalty, you can't just change a field, so basically, it creates a field map, modifies it, then replaces the existing fields with the new "mapped" fields. This one is set to work within all DS's within a FGDB, could easily be modified to only work on one FC, etc.
import arcpy, os
ws = r'D:\update\wch_updated.gdb'
arcpy.env.workspace = ws
datasets = arcpy.ListDatasets()
excludeList = ['Base','OSEGrids','River_Flows','Utilities','Wells','MR']
# Overwrite pre-existing files
arcpy.env.overwriteOutput = True
datasets.append("") # this appends a blank onto the dataset list so it picks up FC's in the base FGDB level.
for ds in datasets:
if ds not in excludeList: # only do this to DS's not in my exclude list
print "working on ",ds
fcs = arcpy.ListFeatureClasses("","",ds)
for fc in fcs:
print "creating field maps"
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(fc)
for field in arcpy.ListFields(fc, "", "String"):
#Find all fields other than type of ObjectId and Geometry
# if (field.type != 'OID') & (field.type != 'Geometry'): # I commented this as my ListFields limits to "String" fields only
#Create a new Field Map Object and populate it
print "populating object for ",fc
fldmap_Changed = arcpy.FieldMap()
fieldName = field.name
fldmap_Changed.addInputField(fc, fieldName)
#Get a new field object from the Field Map Object and set the Allow Null Property to False
print "setting to false"
fld_Changed = fldmap_Changed.outputField
fld_Changed.isNullable = False
#Add the field back to the Field Map Object
fldmap_Changed.outputField = fld_Changed
#Find and replace the current field map in the Field Mappings with the new Field Map Object
print "replacing current field map"
index = fieldmappings.findFieldMapIndex(fieldName)
fieldmappings.replaceFieldMap(index, fldmap_Changed)
del fldmap_Changed, fld_Changed
print "outputting fc ",fc
arcpy.FeatureClassToFeatureClass_conversion(ds + os.sep + fc, arcpy.env.workspace, ds + os.sep + fc + "Copy1", "", fieldmappings)
####
### The script makes a copy in each dataset of the original.
### This section removes the original and renames the copy to the original name
####
for fc in fcs:
if arcpy.Exists(ds + os.sep + fc):
print "deleting ",ds + os.sep + fc
arcpy.Delete_management(ds + os.sep + fc)
print "creating ",fc,"from ",ds + os.sep + fc + "Copy1"
arcpy.FeatureClassToFeatureClass_conversion(ds + os.sep + fc + "Copy1", arcpy.env.workspace, ds + os.sep + fc, "")
arcpy.Delete_management(ds + os.sep + fc + "Copy1")
del fieldmappings
arcpy.Compact_management(ws) # compact FGDB to removed locks and optimize performance
R_
... View more
07-29-2013
07:25 AM
|
0
|
0
|
1837
|
|
POST
|
Well, got to run, so no time to try to explain what I did, but this code is working for me. Goes through every mxd in my folder, if it finds a broken datasource that matches the one I specified, it replaces with the new one in all mxd's in that folder. you should be able to see what is different. I hard coded some of the paths for ease, but you could put back to variables.
import arcpy, os
from arcpy import da
ws = r'D:\test'
workspace = arcpy.env.workspace = ws
arcpy.env.overwriteOutput = True
start = "D:\\test"
for root, dirs, files in os.walk(start):
for mapDoc in files:
if mapDoc.endswith(".mxd"):
path = os.path.abspath(os.path.join(root,mapDoc))
mxd = arcpy.mapping.MapDocument(path)
print "\n" + "Map Document = " + path
df = arcpy.mapping.ListDataFrames(mxd)
for dataframes in df:
print " DATAFRAME = " + dataframes.name + "\n" + "LAYERS: "
# lyrs = arcpy.mapping.ListLayers(dataframes)
# for layers in lyrs:
# print " " + layers.name
for broken in arcpy.mapping.ListBrokenDataSources(dataframes):
if broken.supports("DATASOURCE"):
print broken.name + " source is missing"
print " Original source = " + broken.dataSource
if broken.dataSource == r"D:\esri_data.gdb\WasteSites\WasteSitesLine":
print " Found. Attempting to fix."
broken.replaceDataSource(r'\\mcflight01\MCFlightData\HGIS\Data\WCH.gdb',"FILEGDB_WORKSPACE","WasteSitesLine", False)
mxd.save()
del dataframes
del df
del mxd
# mxd.saveACopy(os.getcwd() + "\\" + mapDoc[:-4] + "_new.mxd")
del mapDoc
I had to make several changes to my data to test this. However, it might be as simple as saving the mxd so that the changes take effect. Could just make that change and see if it works for you first. R_ just noticed this also in your original code:
if broken.dataSource == r"C:\Student\MapScripting10_0\Maps\PlainsView.gdb\East_Timort":
print " Found. Attempting to fix."
osource = r"C:\Student\MapScripting10_0\Maps\PlainsView.gdb"
nsource = "Timor"
Does FC "Timor" actually exist or should it be "Timort"? Or, should it be "East_Timor"
... View more
07-25-2013
05:19 PM
|
0
|
0
|
1402
|
|
POST
|
No worries. Didn't mean to sound snotty or anything. Wasn't sure if you were asking the correct questions, that is why I tried to clarify in my first post. Seems to be the norm to not reply to post that don't seem to "apply", so, from that, I figured that you must be asking for code only solutions. R_
... View more
07-25-2013
04:11 PM
|
0
|
0
|
2403
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-14-2026 04:00 PM | |
| 1 | 09-14-2022 07:53 AM | |
| 1 | 09-14-2022 08:23 AM | |
| 1 | 05-21-2026 08:53 AM | |
| 1 | 05-14-2026 04:28 PM |
| Online Status |
Online
|
| Date Last Visited |
yesterday
|