|
BLOG
|
NumPy SciPy - Although I feel like at this point numpy is a subset of pure python lol. Not so, a lot of the NumPy package is written in C-ish etc languages for speed. Broadcasting — NumPy v2.2 Manual is the key I like it because of its ability to deal with geometry objects, although I had to create my own geometry class to avoid working with object/ragged arrays. Dan-Patterson (Dan Patterson) check out Dan-Patterson/numpy_geometry: A numpy geometry class and functions that work with arcpy and ESRI featureclasses. Includes Free Tools for ArcGIS Pro the code is a work in progress, (now that I am retired for a while) There is a lot of work involving array and array standards as well, although esri isn't on the official list Consortium for Python Data API Standards Also check out the code in C:\...install_folder...\Resources\ArcPy\arcpy C:\...install_folder...\Resources\ArcToolBox\Scripts C:\...install_folder...\Resources\ArcToolBox\toolboxes You would be surprised how many times NumPy is imported and used in arc* code Have fun
... View more
02-20-2025
04:52 PM
|
1
|
0
|
2404
|
|
POST
|
So have you tried? Copy Raster (Data Management)—ArcGIS Pro | Documentation make sure you check the Environments tab so that the proper statistics get calculated
... View more
02-20-2025
03:02 PM
|
1
|
0
|
1366
|
|
BLOG
|
Common imports and names import arcpy
from arcpy.da import SearchCursor
import numpy.lib.recfunctions as rfn
#
t0 = r"C:\arcpro_npg\Project_npg\npgeom.gdb\table0"
t1 = r"C:\arcpro_npg\Project_npg\npgeom.gdb\table1"
table0 = arcpy.da.TableToNumPyArray(t0, "*")
table1 = arcpy.da.TableToNumPyArray(t1, "*")
#
IN_TABLE = r"C:\arcpro_npg\Project_npg\npgeom.gdb\dep_required_by"
SUMMARY_FIELD = "Required_by" fixing row.split() to row[0].split() %%timeit
arr = arcpy.da.TableToNumPyArray(tbl, "Required_by")
vals = arr["Required_by"]
big = [i.strip() for v in vals for i in v.split(",")]
big_flat = npg.flatten(big)
uniq1, cnts1 = np.unique(big_flat, return_counts=True)
out_arr = np.asarray(list(zip(uniq1, cnts1)), dtype=[('Package', 'U50'), ('Counts', 'i4')])
4.01 ms ± 636 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%%timeit
srch_cr = SearchCursor(IN_TABLE, [SUMMARY_FIELD])
vals = [val.strip() for row in srch_cr for val in row[0].split(',')]
unique = np.array([(val, vals.count(val)) for val in set(vals)], dtype=[('Package', 'U50'), ('Counts', 'i4')])
4.84 ms ± 785 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%timeit arr = arcpy.da.TableToNumPyArray(tbl, "Required_by")
1.51 ms ± 105 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
%timeit srch_cr = SearchCursor(IN_TABLE, [SUMMARY_FIELD])
76.7 µs ± 9.73 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each) shows comparable times with TableToNumPyArray taking up about 20% of the time, however, it creates an object (line 20, 21) rather than a reference (lines 23, 24) lines 4 and 14 are the clinch points. Now to really have a look underneath do a dir(srch_cr)
[.... snip ...
'__subclasshook__',
'_as_narray',
'_dtype',
'fields',
'next',
'reset']
# explore away
arr = srch_cr._as_narray()
type(arr)
numpy.ndarray
arr.shape
(252,) so you can skip the for row in rows thing and skip directly to a numpy array.
... View more
02-20-2025
01:57 PM
|
1
|
0
|
2415
|
|
POST
|
Clip Raster (Data Management)—ArcGIS Pro | Documentation you can certainly set the output extent of the clipped raster What parameters did you use for the tool? defining the output extent can definitely be accomplished using the appropriate parameter settings. compare the options you used with the parameter functions in the help topic
... View more
02-20-2025
04:21 AM
|
0
|
0
|
1453
|
|
POST
|
yes They are stored in your user profile at [drive]:\Users\[your_name]\Documents\ArcGIS\OnlineStyles. Add styles to a project—ArcGIS Pro | Documentation I don't see anything in the Project backstage
... View more
02-19-2025
02:03 PM
|
0
|
0
|
665
|
|
POST
|
got it. but import arcpy
array_polygon = arcpy.Array([arcpy.Point(1000.0, 2000.0, 50.0),
arcpy.Point(1500.0, 2000.0, 50.0),
arcpy.Point(1500.0, 2500.0, 50.0),
arcpy.Point(1000.0, 2500.0, 50.0),
arcpy.Point(1000.0, 2000.0, 50.0)]) # Closing the polygon
polygon = arcpy.Polygon(array_polygon) # polygon object
out_fc = r"C:\arcpro_npg\Project_npg\npgeom.gdb\copy_poly_tst"
arcpy.CopyFeatures_management([polygon], out_fc) copy_poly.png seems to work as @XanderBakker suggested back in the day
... View more
02-19-2025
12:19 PM
|
1
|
0
|
2722
|
|
BLOG
|
Forgot the python/numpy solution,. What it lacks in elegance, it should be admired for its persistence z = [[1, 2], [3, 4], [5, 6], [7, 8, 9], [10], [[11]], [[[12]]]]
z0 = sum([np.array(i).reshape(-1).tolist() for i in z], [])
z0
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
... View more
02-19-2025
11:59 AM
|
0
|
0
|
1231
|
|
POST
|
# Create a polygon feature class feature_class_name_polygon = "counties_polygon" arcpy.CreateFeatureclass_management( out_path=gdb_full_path, out_name=feature_class_name_polygon, geometry_type="POLYGON", has_z="ENABLED" # Enable Z values ) It was... unless the original code was edited by someone other than @SononosoT ... which it shouldn't be
... View more
02-19-2025
11:32 AM
|
0
|
1
|
2727
|
|
BLOG
|
but only if you know all entities are lists of the same depth z =[[[1, 2], [3, 4], [5, 6], [7, 8, 9], [10]]]
sum(*z, [])
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# .... but
z =[[[1, 2], [3, 4], [5, 6], [7, 8, 9], [10], [[11]], [[[12]]]]]
sum(*z, [])
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, [11], [[12]]]
# and no, sum(sum... fails
... View more
02-19-2025
11:28 AM
|
1
|
0
|
1234
|
|
BLOG
|
lots I could write about... I don't suppose there is much market for inner, outer, and left outer joins using numpy and arcpy? production of the tables and the output .... 20 minutes production of the image below (eg rearranging tables and the fiddly stuff) 1 hour bunchOfjoins.png import arcpy
t0 = r"C:\arcpro_npg\Project_npg\npgeom.gdb\table0"
t1 = r"C:\arcpro_npg\Project_npg\npgeom.gdb\table1"
table0 = arcpy.da.TableToNumPyArray(t0, "*")
table1 = arcpy.da.TableToNumPyArray(t1, "*")
#
import numpy.lib.recfunctions as rfn
#
inner_ = rfn.join_by('f0', table0, table1, 'inner', usemask=False)
outer_ = rfn.join_by('f0', table0, table1, 'outer', usemask=False)
lft_outer_ = rfn.join_by('f0', table0, table1, 'leftouter', usemask=False)
#
t_in = r"C:\arcpro_npg\Project_npg\npgeom.gdb\t0t1_inner"
t_out = r"C:\arcpro_npg\Project_npg\npgeom.gdb\t0t1_outer"
t_lft_out = r"C:\arcpro_npg\Project_npg\npgeom.gdb\t0t1_lft_outer"
arcpy.da.NumPyArrayToTable(inner_, t_in)
arcpy.da.NumPyArrayToTable(outer_, t_out)
arcpy.da.NumPyArrayToTable(lft_outer_, t_lft_out) I could have used arcpy.da.ExtendTable but I was on an 'rfn' roll
... View more
02-19-2025
12:08 AM
|
0
|
0
|
2454
|
|
BLOG
|
Replace the numbers below with anything you want. lst = [
[[1, 2, 3], [4, 5]],
[[1, 2]],
[1, 2],
[[]],
[[1, 2, 3], [4, 5], [6, 7, 8]],
[[[1, 2, 3], [4, 5]], [[6, 7, 8]]],
] Flatten with recursion (a function calling itself 'recursively') def flatten(a_list, flat_list=None):
"""Change the isinstance as appropriate.
: Flatten an object using recursion
: see: itertools.chain() for an alternate method of flattening.
"""
if flat_list is None:
flat_list = []
for item in a_list:
if isinstance(item, list):
flatten(item, flat_list)
else:
flat_list.append(item)
return flat_list Simple flattening flatten(lst) [1, 2, 3, 4, 5, 1, 2, 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8] Who says you can't start out with initial values. flatten(lst, ['a', 'b'])) ['a', 'b', 1, 2, 3, 4, 5, 1, 2, 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8]
... View more
02-18-2025
09:27 PM
|
2
|
6
|
1745
|
|
BLOG
|
It seemed like a simple idea at the time. Take the outputs from another data source, concatenate the values to a string and toss them into a new field. Looks nice eh? table_of_data.png Well, well, you can even query the whole stringy-thing. Don't get me wrong, the whole Select By Attributes and the sql thing are pretty cool table_query.png Sorting is fun too. Who would have thought that arcpy-base had so many friends (dependencies). arcpy-base.png That is when I asked myself what are the interdependencies/requirements/dependencies for Spyder, my favorite python IDE. Sql away, the sort thing got me to roll. That is when I thought .... what about this package? how about that one? Time for a big summary, which wasn't going to work with the existing options. That is when I remembered those arc angels that coded the numpy stuff!! (not the post stevie ray band or things divinical) TableToNumPyArray and NumPyArrayToTable. Follow along. 1 import arcpy of course or 2-4 specify your table of interest and its field(s). We now have an array. None of this "for row in cursor stuff". 'vals' is a view of the data in 'arr', so we can explore it and manipulate it 6 list comprehensions can be fun for every value (v) in the array (vals) split the value at the commas (note I used "," instead of ", " since there was a mixture strip off any leading/trailing spaces to be on the safe side 7 flatten the whole dataset 8 get the unique entries and their counts. Remember the field was one big messy string/former list thing. 9- 11 Create the output array and send the whole summary back to Pro import arcpy
tbl = r"C:\arcpro_npg\Project_npg\npgeom.gdb\dep_required_by"
arr = arcpy.da.TableToNumPyArray(tbl, "Required_by")
vals = arr["Required_by"]
big = [i.strip() for v in vals for i in v.split(",")]
big_flat = npg.flatten(big)
uniq1, cnts1 = np.unique(big_flat, return_counts=True)
out_tbl = r"C:\arcpro_npg\Project_npg\npgeom.gdb\dep_summary"
out_arr = np.asarray(list(zip(uniq1, cnts1)), dtype=[('Package', 'U50'), ('Counts', 'i4')])
arcpy.da.NumPyArrayToTable(out_arr, out_tbl) Now the next time I am interested in exploring the python package infrastructure for Pro, I have a workflow. table_summary.png Don't be afraid to use what was given to you. Arcpy and NumPy play nice together.
... View more
02-18-2025
08:55 PM
|
3
|
13
|
2924
|
|
POST
|
Have you tried to create a list of your poly* features, then use the Copy Features tool/function as in this blog Working with 3D and M-aware geometries in Arcpy - Esri Community might be worth a shot to see if it could be an alternative to cursors.
... View more
02-18-2025
04:53 PM
|
1
|
0
|
2768
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 2 weeks ago | |
| 1 | 4 weeks ago | |
| 1 | 3 weeks ago | |
| 1 | 2 weeks ago | |
| 1 | 3 weeks ago |