IDEA
|
👎The ASCII format lines you quote describe an ASCII Raster file. The ASCII 3D To Feature Class tool is designed to turn text data to feature class. If you want to turn ascii raster to features, look at chaining together a tool to import the ascii (Copy Raster) and a tool to convert the raster to features (for example Raster to Polygon)
... View more
08-01-2023
12:47 AM
|
0
|
0
|
483
|
IDEA
|
You can run a field calculator on the concatenated field. def sortValues(the_value, delimiter=','):
"""Sort a separated value into an order
Useful to run on ArcGIS processes where there is no control on returned values.
For example SpatialJoin, JOIN_ONE_TO_ONE, with FieldMapping Merge Rule = Join
"""
if the_value == None:
return the_value
# Create a Python list by splitting the string on the delimeter
the_list = the_value.split(delimiter)
# unique elements of the list using set()
the_set = set(the_list)
# turn the set back to a list
the_list = list(the_set)
# Sort the list
the_list.sort()
# Reassemble the string from the sorted list
rval = delimiter.join(the_list)
return rval
... View more
07-18-2023
04:55 AM
|
0
|
0
|
513
|
POST
|
I am trying to use ArcHydro for ArcGIS Pro (3.1.12) and I am getting errors where the code is calling time.clock() which is has been removed (not just deprecated) as a function in python 3.8 From the Python 3.8 doc: The function time.clock() has been removed, after having been deprecated since Python 3.3: use time.perf_counter() or time.process_time() instead, depending on your requirements, to have well-defined behavior. (Contributed by Matthias Bussonnier in bpo-36895.)
... View more
06-18-2023
05:29 PM
|
0
|
0
|
484
|
DOC
|
To get rid of duplicated values, you need to run another function on the result. It can't be changed as this is a result of the merge rule. The code I use is this: def uniqueValues(the_value, delimiter=","):
"""return unique separated values in order
Useful to run on ArcGIS processes where there is no control on returned values.
For example SpatialJoin, JOIN_ONE_TO_ONE, with FieldMapping Merge Rule = Join
"""
if the_value is None:
return the_value
# Create a Python list by splitting the string on the delimeter
the_list = the_value.split(delimiter)
# Use set to get unique values
unique_values = sorted(set(the_list))
# Reassemble the string from the sorted list
return delimiter.join(unique_values)
... View more
08-01-2022
07:09 PM
|
0
|
0
|
2386
|
POST
|
The ValueError could be raised if you have nothing but null values in a column. You could try changing the function checking for the maximum value to change null values to zeros. def get_maximum_field_value(in_table, field_name):
"""Return the maximum value of a field in a table. Using Numpy."""
data = arcpy.da.TableToNumPyArray(in_table, [field_name], null_value=0)
return numpy.max(data[field_name])
... View more
06-16-2022
09:09 PM
|
1
|
1
|
623
|
POST
|
Build a list of the fields where the precipitation is less than 100. There a number of tools that could do this including "Summary Statistics", but I have include a way to do this with numpy. Once you have the list of fields, pass it to the delete fields tool. import numpy
import arcpy
def get_maximum_field_value(in_table, field_name):
"""Return the maximum value of a field in a table. Using Numpy."""
data = arcpy.da.TableToNumPyArray(in_table, [field_name])
return numpy.max(data[field_name])
table = "Test_area_cliped"
fields = [f.name for f in arcpy.ListFields(table)]
delete_fields=[]
for field in fields:
precipitation = get_maximum_field_value(table, field)
if precipitation < 100:
delete_fields.append(field)
arcpy.DeleteField_management(table, delete_fields)
... View more
06-15-2022
06:58 PM
|
1
|
0
|
639
|
POST
|
There are two issues. You have two variables called bookmark. The user input Line8 and list of bookmarks in the map on Line9. Your user input is overwritten by the list of bookmarks. You never compare the bkmk.name in the loop with the user input to find the actual bookmark your are looking for. # get the user input bookmark name
in_bookmark = arcpy.GetParameterAsText(2)
bookmark = mf.map.listBookmarks()
for bkmk in bookmark: # loop through all bookmarks until find specific bookmark
if bkmk.name == in_bookmark: # compare the bookmark name with the user input
mf.zoomToBookmark(bkmk)
arcpy.AddMessage(f'{in_bookmark} bookmark set')
# then do layers on/off
else:
arcpy.AddWarning('Bookmark does not exist')
... View more
06-13-2022
05:07 PM
|
1
|
1
|
579
|
IDEA
|
Wrap the summary statistics in a function. def calculate_field_statistics(in_table, field, statistics_type='SUM'):
""" Run the Summary Statistics on a field in a table and return the result."""
try:
# Create the temporary stats result table
stats_table = arcpy.CreateUniqueName('stats', 'in_memory')
# The output field is statistics_type underscore field name
stats_field = "{}_{}".format(statistics_type, field)
# Run Summary Statistic
arcpy.analysis.Statistics(in_table, stats_table, [[field, statistics_type]])
# Return the first value from the stats_table
return arcpy.da.SearchCursor(stats_table, stats_field).next()[0]
finally:
# Delete the stats table
if arcpy.Exists(stats_table):
arcpy.management.Delete(stats_table)
... View more
05-04-2022
03:41 AM
|
0
|
0
|
703
|
POST
|
To fix your problem you will need to alter your code to: Add a field to the output feature class to store the parcel id. Modify the insert cursor to also update this parcel update Insert the row with the geometry and the parcel id every time the parcel id changes. The code will look like this: import csv
import os
import arcpy
in_dir = "D:/demo"
csvFile = "parcel_points.csv"
fc = "polygonFromCSV"
in_csv = os.path.join(in_dir, csvFile)
sr = arcpy.SpatialReference(26910)
# Create output feature class
arcpy.management.CreateFeatureclass(
in_dir, fc, geometry_type="POLYGON", spatial_reference=sr
)
out_feature_class = os.path.join(in_dir, fc)
# Add a field to transfer PARCELID from input csv
arcpy.management.AddField(out_feature_class, "PARCELID", "LONG")
with arcpy.da.InsertCursor(out_feature_class, ["SHAPE@", "PARCELID"]) as cursor:
point_list = []
parcel_value = None
is_first_pass = True
with open(in_csv, mode="r") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
header = next(csv_reader)
for row in csv_reader:
#print(f"Parcel id:{row[0]} with X {row[1]} and Y {row[2]}.")
if is_first_pass:
parcel_value = row[0]
is_first_pass = False
elif row[0] != parcel_value:
# Parcel ID has changed, write the polygon
polygon = arcpy.Polygon(arcpy.Array(point_list), sr)
cursor.insertRow([polygon, parcel_value])
# Reset the current group
parcel_value = row[0]
point_list = []
# Add the point to the feature's array of points
point_list.append(arcpy.Point(row[1], row[2]))
# final insert
polygon = arcpy.Polygon(arcpy.Array(point_list), sr)
cursor.insertRow([polygon, parcel_value])
... View more
05-04-2022
03:27 AM
|
0
|
1
|
1370
|
POST
|
If you just want to point to an excel file (and not a sheet/range within the file) use the FILE data type, and then set the filter to XLSX.
... View more
03-08-2021
08:09 PM
|
2
|
0
|
2928
|
POST
|
You can do it via code. import arcpy
#Reference the Project document from within PRO
aprx = arcpy.mp.ArcGISProject("CURRENT")
#Reference the layout
lyt = aprx.listLayouts("your_layout_name_here")[0]
#Get the Map Frame
mf = lyt.listElements("mapframe_element", "your_mapframe_name")[0]
extent = mf.camera.getExtent()
polygon = extent.polygon You then have a polygon object that you can work with. Note that this code just grabs the extent, if the map frame is rotated, the extent doesn't match what you see on screen.
... View more
01-07-2021
04:24 PM
|
6
|
2
|
4725
|
IDEA
|
The closest they come to a help topic is the How To, with a mention a step 8 How To: Create and store a custom Python system toolbox in ArcGIS Pro
... View more
01-05-2021
06:37 PM
|
0
|
0
|
1534
|
POST
|
Because Pro has multiple layouts, you need to get the layout as well. Try something like this: aprx = arcpy.mp.ArcGISProject("CURRENT")
lyt = aprx.listLayouts("your_layout_name")[0]
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.name == 'SiteName':
elm.text = SiteName
elif elm.name == 'Address':
elm.text = Address
... View more
01-05-2021
04:26 PM
|
0
|
0
|
1044
|
POST
|
Conor, You need to nest your cursors, rather than having two separate cursors. Otherwise you just get the Max_Value from the last row for the route table. def frange(start, stop, step):
"""Range function that works with floats"""
r = start
while r < stop:
yield r
if step > 0:
r += step
else:
r -= step
def main_snippet():
""" main processing snip"""
in_routes = arcpy.lr.CreateRoutes(Input_Linework, Linework_Field, Output_Name)
# Create table with two fields, RouteID and Chainage
route_table = arcpy.management.CreateTable(str(Output_WS), Output_Name)
# add the fields. Missing in your script
arcpy.management.AddField(route_table, 'RouteID', 'TEXT', field_length=15)
arcpy.management.AddField(route_table, 'Chainage', 'DOUBLE')
# Populate event table using cursors
search_fields = [Linework_Field, "SHAPE@"]
update_fields = ['RouteID', 'Chainage']
# increments of 1
measure_interval = 1
with arcpy.da.InsertCursor(route_table, update_fields) as icursor:
with arcpy.da.SearchCursor(in_routes, search_fields) as cursor:
for row in cursor:
# read the geometry
line = row[1]
# use the measures
first_measure = float(line.firstPoint.M)
last_measure = float(line.lastPoint.M)
# step thru the meaures, by measure_interval
for measure in frange(first_measure, last_measure, measure_interval):
# insert value into route_table
icursor.insertRow((row[0], measure))
print('Done.')
... View more
06-16-2020
06:24 PM
|
0
|
0
|
348
|
POST
|
There is an example of this coding on the 'Calculate Field Example' page in the help called 'Calculate fields using logic with python'. Use a Code Block similar to this: def calcRisk(sixtyFiveO, metroClass, diabetes):
if sixtyFiveO <= 0.0933 and metroClass in ('Noncore', 'Micropolitan') and Diabetes < 0.05:
theRisk = 'low'
elif sixtyFiveO >= 0.09331 and sixtyFiveO <= 0.0.01866 and metroClass in ('Small Metro', 'Medium Metro'):
theRisk = 'moderate'
else:
theRisk = 'high'
return theRisk With a call to the code block like: calcRisk(!SixtyFiveO!, !MetroClass!, !Diabetes!)
... View more
04-21-2020
05:00 PM
|
2
|
0
|
366
|
Title | Kudos | Posted |
---|---|---|
1 | 06-16-2022 09:09 PM | |
1 | 06-15-2022 06:58 PM | |
1 | 06-13-2022 05:07 PM | |
2 | 03-08-2021 08:09 PM | |
6 | 01-07-2021 04:24 PM |
Online Status |
Offline
|
Date Last Visited |
08-01-2023
12:53 PM
|