|
POST
|
Replace line 50 above with line 2 below (it just stores the result in a variable), move the offset parameters to the rest of the parameters for ease of access. # randomly distribute the points inside the cluster boundaries
out_fc = arcpy.management.CreateRandomPoints(output_folder, output_name, cluster_boundaries, None, "NumOfPoints", min_point_distance)
# randomly offset each point
min_offset = 0
max_offset = 2000
with arcpy.da.UpdateCursor(out_fc, ["SHAPE@XY"]) as u_cursor:
for p in u_cursor:
x, y = p
dx = random.randint(min_offset, max_offset) * random.sample([-1, 1], 1)[0]
dy = random.randint(min_offset, max_offset) * random.sample([-1, 1], 1)[0]
new_p = [x + dx, y + dy]
u_cursor.updateRow([new_p]) before: after (with quite high offset values):
... View more
02-10-2023
06:10 AM
|
1
|
0
|
5708
|
|
POST
|
Right, running Mean Center on the Intersection of the points and polygons (for the case field) gives the same result as Dissolving and converting to centroid.
... View more
02-09-2023
01:16 PM
|
0
|
0
|
5671
|
|
POST
|
Be aware that this approach does not guarantee that the centroid is in the polygon!
... View more
02-09-2023
01:12 PM
|
0
|
0
|
5683
|
|
POST
|
Intersect the point and polygon fcs Dissolve the resulting point fc by the polygon id field into a multipoint fc run Feature To Point on that multipoint fc to get the centroids
... View more
02-09-2023
01:07 PM
|
1
|
1
|
5693
|
|
POST
|
A naive approach: create clusters with random point counts until you reach 50k points create random center points for the clusters create buffers with random radii around the cluster centers use these buffers as constraining fc for the Random Points tool Script: import arcpy
import random
# tool parameters
output_folder = ""
output_name = "RandomPointClusters"
constraining_fc = "TestPolygons"
num_of_points = 50000
min_points_in_cluster = 20
max_points_in_cluster = 100
min_cluster_radius = 500
max_cluster_radius = 1500
min_point_distance = 1
# randomly distribute the points into clusters
rest = num_of_points
clusters = []
while rest > 0:
num = random.randint(min_points_in_cluster, max_points_in_cluster)
num = min(num, rest)
clusters.append(num)
rest -= num
print(f"{len(clusters)} clusters will be created.")
# randomly create the cluster centers
cluster_centers = arcpy.management.CreateRandomPoints("memory", "ClusterCenters", constraining_fc, None, len(clusters), min_point_distance)
# randomly create the cluster buffers
sr = arcpy.Describe(constraining_fc).spatialReference
cluster_buffers = arcpy.management.CreateFeatureclass("memory", "ClusterBuffers", "POLYGON", spatial_reference=sr)
arcpy.management.AddField(cluster_buffers, "NumOfPoints", "LONG")
with arcpy.da.InsertCursor(cluster_buffers, ["SHAPE@", "NumOfPoints"]) as i_cursor:
with arcpy.da.SearchCursor(cluster_centers, ["SHAPE@", "OID@"]) as s_cursor:
for cluster_center, cluster_id in s_cursor:
cluster_radius = random.randint(min_cluster_radius, max_cluster_radius)
cluster_buffer = cluster_center.buffer(cluster_radius)
num = clusters[cluster_id - 1]
i_cursor.insertRow([cluster_buffer, num])
# clip the cluster buffers with the constraining fc
cluster_boundaries = arcpy.analysis.Clip(cluster_buffers, constraining_fc, "memory/ClusterBoundaries")
# randomly distribute the points inside the cluster boundaries
arcpy.management.CreateRandomPoints(output_folder, output_name, cluster_boundaries, None, "NumOfPoints", min_point_distance) This would be better with irregular cluster boundaries, as now it's very noticeable that they are circles. A random offset for each point could do the trick, too.
... View more
02-09-2023
12:47 PM
|
1
|
1
|
5816
|
|
POST
|
Hmm, there was a post here this morning, but when I refreshed right now, it disappeared, maybe you deleted it? Anyway, I remember that there was a problem with the key fields you assigned in your code. So, just to be clear (which I wasn't in my original answer): near_features is the polygon fc. It has a field that acts as primary key: it uniquely identifies each polygon (like OBJECTID). Assign this field's name to near_key. In my example script, this field would be Polygons.id in_features is the point fc. It has a field that links to the primary key of the polygon fc. Assign this field's name to in_key. In my example script, this field would be Points.polygon_id I think I read "point_id" somewhere in your code, that seemed wrong. Sorry that I wasn't very clear on that point. Feel free to ask questions, of course.
... View more
02-09-2023
05:29 AM
|
0
|
1
|
2518
|
|
POST
|
if COMPLETE and COMPLETE.altered: You're not checking the value of the parameter, you're checking if a non-empty value is assigned to the variable COMPLETE. Take a look at this code and its output: test_values = [False, 0, None, "", [], ()]
for value in test_values:
msg = str(value) + ": "
if value:
msg += "TRUE"
else:
msg += "FALSE"
print(msg) False: FALSE
0: FALSE
None: FALSE
: FALSE
[]: FALSE
(): FALSE So, your if COMPLETE: could also be written as if COMPLETE not in [False, 0, None, "", [], ()]: # and maybe some other values, too and that will always return False, because COMPLETE has a value (it is an arcpy.Parameter). Instead, you have to check the value of that arcpy.Parameter: if COMPLETE.value:
... View more
02-09-2023
05:15 AM
|
1
|
1
|
2616
|
|
POST
|
Probably not the most efficient way, but it gets the job done: // define the zoning layers and their zone fields
var zoning_layers = [
FeaturesetByName($datastore, "TestPolygons", ["*"], false),
FeaturesetByName($datastore, "TestPolygons", ["*"], false),
FeaturesetByName($datastore, "TestPolygons", ["*"], false),
FeaturesetByName($datastore, "TestPolygons", ["*"], false),
]
var zoning_fields = [
"TextField",
"IntegerField",
"GlobalID",
"OBJECTID",
]
var zones = []
// loop through the layers
for(var i in zoning_layers) {
// get the first intersecting zone, abort if none found
var zone = First(Intersects(zoning_layers[i], $feature))
if(zone == null) { continue }
// append the zone's zoning field value
Push(zones, zone[zoning_fields[i]])
}
// concatenate and return
return Concatenate(zones, ", ")
... View more
02-07-2023
10:40 PM
|
0
|
1
|
1617
|
|
POST
|
Feature To Point generates centroid points for polygons.
... View more
02-07-2023
09:19 AM
|
2
|
0
|
3020
|
|
POST
|
Try converting the existing date to Number: if (IsEmpty($feature.SurveyDate)) {
return Now()
}
return Number($feature.SurveyDate)
... View more
02-07-2023
01:15 AM
|
0
|
1
|
1447
|
|
POST
|
Switch tha language to Arcade, use this expression: var titles = ["ZEE", "OP", "Vast", "Lok"]
var values = [
$feature.Km_paal_in_zee,
$feature.Oriëntatiepaal,
$feature.vaste_plaatsnaam,
$feature.Lokale_benaming,
]
var lines = []
for(var i in titles) {
if(!IsEmpty(values[i])) {
var line = `${titles[i]}-<BOL><CLR red="21" green="47" blue="255">${values[i]}</CLR></BOL>`
Push(lines, line)
}
}
return Concatenate(lines, TextFormatting.NewLine)
... View more
02-07-2023
01:11 AM
|
1
|
1
|
2637
|
|
POST
|
@HusseinNasser2 I don't have access to the beta. The example above was done in 3.0.3
... View more
02-06-2023
07:35 AM
|
0
|
0
|
5542
|
|
POST
|
I believe ArcGIS uses default values when it verifies Arcade expressions. That means that it often doesn't find anything with functions like FeaturesetByRelationshipName() and Filter() adn returns empty featuresets. In your case, it returned an empty fs with FeaturesetByAssociation(), so your globalIDs array is empty, which leads to your query being "GlobalID IN ()" which is invalid. Try guarding against empty featuresets: var contentRows = FeatureSetByAssociation($feature, "content");
var globalIds = [];
var i = 0;
for (var v in contentRows) {
globalIds[i++] =v.globalId
}
var deviceCount = 0 // set a defaul value
if(i > 0) { // only enter this block if contentRows is not empty
var asset_Array=[27,26]
var deviceClass = FeatureSetByName($datastore, "CommunicationsJunctionObject");
var devicesRows = Filter(deviceClass, "globalid in @globalIds");
deviceCount = Count(deviceRows) // overwrite the default value
}
return{'errorMessage':deviceCount}
... View more
02-06-2023
04:51 AM
|
1
|
1
|
2285
|
|
POST
|
Ah, I see now that I misunderstood your second question. I see this behavior in a file gdb. While the Console() command ouputs the right message (empty geometry and only one field [plut OBJECTID]), the error message prints the complete feature, although I didn't load the geometry and the other fields. var fs = FeatureSetByName($datastore, "TestLines", ["IntegerField"], false);
Console(First(fs))
return {errorMessage: Text(First(fs))} In an Enterprise GDB, it works as expected: var fs = FeatureSetByName($datastore, "Bauwerke", ["BauwerkID"], false);
Console(First(fs))
return {errorMessage: Text(First(fs))} @HusseinNasser2 , any insights?
... View more
02-06-2023
04:35 AM
|
0
|
5
|
5558
|
|
POST
|
To post code: I am trying to filter the database by using profile variable $Map in ArcGIS Pro Attribute Rules You can't use $map in attribute rules. Attribute rules work on the database level and can be triggered from different maps (or even without a map at all), so it doesn't make sense to rely on a featureset in a specific map. Instead, use $datastore if the featureset is in the same database. If not, you have to publish it and load it in using FeaturesetByPortalItem(). I want only to get the field room from this table, but when printing the results all fields are there You return the whole feature, so every field is printed. Instead, return only a specific field: var test="{4EC98101-67C4-44FC-8BF5-C7DF9393AB73}"
var deviceClass = FeatureSetByName($datastore, "CommunicationsJunctionObject");
var devicesRows = Filter(deviceClass, "GLOBALID = @test");
var device = First(devicesRows)
var room = IIf(device == null, "nodevice found", device.room)
return{"errorMessage":"FeatureSetByAssociation: " + room};
... View more
02-06-2023
12:05 AM
|
1
|
8
|
5589
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-30-2023 09:57 AM | |
| 1 | 05-18-2023 12:51 AM | |
| 1 | 03-05-2023 12:46 PM | |
| 1 | 12-07-2022 07:01 AM | |
| 1 | 06-21-2022 08:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-03-2024
06:14 PM
|