|
BLOG
|
Take a square representing a polygon or a closed-loop polyline. Let us call it aoi, perhaps out area of interest. aoi
array([[ 0.00, 0.00],
[ 0.00, 10.00],
[ 10.00, 10.00],
[ 10.00, 0.00],
[ 0.00, 0.00]])
aoi.shape
(5, 2) Notes: The first and last points are the same, hence it is a closed geometry The shape of the poly* feature is 5 rows (0 through 4 inclusive) and 2 columns ( 0 and 1), since python numbering is zero-based Conceptually we know from out maths, that we just need to take the sequential difference between the points to get the differences in the x's and y's. Whip in a quick euclidean calculation courtesy of the right-angle triangle and other cringeful recollections of things numeric. So it comes as no surprise that anything that involves rows and columns would be painfully slow to do one calculation at a time. Enter einsum notation and its NumPy representation. (also useful for you Tensor types out there) diff = aoi[1:] - aoi[:-1]
np.sqrt(np.einsum('ij,ij->i', diff, diff))
array([ 10.00, 10.00, 10.00, 10.00]) Which means multiply the two columns, and summarize, just like diff
array([[ 0.00, 10.00],
[ 10.00, 0.00],
[ 0.00, -10.00],
[-10.00, 0.00]])
diff * diff
array([[ 0.00, 100.00],
[ 100.00, 0.00],
[ 0.00, 100.00],
[ 100.00, 0.00]])
np.sum(diff*diff, axis= 1) # -- axis 1 means by row, since axis 0 is columns
array([ 100.00, 100.00, 100.00, 100.00]) So you want the hypotenuse of your square? Just use einsum summation on the other axis. np.sqrt(np.einsum('ij,ij->j', diff, diff)) # -- note summation is by 'j' this time
array([ 14.14, 14.14]) The einsum notation string, just needs to be consistent when referencing the axes to perform actions on np.sqrt(np.einsum('ab,ab->a', diff, diff)) is the same as np.sqrt(np.einsum('ij,ij->j', diff, diff)) I use einsum in a lot of my Geo array calculations. For example to determine the area of a polygon "bit" (either an inner or outer ring or parts of multipart polygons). def _bit_area_(a):
"""Mini e_area, used by `areas` and `centroids`.
Negative areas are holes. This is intentionally reversed from
the `shoelace` formula.
"""
a = _get_base_(a)
x0, y1 = (a.T)[:, 1:] # cross set up as follows
x1, y0 = (a.T)[:, :-1]
e0 = np.einsum('...i,...i->...i', x0, y0) # 2024-03-28 modified
e1 = np.einsum('...i,...i->...i', x1, y1)
return np.sum((e0 - e1) * 0.5) This essentially sets up the 2D crossproduct for a modified 'shoelace' formula. How about determining the distance from one point to a bunch of other points? I will use 'aoi' as my other points and define a point 'p'. def _e_2d_(a, p):
"""Return distance from a point to an array of points"""
diff = a - p[None, :]
return np.sqrt(np.einsum('ij,ij->i', diff, diff))
p = np.array([3., 4.])
_e_2d_(aoi, p)
array([ 5.00, 6.71, 9.22, 8.06, 5.00]) And to end this off, how about a translation and rotation of a polygon? A little use of einsum to simplify the matrix calculations. def _r_(a, cent, angle, clockwise):
"""Rotate by `angle` in degrees, about the center."""
angle = np.radians(angle)
if clockwise:
angle = -angle
c, s = np.cos(angle), np.sin(angle)
R = np.array(((c, -s), (s, c)))
return np.einsum('ij,jk->ik', a - cent, R) + cent Using the function above with these inputs _r_(aoi, cent=[1., 1.], angle=45., clockwise=True)
array([[ 1.00, -0.41],
[ -6.07, 6.66],
[ 1.00, 13.73],
[ 8.07, 6.66],
[ 1.00, -0.41]]) yields the above coordinates which looks like this einsum_rotate_poly.png Enough for now.
... View more
03-27-2025
06:03 PM
|
2
|
0
|
550
|
|
POST
|
is your input flow direction raster alright? Flow Length (Spatial Analyst)—ArcGIS Pro | Documentation
... View more
03-27-2025
03:42 PM
|
0
|
0
|
709
|
|
POST
|
By track back, I meant the procedures under the Usage section. This ensures the inputs are correct for the tool
... View more
03-27-2025
03:38 PM
|
0
|
0
|
1463
|
|
POST
|
via code or the builtin tool? Detect Objects Using Deep Learning (Raster Analysis)—ArcGIS Pro | Documentation You may have to track back the error to its source during the creation process to get at the one thrown by which-ever method you used.
... View more
03-27-2025
12:28 PM
|
0
|
0
|
1495
|
|
POST
|
the same bit depth? pyramids? anything you can provide about the mosaic and the input rasters would help
... View more
03-27-2025
09:07 AM
|
0
|
0
|
829
|
|
POST
|
if both inputs are polygons, then a summarize within using the maximum might work Summarize Within (Analysis)—ArcGIS Pro | Documentation
... View more
03-27-2025
09:06 AM
|
1
|
2
|
1934
|
|
POST
|
Since you have found the link, regarding minimum dependencies, it might be worthwhile looking at the "issues" section of their github site to see if any similar questions have popped up and been closed Esri/arcgis-python-api: Documentation and samples for ArcGIS API for Python I would post a query directly on their github site, it gets more traffic from the developers than here
... View more
03-26-2025
02:58 PM
|
2
|
1
|
1841
|
|
BLOG
|
It began as a simple coding exercise, but it soon morphed into one of those "things". Offset Buffer I began with the seemingly simple exercise of the offset buffer, which is created by 'offsetting' the segments of a geometry object, polygons in this case, by a finite distance. I will spare you the sheer excitement when I managed to implement an offset buffer for an axis aligned square. Here is a concave polygon with an offset buffer. offset_simple.png For the most part the buffer is equally spaced except for those outward pointing corners. On to the rounded corners. That involved arcs and angles and intersections and the math stuff that I had forgotten or long not used. The effort was breathtaking. I left the arc nodes to show I worked really hard. rounded_simple.png On to the next shapes! What could go wrong. Here is another example of a more convoluted concave polygon as an offset and conventional buffer. d1_with_np_wn_algo.png d1_with_np_wn_rounded.png I wonder what a really cool geometry would look like with the new buffering code? maple0.png The journey continue smoothly there. Producing rounded corners when the pointy bits are close together proved to a challenge, but that involves another blog and the code links. But in the interim, something to look forward to and share with your neighbours. maple_leaf.png
... View more
03-25-2025
07:39 PM
|
3
|
0
|
814
|
|
POST
|
Does the first row of the csv contain the field names? Can you post a few rows to see if there is something wrong with the csv?
... View more
03-25-2025
12:29 PM
|
0
|
0
|
2027
|
|
POST
|
what were the label expressions? Specify text for labels—ArcGIS Pro | Documentation Write Arcade expressions for symbology and labeling—ArcGIS Pro | Documentation plus more links in the help files
... View more
03-25-2025
09:59 AM
|
0
|
0
|
1034
|
|
POST
|
Chart symbology—ArcGIS Pro | Documentation which may not be suitable for your data layout. It is also only recommended for small data sets. as well, you are trying to symbolize 4 variables by their count
... View more
03-25-2025
03:20 AM
|
0
|
1
|
1331
|
|
POST
|
Glad you mirrored my response and found a solution in any event.
... View more
03-24-2025
12:50 PM
|
1
|
0
|
3931
|
|
POST
|
What version of Arcgis Pro? (hence arcpy) Do you have integer fields? Was the table old? using short integer vs long integer? Note in the snippet that the entry for the parameters is a space delimited string. I just did a test and copies the tool parameters and got this for one field Alter Fields (multiple)
=====================
Input Table maple_leaf_multi
Field Properties ID_arr ID_orig # LONG # # #
Updated Input Table maple_leaf_multi
===================== The LONG was prompted for confirmation by the tool. copied python snippet arcpy.management.AlterFields( in_table="maple_leaf_multi", field_description="ID_orig ID_orig # LONG # # #" ) I would check check a manual run of the tool again
... View more
03-24-2025
12:23 PM
|
0
|
2
|
3959
|
|
POST
|
Where is the string being used/assigned? are you manually putting the string in or defining it somewhere? Can you confirm that input string has the form r'xmlns="urn:Redlines.xsd"'
'xmlns="urn:Redlines.xsd"'
'''xmlns="urn:Redlines.xsd"''' and the string includes xmlns= Side notes other encodings are used in various parts of arcgis pro, for example in Calculate Field there is this ArcGIS applications use UTF-16-LE encoding to read and write .cal files. Other applications (for example, Notepad) can be used to create or modify .cal files as long as the file is written using UTF-16-LE encoding. A file with any other encoding will not load into the code block. So where the string "is" and what it is part of
... View more
03-21-2025
05:09 AM
|
0
|
1
|
1531
|
|
POST
|
What's new in version 2.4.0 | ArcGIS API for Python top paragraph for previous versions Downloads | ArcGIS API for Python
... View more
03-20-2025
09:25 AM
|
0
|
0
|
2183
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a week ago | |
| 1 | 4 weeks ago | |
| 1 | 2 weeks ago | |
| 1 | 2 weeks ago | |
| 1 | 2 weeks ago |