|
POST
|
Did you try: mxd = arcpy.mapping.MapDocument(r"C:\GIS\testfile.mxd") The r before the quoted text of the file name will cause Python to interpret the string as raw text. Otherwise, it would see the \t as an escaped tab character.
... View more
07-03-2019
09:30 AM
|
0
|
3
|
2648
|
|
POST
|
You might try something like: from datetime import datetime
dt = datetime.strptime('6/1/2019', '%m/%d/%Y')
tt = dt.timetuple()
print "{}-{}".format(tt.tm_yday, tt.tm_year)
# prints: 152-2019 See also: Extract day of year and Julian day from a string date
... View more
07-01-2019
01:42 PM
|
1
|
9
|
6866
|
|
POST
|
Looks like you are trying to accomplish what Richard Fairhurst is describing in his blog: Turbo Charging Data Manipulation with Python Cursors and Dictionaries. See his code for Example 1.
... View more
06-28-2019
09:30 AM
|
3
|
1
|
4907
|
|
POST
|
With only a quick look, I see you are sometimes using "dataset1/" + ... and sometimes not using it. I wonder if the inconsistency is the issue. You might try: arcpy.CopyFeatures_management (flayer, "dataset1/" + blockname + "_export")
arcpy.Dissolve_management ("dataset1/" + blockname + "_export", "dataset1/" + blockname + "_dissolve")
arcpy.AddGeometryAttributes_management("dataset1/" + blockname + "_dissolve", "AREA", Area_Unit="SQUARE_KILOMETERS")
... View more
06-14-2019
02:41 PM
|
0
|
0
|
2474
|
|
POST
|
Can you share a bit more of your script - specifically, where the layer name is being set?
... View more
06-14-2019
11:37 AM
|
0
|
0
|
2474
|
|
POST
|
Assuming you are trying to determine if any value/row in any of the fields are NULL you can try something like: import arcpy
inFeature = r'C:\path\to\file.gdb\SCRIPT_PARAMETER_TEST' # path to feature
fields = ['Prov', 'Rd_symbol', 'Name_type' ]
# create where_clause
wc = []
for f in fields:
wc.append('{} IS NULL'.format(f)) # search for null fields
where_clause = ' OR '.join(wc) # join to make OR statement
print where_clause # print where clause for test
# Prints: 'Prov IS NULL OR Rd_symbol IS NULL OR Name_type IS NULL'
rows = [row for row in arcpy.da.SearchCursor(inFeature, fields, where_clause)]
if len(rows): # if len(rows) > 0
print('{} has null values'.format(inFeature))
else:
print('{} does not have null values'.format(inFeature)) # but may also be empty feature
del rows You could also use Select Layer By Attribute and Get Count in place of the search cursor (lines 14+).
... View more
06-08-2019
08:24 PM
|
1
|
0
|
777
|
|
POST
|
Here are a couple of scripts that I have used. This one reads the domain information: import arcpy
dbName = r"C:\path\to\file.gdb" # your geodatabase path
print dbName
print
domains = arcpy.da.ListDomains(dbName)
for domain in domains:
print
print('Domain name: {0}'.format(domain.name))
if domain.domainType == 'CodedValue':
coded_values = domain.codedValues
for val, desc in sorted(coded_values.iteritems()):
print('{0} : {1}'.format(val, desc))
elif domain.domainType == 'Range':
print('Min: {0}'.format(domain.range[0]))
print('Max: {0}'.format(domain.range[1])) This one reads the field information. Note specifically the field.domain property. import arcpy
from arcpy import env
# Set the current workspace
env.workspace = r"C:\path\to\file.gdb" # your geodatabase path
print env.workspace
print
# Get the list of standalone tables in the geodatabase
#
tableList = arcpy.ListFeatureClasses() # for features
# tableList = arcpy.ListTables() # for tables
print tableList
for table in tableList:
print
print table
dbTable = env.workspace + "\\" + table
fieldList = arcpy.ListFields(dbTable)
print '\t['
for field in fieldList:
# print("\t{0} is a type of {1} with a length of {2}"
# .format(field.name, field.type, field.length))
# Print field properties
#
# print("Name: {0}".format(field.name))
# print("\tBaseName: {0}".format(field.baseName))
# print("\tAlias: {0}".format(field.aliasName))
# print("\tLength: {0}".format(field.length))
# print("\tDomain: {0}".format(field.domain))
# print("\tType: {0}".format(field.type))
# print("\tIs Editable: {0}".format(field.editable))
# print("\tIs Nullable: {0}".format(field.isNullable))
# print("\tRequired: {0}".format(field.required))
# print("\tScale: {0}".format(field.scale))
# print("\tPrecision: {0}".format(field.precision))
print '\t["' + field.name + '",',
if (field.type == "String"):
print '"TEXT", ',
print '"' + str(field.length) + '",',
else:
print ("\"{0}\", ".format(field.type).upper()),
print '"#",',
print '"' + field.aliasName + '",',
if len(field.domain):
print '"' + field.domain + '"],',
else:
print '"#",',
print '"#"],' # Default
print '\t]'
# Fields: [ 0:Name, 1:Type, 2:Size, 3:Alias, 4:Domain 5:Default ] use "#" for blanks
# Field type is returned as:
# SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, Blob See also: ListDomains ListFeatureClasses ListFields
... View more
06-07-2019
09:28 AM
|
0
|
0
|
1209
|
|
POST
|
The quoting of your where clause is incorrect. Try: # if field_name is the name of the field:
where_clause = "field_name is NULL"
# if field_name is a variable containing a field name:
field_name = 'myFieldName' # the name of the field
where_clause = "{} is NULL".format(field_name) That said, I'm not sure if you want to indicate if a feature contains any field where there is a null, or if you want to find rows in the feature that has a field with a null value. See this thread for some additional ideas: Calculate number of NULL values in a feature dataset.
... View more
06-06-2019
02:26 PM
|
2
|
0
|
6884
|
|
POST
|
We may be in agreement, but to be clear, "<Null>" is not a six-character string or the description of a coded value. It is the file geodatabase's representation that a null value is in the field. When it appears in a drop-down list, like a display of a database table in edit mode or an application like Collector, when "<Null>" is selected, a null value will be placed in the field.
... View more
06-04-2019
09:14 AM
|
0
|
3
|
4060
|
|
POST
|
I don't think it is possible to have a coded value domain where the "code" is None/Null. To have an option of "<Null>" show up in the domain selections (where the actual code stored is a NULL value), you need to set the field using the domain to "Allow NULL Values". Typically, I set the default value of my fields using domains to use a code like "?" or "NA". These would then display a description of "None", "Missing" or a prompt to "Make a selection". I would then set allow null values to "No". I would set any fields with a null to this default value. Hope this helps.
... View more
06-03-2019
08:40 PM
|
1
|
5
|
4060
|
|
POST
|
It appears that you are using a Python toolbox script (.pyt file) and including GetParametersAsText which works with custom Python script tool. Comparing custom and Python toolboxes might help clarify some of the differences. Here is your script with the formatting that Dan Patterson is suggesting: import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Test_tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(
displayName="Input workspace",
name="workspace",
datatype="DEWorkspace",
parameterType="Required",
direction="Input")
param1 = arcpy.Parameter(
displayName="Input classified raster",
name="input_raster",
datatype="GPRasterLayer",
parameterType="Required",
direction="Input")
param2 = arcpy.Parameter(
displayName="Input features",
name="input_features",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
params = [param0, param1, param2]
return params
def execute(self, parameters, messages):
"""The source code of the tool."""
# Define some paths/variables
outWorkspace = arcpy.GetParameterAsText(0)
arcpy.env.workspace = outWorkspace
input_raster = arcpy.GetParameterAsText(1)
input_features = arcpy.GetParameterAsText(2)
output_features = outWorkspace + "\\projected.shp"
out_coordinate_system = arcpy.Describe(input_raster).spatialReference
proj_grid = arcpy.Project_management(input_features, output_features, out_coordinate_system)
return
Since the parameters are defined inside the Python toolbox script (lines 21-45) versus a "wizard" with the custom script, you don't need the GetParameters as text in lines 51-54. Try replacing lines 47 to the end with: def execute(self, parameters, messages):
"""The source code of the tool."""
# Define some paths/variables
outWorkspace = parameters[0].valueAsText
arcpy.env.workspace = outWorkspace
input_raster = parameters[1].valueAsText
input_features = parameters[2].valueAsText
output_features = outWorkspace + "\\projected.shp"
out_coordinate_system = arcpy.Describe(input_raster).spatialReference
proj_grid = arcpy.Project_management(input_features, output_features, out_coordinate_system)
return
Hope this helps.
... View more
05-29-2019
10:08 AM
|
1
|
1
|
3797
|
|
POST
|
Since you are making a URL request, it needs to be URL encoded. You might try: https://services.dat.noaa.gov/arcgis/rest/services/nws_damageassessmenttoolkit/DamageViewer/MapServer/export?bbox=-11767633.378559455,5058296.783799826,-9001224.450862357,3957603.5764932865&size=1131,450&dpi=96&format=png24&transparent=true&bboxSR=3857&imageSR=3857&layers=show:0&f=image&dynamicLayers=%5B%7B%22source%22%3A%7B%22type%22%3A%22mapLayer%22%2C%22mapLayerId%22%3A0%7D%2C%22definitionExpression%22%3A%22stormdate%20%3E%20DATE%20%272019-01-01%27%22%7D%5D See: HTML URL Encoding Reference and urlencoder.org
... View more
05-28-2019
10:24 AM
|
0
|
1
|
1612
|
|
POST
|
See AddField. I usually have the field name, type, alias, and other properties in a list. For multiple fields, I would then have a list of lists to loop through. In a very rough form, something like: fields = [
['fldName', 'TEXT', '50', 'fldAlias', .... other properties ],
['fldName2', 'TEXT', '50', 'fldAlias2', .... other properties ]
]
for fld in fields:
arcpy.AddField_management(dbFeature,fld[0],fld[1],"#","#",
fld[2],fld[3],nullable,"NON_REQUIRED", ...etc...)
... View more
05-23-2019
03:06 PM
|
0
|
0
|
901
|
|
POST
|
You might try adding the following line just after CalculateField - at line 141. GetMessages will return messages from the CalculateField tool (i.e., the tool last used) and you can see if it ran successfully. arcpy.AddMessage(arcpy.GetMessages())
... View more
05-16-2019
02:08 PM
|
0
|
2
|
2766
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|