POST
|
This Community is not really the place to find out what Esri Inc recommends. Most staffers here don't have the privilege to speak for the company, so explicitly asking for that is going to suppress responses from non-employees and employees both (probably not what you're shooting for here). - V
... View more
11-07-2023
07:17 PM
|
1
|
1
|
846
|
POST
|
You can certainly fashion a .bat file that calls python tool.pyt arg1 ... argN, but it can't be a .exe executable. - V
... View more
11-07-2023
12:01 PM
|
1
|
0
|
276
|
BLOG
|
I've seen a number of queries recently, trying to find a tool which would allow a user to determine the maximum number of circles of a certain size which fit inside an arbitrary polygon. There is, of course, no such COTS tool, but generating a custom tool task starts with generating a region of tightly packed circles, and there's almost a tool to do that, though it needs some tweaking... The ArcGIS GenerateTessellation tool (arcpy.management.GenerateTessellation) will generate tessellations of a number of given shapes*: *Note: Transverse Hexagon and Diamond only available in ArcGIS Pro but "Circle" isn't included because the definition of tessellation ("a covering of an infinite geometric plane without gaps or overlaps by congruent plane figures of one type or a few types" -- Merriam-Webster) requires the figures to be "without gaps or overlaps". However, if your intent is to use circles anyway, then there are clearly two base geometries one could use to start: SQUARE (which is the same as DIAMOND, just rotated 45 degrees), and HEXAGON (for which TRANSVERSE_HEXAGON is the rotated form, at 90 degrees). Since the goal here is "packing", the choice should clearly be for HEXAGON (since they are the bestagons ) And how do you go from hexagon to circle? Ahh, well there are a couple of issues to consider: Regular hexagons are composed of six equilateral triangles, so "side" and "radius" are actually the same The radius of a hexagon is the radius of the circumscribing circle, not the inscribed circle, and circumscribed circles of neighboring tiles would overlap (doh!) The Generate Tessellation tool uses hexagon area to determine hexagon size, not side length/radius* *This is cool, though, because there's a formula to derive area ( A ) from side ( a ) So what's the key thing to know? In order to use hexagons to generate packed circles, we need to define the hexagon with respect to the midpoint of the hexagon side (where the inscribed circle touches). And what is the difference? I'll save the math, for now, and cut to the chase: You need to increase the circle radius by the inverse of the sine of the interior angle size of a hexagon -- 60 degrees (aka pi / 3 radians). In Python, that works out to: import math
diameter = 100
radius = diameter * 0.5
side = radius / math.sin(math.pi / 3.0)
hex_area = 1.5 * math.sqrt(3) * side * side The rest of the problem is simple enough to script: Generate Tessellation with the compensated area Extract centroids from the hexagons as points Use the points to buffer circles of the original diameter And that would look like this (with an arbitrary Cartesian CRS and extent, and kludged naming): sr = arcpy.SpatialReference(3968)
tess_shape = 'TRANSVERSE_HEXAGON' # or 'HEXAGON'
arcpy.env.workspace = r"C:\Temp\packed_circles\cartesian.gdb"
extent = '-1000 -1000 1000 1000'
subscript = 1
print("Generating hexagons with side {:.6f}...".format(side))
arcpy.management.GenerateTessellation(
Output_Feature_Class="hexagons{:d}".format(subscript),
Extent=extent,
Shape_Type=tess_shape,
Size="{:f} SquareMeters".format(hex_area),
Spatial_Reference=sr.exportToString()
)
print("Generating centroids...")
arcpy.management.FeatureToPoint(
in_features="hexagons{:d}".format(subscript),
out_feature_class="centroids{:d}".format(subscript),
point_location="CENTROID"
)
print("Generating circles (radius {:.1f})...".format(radius))
arcpy.analysis.Buffer(
in_features="centroids{:d}".format(subscript),
out_feature_class="circles{:d}".format(subscript),
buffer_distance_or_field="{:.1f} Meters".format(radius),
line_side="FULL",
line_end_type="ROUND",
dissolve_option="NONE",
dissolve_field=None,
method="PLANAR"
) Which gives us 100m diameter circles, packed tightly: And how do I use these circles to find the maximum number of circles in an arbitrary polygon? Well, that's going to be a bit trickier (aka, "I haven't coded it yet"), so I'll address it in Part II. - V
... View more
11-06-2023
07:37 AM
|
6
|
2
|
417
|
POST
|
Please put your code in code blocks (click on Post options, choose "Edit post (or reply)", hit the "..." in the top-right of the editor menu (to expand the menu block), copy the code text, then click on "</>" and paste into the popup, then clean up the code inside and outside the code block). This will make your code legible. - V
... View more
11-01-2023
10:57 AM
|
1
|
0
|
336
|
IDEA
|
I don't use regularly use SDE.ST_GEOMETRY. How did you create those rows, because at least one of them seems malformed. - V
... View more
10-31-2023
08:07 PM
|
0
|
0
|
529
|
POST
|
For reference, the empty array trick works for Polygon, Polyline, and Multipoint classes, but PointGeometry won't accept a None point parameter. - V
... View more
10-30-2023
05:58 PM
|
1
|
0
|
726
|
POST
|
You can use the Well-Known Text keyword "EMPTY" to generate a NIL geometry: import arcpy
sr = arcpy.SpatialReference(4326)
np = arcpy.FromWKT("POLYGON EMPTY",sr)
print("np - pointCount: {:d} JSON: {:s}".format(np.pointCount,np.JSON))
nl = arcpy.FromWKT("LINESTRING EMPTY",sr)
print("nl - pointCount: {:d} JSON: {:s}".format(nl.pointCount,nl.JSON))
nm = arcpy.FromWKT("MULTIPOINT EMPTY",sr)
print("nm - pointCount: {:d} JSON: {:s}".format(nm.pointCount,nm.JSON))
nx = arcpy.FromWKT("POINT EMPTY",sr)
print("nx - pointCount: {:d} JSON: {:s}".format(nx.pointCount,nx.JSON))
print("nx - firstPoint: {:s}".format(str(nx.firstPoint))) which results in: np - pointCount: 0 JSON: {"rings":[],"spatialReference":{"wkid":4326,"latestWkid":4326}}
nl - pointCount: 0 JSON: {"paths":[],"spatialReference":{"wkid":4326,"latestWkid":4326}}
nm - pointCount: 0 JSON: {"points":[],"spatialReference":{"wkid":4326,"latestWkid":4326}}
nx - pointCount: 1 JSON: {"x":"NaN","y":"NaN","spatialReference":{"wkid":4326,"latestWkid":4326}}
nx - firstPoint: None Curiously, the PointGeometry type always returns a pointCount of one, but the firstPoint is None. WKT can also be used at the SQL prompt in Oracle: SQL> SELECT 'POLYGON' as type,SDE.ST_ASTEXT(SDE.ST_PolyFromText('POLYGON EMPTY',4326)) as geom FROM DUAL;
TYPE
-------
GEOM
--------------------------------------------------------------------------------
POLYGON
POLYGON EMPTY
SQL> SELECT 'LINE ' as type,SDE.ST_ASTEXT(SDE.ST_LineFromText('LINESTRING EMPTY',4326)) as geom FROM DUAL;
TYPE
-------
GEOM
--------------------------------------------------------------------------------
LINE
LINESTRING EMPTY
SQL> SELECT 'MPOINT ' as type,SDE.ST_ASTEXT(SDE.ST_MPointFromText('MULTIPOINT EMPTY',4326)) as geom FROM DUAL;
TYPE
--------
GEOM
--------------------------------------------------------------------------------
MPOINT
MULTIPOINT EMPTY
SQL> SELECT 'POINT ' as type,SDE.ST_ASTEXT(SDE.ST_PointFromText('POINT EMPTY',4326)) as geom FROM DUAL;
TYPE
-------
GEOM
--------------------------------------------------------------------------------
POINT
POINT EMPTY
SQL> - V
... View more
10-30-2023
12:06 PM
|
1
|
1
|
761
|
IDEA
|
A NIL (zero vertex) geometry is a valid shape type. It is required for some operations (e.g., the result of the intersection of two disjoint features). The shapefile specification permits Nil paired with any other one geometry type as the supported types in shapefiles. How would it be an "enhancement" to remove this capability? - V
... View more
10-27-2023
01:48 PM
|
0
|
0
|
615
|
POST
|
I've seen this behavior in Python often enough. I just assumed it was quirk of how Python operates -- if you don't fill all the values, it uses the value with which the object was initialized (the current time). So I usually combine strptime with a replace: to clear the microseconds property (and to either clear or force a UTC timezone) import datetime
test_str = '2023-10-16T07:50:00'
new_dt = datetime.datetime.strptime(
test_str,'%Y-%m-%dT%H:%M:%S').replace(
microsecond=0,tzinfo=None)
print(new_dt.strftime('%Y-%m-%d %H:%M:%S.%f %Z')) The funny thing is, I can't reproduce the problem in the Python in my Pro 3.1.1 or ArcMap 10.8.2 installs, so maybe that Python "feature" has been cleared. What version of ArcGIS are you using for the ConvertTimeField utility? - V
... View more
10-27-2023
10:35 AM
|
0
|
1
|
535
|
POST
|
Which Python are you using? I've ingested tens of millions of rows in 64-bit Python 2.7 (64-bit Geoprocessing for ArcMap), and processed 40-60 million rows in 64-bit Python 3 (ArcGIS Pro). Both of those VMs had less than 32GiB RAM available. - V
... View more
10-26-2023
07:20 AM
|
0
|
1
|
2635
|
POST
|
Be careful. The polygon area or line length can be in the list of fields. You only need to query one table's columns, so sorting shouldn't be necessary, but you can cross-check to make sure they're all present (again, as a safety thing). - V
... View more
10-23-2023
08:24 AM
|
1
|
0
|
387
|
POST
|
If the data is small enough*, I prefer to cache the array and not use nested cursors. This is especially true with EGDB feature classes, which do not like with nesting. - V *Nowadays, "small enough" is "less than 10-20 million rows".
... View more
10-19-2023
07:09 PM
|
1
|
0
|
444
|
POST
|
Best practice would be to capture the source column names (arcpy.ListFields), replacing the 'Geometry' column with 'Shape@', then using explicit column names for both cursors. Using a wildcard is likely to cause trouble if the tables are altered with a new column. - V
... View more
10-19-2023
09:32 AM
|
2
|
0
|
469
|
POST
|
You can create a field that contains whatever you want to populate, but polygons don't have length, just (2D) perimeter. - V
... View more
10-17-2023
07:31 AM
|
0
|
0
|
475
|
POST
|
For statistical purposes, you should use the same set of points in each environment. This could be done by initializing the random class with same initialization seed. - V
... View more
10-16-2023
10:27 AM
|
0
|
0
|
560
|
Title | Kudos | Posted |
---|---|---|
1 | 3 weeks ago | |
2 | 3 weeks ago | |
1 | 02-21-2024 11:41 AM | |
1 | 02-20-2024 07:41 AM | |
1 | 02-16-2024 07:13 AM |