|
POST
|
I'll take a look. With 6 wells per section at 800 feet spacing, would the buffer be adjusted (if using the current tool under discussion)? Would you prefer points over lines?
... View more
01-11-2019
10:01 AM
|
0
|
1
|
6280
|
|
POST
|
If your geodatabase has both feature classes and feature datasets, I believe you need to deal with each. That is, loop through the datasets and delete feature classes in the dataset and then empty datasets, and follow this by looping through remaining feature classes and deleting the empty ones. import arcpy
arcpy.env.workspace = r'C:\Path\To\file.gdb'
# check empty datasets
for fds in arcpy.ListDatasets('','Feature'):
print "{}".format(fds)
features = 0
for fc in arcpy.ListFeatureClasses('','',fds):
count = int(arcpy.GetCount_management(fc).getOutput(0))
if count:
features += 1
print "\t{}: {} records".format(fc, count)
else:
print "\t{} records, deleting: {}".format(count, fc)
arcpy.Delete_management(fc)
print "{} has {} remaining features".format(fds, features)
if features == 0:
print "{} dataset is empty, deleting".format(fds)
arcpy.Delete_management(fds)
else:
print "{} has {} remaining features".format(fds, features)
# check empty feature classes
for fc in arcpy.ListFeatureClasses():
count = int(arcpy.GetCount_management(fc).getOutput(0))
if count:
features += 1
print "\t{}: {} records".format(fc, count)
else:
print "\t{} records, deleting: {}".format(count, fc)
arcpy.Delete_management(fc)
... View more
01-11-2019
09:40 AM
|
1
|
0
|
3573
|
|
POST
|
Can you supply the code you are having issues with? I haven't been able to duplicate your results. In the meantime, here is an example of a python toolbox that utilizes arcpy.GetMessages(). It is rather simple; it just asks for a feature layer and then uses arcpy.GetCount_management() to print a count of the rows in the feature layer. 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 = "Tool"
self.description = "Get count of items in feature layer"
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
# First parameter
inFeature = arcpy.Parameter(
displayName="Input Features",
name="inFeature",
datatype=["GPFeatureLayer"],
parameterType="Required",
direction="Input")
params = [inFeature]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
inFeature = parameters[0].valueAsText
arcpy.GetCount_management(inFeature)
# last tool used: GetCount
arcpy.AddMessage(arcpy.GetMessages())
return The script will display the following messages (rows 4-7 are from the GetCount tool): Executing: Tool "MyFeature"
Start Time: Thu Jan 10 20:24:08 2019
Running script Tool...
Executing: GetCount "MyFeature"
Start Time: Thu Jan 10 20:24:08 2019
Row Count = 2965
Succeeded at Thu Jan 10 20:24:08 2019 (Elapsed Time: 0.00 seconds)
Completed script Tool...
Succeeded at Thu Jan 10 20:24:08 2019 (Elapsed Time: 0.05 seconds)
If line 50 -- arcpy.AddMessage(arcpy.GetMessages()) -- in the python toolbox is commented out, the following messages are displayed (the output of GetCount_management is suppressed): Executing: Tool "MyFeature"
Start Time: Thu Jan 10 20:26:00 2019
Running script Tool...
Completed script Tool...
Succeeded at Thu Jan 10 20:26:00 2019 (Elapsed Time: 0.05 seconds) Hope this helps.
... View more
01-10-2019
09:40 PM
|
1
|
0
|
3660
|
|
POST
|
Another suggestion for a possible script in the Python section is: Delete Empty Datasets.
... View more
01-10-2019
12:07 PM
|
1
|
5
|
3573
|
|
POST
|
Although I am not running 10.1, I did some experimenting and have the following suggestion: arcpy.mapping.ExportToJPEG(mxd, path_output, "PAGE_LAYOUT",
df_export_width=9360,
df_export_height=6623,
resolution=200,
world_file=False) I am assuming the text element was created in layout view. Referencing "df" in the export would point to the first data frame and not the layout view.
... View more
01-07-2019
07:46 PM
|
0
|
1
|
1397
|
|
POST
|
I tested the script that you linked to and was able to get it to work using desktop 10.5 without making any changes to the code. I set it up as a script tool with parameter 0 as a feature layer for input, parameter 1 as a feature class for output, and parameters 2 and 3 as linear units for input. The code at the bottom of the script references the "CURRENT" map document, so the tool is designed to be run inside ArcMap. The polygon layer should be a layer in the open map. The output feature can be in memory as the example on stackexchange shows, or a new one to be created in an existing geodatabase. As you are indicating errors with the copy features management, I would check that the parameter is set as a feature class for output and that you are using a valid name and location for the feature class. If this feature is being created and is empty, then I would check the line spacing and buffer distance used to make sure the lines will fit inside the polygons. If the buffer is 10 meters, then the polygon should be over 20 meters in width/height to accommodate the lines. If you are still having problems with the code, see Debugging script tools for some ideas and post the error messages.
... View more
01-04-2019
11:52 PM
|
1
|
4
|
6280
|
|
POST
|
I like MySQL's SHOW CREATE TABLE, so I created something similar with arcpy. One script reads the table and prints a list of field information that I can modify as desired and use to create a new feature or table. import arcpy
from arcpy import env
# Set the current workspace
env.workspace = r"C:\Path\To\file.gdb"
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
This script produces something like: businesses
[
["OBJECTID", "OID", "#", "OBJECTID", "#", "#"],
["Business", "TEXT", "50", "Business Name", "#", "#"],
["Address", "TEXT", "50", "Business Address", "#", "#"],
["City", "TEXT", "20", "Business City", "#", "#"],
["Zip", "TEXT", "10", "Business Zip", "#", "#"],
["Phone", "TEXT", "16", "Business Phone", "#", "#"],
["GlobalID", "GLOBALID", "#", "GlobalID", "#", "#"],
["CreationDate", "DATE", "#", "CreationDate", "#", "#"],
["Creator", "TEXT", "50", "Creator", "#", "#"],
["EditDate", "DATE", "#", "EditDate", "#", "#"],
["Editor", "TEXT", "50", "Editor", "#", "#"],
["Shape", "GEOMETRY", "#", "Shape", "#", "#"],
["POINT_X", "DOUBLE", "#", "POINT_X", "#", "#"],
["POINT_Y", "DOUBLE", "#", "POINT_Y", "#", "#"],
] I then modify the list by modifying/removing/adding fields. From there, I recreate an empty table/feature using something like this (this is for a feature so there are some geometry functions added). # Import system modules
import arcpy
from arcpy import env
# name of geodatabase
geoDB = r"C:\Path\To\file.gdb"
# set environment settings
env.workspace = geoDB
def new_feature(dbFeature, dbAttributes, geoDB):
# create the table
print "\nCreating feature: " + dbFeature
# set local variables
geometry_type = "POINT"
template = "#"
has_m = "DISABLED"
has_z = "DISABLED"
# Use SpatialReference to set object reference - system name, projection file or authority code
spatial_reference = arcpy.SpatialReference("WGS 1984 Web Mercator (auxiliary sphere)")
# spatial_reference = arcpy.SpatialReference("WGS 1984")
# Execute CreateFeatureclass
# CreateFeatureclass_management (out_path, out_name, {geometry_type}, {template}, {has_m}, {has_z}, {spatial_reference},
# {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})
arcpy.CreateFeatureclass_management(geoDB, dbFeature, geometry_type, template, has_m, has_z, spatial_reference)
# add the fields
print "Adding attributes: "
for new_field in dbAttributes:
# add new field
print "\t" + new_field[0]
# all fields using domains are non-nullable
if (new_field[4] == "#"):
nullable = "NULLABLE"
else:
nullable = "NON_NULLABLE"
# AddField_management (in_table, field_name, field_type, {field_precision}, {field_scale},
# {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
arcpy.AddField_management(dbFeature,new_field[0],new_field[1],"#","#",
new_field[2],new_field[3],nullable,"NON_REQUIRED",new_field[4])
# assign default value as specified
if ( new_field[5] <> "#" ) :
# AssignDefaultToField_management (in_table, field_name, default_value, {subtype_code})
arcpy.AssignDefaultToField_management(dbFeature,new_field[0],new_field[5],"#")
if __name__ == "__main__":
# Fields: [ 0:Name, 1:Type, 2:Size, 3:Alias, 4:Domain, 5:Default] use "#" for blanks
dbFeature = new_business"
dbAttributes = [
["Business", "TEXT", "50", "Business Name", "#", "#"],
["Address", "TEXT", "50", "Business Address", "#", "#"],
["City", "TEXT", "20", "Business City", "#", "#"],
["Zip", "TEXT", "10", "Business Zip", "#", "#"],
["Phone", "TEXT", "16", "Business Phone", "#", "#"],
["Licensed","TEXT","1","Business Licensed","YN","?"], # added domain choices: ?, Y, N
]
new_feature(dbFeature, dbAttributes, geoDB)
print
print "Processing complete."
This gives you the basic workings of the process. Except for the geometry, creating a data table is similar. You can capture more of the field's properties in the first script to use in the second (field.editable, field.precision, etc.). Hope this helps.
... View more
01-03-2019
10:17 AM
|
2
|
3
|
3927
|
|
POST
|
I don't believe it is possible to open all attribute tables at once. However, if you open the attribute tables and save the map with all tables opened, they will be available when you open the map the next time. Again, this only works if the attribute tables are open when the map is saved. You might make an enhancement suggestion at ArcGIS Ideas.
... View more
12-21-2018
12:12 PM
|
1
|
3
|
4649
|
|
POST
|
Can you provide some additional details of what you want to accomplish? Perhaps you want to loop through every layer in the map and use a search cursor to examine attributes?
... View more
12-20-2018
10:54 PM
|
2
|
6
|
4649
|
|
POST
|
I looked in 10.6 for the CalculateGeometry tool and could not find it. I was wondering if it was new in 10.6.1, but it was not in the listed enhancements. The documentation may be incorrect, perhaps just ported over from Pro. The license level info, normally at the bottom of the page, was missing as well. Pro indicated the tool was available at all levels.
... View more
12-20-2018
10:04 PM
|
0
|
1
|
5196
|
|
POST
|
In your code, you first selected those features in your layer that are intersected by roads. Rather than adding to that selection, you want to remove features from the selection where the shape area does not meet your criteria. Then you can save the selected features. try:
arcpy.MakeFeatureLayer_management(opt_areas, opt_areas_layer)
# Process: Selecting by Location; Use Selecting by Location to select features that are intersected by roads.
arcpy.SelectLayerByLocation_management(opt_areas_layer, "INTERSECT", roads, None, "NEW_SELECTION", None)
print("Select by location completed")
# Process: Select by Attribute
arcpy.SelectLayerByAttribute_management(opt_areas_layer, "REMOVE_FROM_SELECTION", where_clause="Shape_Area < 40469")
print("Select by attribute completed")
except:
print(arcpy.GetMessages())
... View more
12-20-2018
09:29 PM
|
1
|
1
|
1762
|
|
POST
|
Regarding the line of code you mention: relclassDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(otable, [opk, opk_nw])}
# produces dictionary entries like:
# {'opk': ('opk_nw',) ....} value is a tuple or list
# since there are only two fields, you might try some changes around (r[1:]) like
relclassDict = {r[0]:r[1] for r in arcpy.da.SearchCursor(otable, [opk, opk_nw])}
# produces dictionary entries that might be easier to work with:
# {'opk': 'opk_nw', ....}
... View more
12-13-2018
10:34 PM
|
1
|
1
|
3182
|
|
POST
|
I have doing some experiments with add-ins, and I think you are partially correct that the problem is with the AddInID. Testing an add-in mentions one use of the AddInID: The installation utility copies the add-in file to a generated subfolder under the default add-in folder; the subfolder is automatically generated using a globally unique identifier (GUID). This prevents file naming conflicts that might occur if several add-ins have the same file name. Although add-ins can be manually copied to a default add-in folder, doing so bypasses the security and name conflict checks the add-in installation utility performs. Additionally in the add-in's XML, there are some other items that affect the add-in's operation. With the Add-In Wizard I created the start of an add-in. The XML generated by the wizard looks like this (note the red dots above and where it appears in the XML): <ESRI.Configuration xmlns="http://schemas.esri.com/Desktop/AddIns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Version2</Name>
<AddInID>{6f8bf92b-918d-440f-9fb8-e2cb53bc5f44}</AddInID>
<Description>Some description text</Description>
<Version>0.1</Version>
<Image />
<Author>Author's name</Author>
<Company>Author's company</Company>
<Date>12/13/2018</Date>
<Targets>
<Target name="Desktop" version="10.1" />
</Targets>
<AddIn language="PYTHON" library="Version2_addin.py" namespace="Version2_addin">
<ArcMap>
<Commands>
<Tool caption="Version 2" category="Version2" class="Class2" id="Version2_addin.tool" image="" message="Some message text" tip="Text of tip">
<Help heading="Some heading text">Some help text</Help>
</Tool>
</Commands>
<Extensions></Extensions>
<Toolbars>
<Toolbar caption="Toolbar2" category="Version2" id="Version2_addin.toolbar" showInitially="true">
<Items>
<Tool refID="Version2_addin.tool" />
</Items>
</Toolbar>
</Toolbars>
<Menus></Menus>
</ArcMap>
</AddIn>
</ESRI.Configuration> I think some of the problem might also relate to the duplication of the names (the red dots). My recommendation when you want to copy and modify an add-in is to: Create an empty folder for the new add-in. Open the Python Add-In Wizard and navigate to the empty folder. Complete the responses making sure to use new names where the red dots indicate. When completed, save the changes (this will generate a new AddInID). Open the Install folders for both your original add-in and the new add-in In a Python editor copy everything below the "class ClassName(object):" in your original add-in and paste it below the "class ClassName(object):" replacing the auto-generated code in your new add-in but keeping the new class name. Make the desired changes in the new add-in's Python code and save. Run the makeaddin.py script. Double-click on the **.esriaddin file to install the add in. Use the Add-In Manager as required to complete the process. It's probably not the simple rename process you were looking for, but it is fairly easy. Hope this helps.
... View more
12-13-2018
10:17 PM
|
1
|
1
|
1949
|
|
POST
|
Were you looking for something like this: from datetime import timedelta
with arcpy.da.UpdateCursor("Point Test",['myDate']) as cursor:
s = 1 # can be set to a time if needed: ( hrs * 3600 ) + ( min * 60 ) + sec
for row in cursor:
row[0] += timedelta(seconds=s) # also minutes= hours= days=
s += 1 # increment amount
cursor.updateRow(row)
... View more
12-13-2018
03:51 PM
|
1
|
1
|
3103
|
|
POST
|
What does the "UGI_Pass_Fail" domain look like? You need to match the value of the code, not the description. And the match is case-sensitive. If "FAIL" is both the code and the description, you will need to change the case use in line 41 of Joshua Bixby's code. Also, you can use List Fields to find the fields that use a specific domain: domain = 'UGI_Pass_Fail'
chkFields = []
fc = 'MyFeature' # a feature in the geodatabase
fields = arcpy.ListFields(fc)
for field in fields:
if field.domain == domain:
chkFields.append(field.name)
print chkFields
... View more
12-10-2018
09:01 PM
|
1
|
0
|
1004
|
| 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
|