|
POST
|
Maybe asset is actually a feature class, not a layer? Selection doesn't work on feature classes. If that's not it, you should probably post the whole script, so that we can see what's going on before the two lines you posted. To post code:
... View more
08-16-2022
12:45 AM
|
0
|
3
|
2658
|
|
POST
|
Go into the symbology pane and create a ring symbol. Switch to the Structure tab and duplicate the symbol layer. Switch back and change the attributes of the duplicated layer. Repeat as needed.
... View more
08-16-2022
12:29 AM
|
0
|
1
|
1707
|
|
POST
|
Code screenshots are hard to work with, because we can't easily test what you did. To post code as text: Passing a simple list of coordinate tuples to the InsertCursor seems to be a shortcut that is only valid for singlepart features. Personally, I always create an arcpy.Geometry object and pass that. test_fc = arcpy.management.CreateFeatureclass("memory", "test_fc", "POLYLINE", has_z="YES", spatial_reference=4326)
coordinates = [
[-117.2000424, 34.055514, 1],
[-117.2000788, 34.0592066, 2],
[-117.1957315, 34.0592309, 5],
[-117.1956951, 34.0556001, 2],
]
with arcpy.da.InsertCursor(test_fc, ["SHAPE@"]) as cursor:
points = [arcpy.Point(c[0], c[1], c[2]) for c in coordinates]
line = arcpy.Polyline(arcpy.Array(points), has_z=True, spatial_reference=4326)
cursor.insertRow([line]) multipart_coordinates = [
[coordinates[0], coordinates[1]],
[coordinates[2], coordinates[3]],
]
with arcpy.da.InsertCursor(test_fc, ["SHAPE@"]) as cursor:
parts = arcpy.Array([
arcpy.Array([
arcpy.Point(p[0], p[1], p[2]) for p in part
])
for part in multipart_coordinates])
line = arcpy.Polyline(parts, has_z=True, spatial_reference=4326)
cursor.insertRow([line])
... View more
08-15-2022
02:26 AM
|
0
|
0
|
2399
|
|
POST
|
You're misunderstanding the When function. When() doesn't work on feature sets. It takes multiple booleans and objects and returns the object following the first true boolean. var x = 1
// this will return 25
return When(x == 0, "a", x == 1, 25, x == 2, "z", "default") Other things: the dollar sign denotes global variables like $feature, $map, or $layer. You can't just put it in front of custom variables. In most programming languages, "=" is assignment ("var x = 3"). To test for equal, use "==" ("x == 3" -> true) FS is a FeatureSet, a collection of Seatures. You can't call a field on a FeatureSet, only on the separate Features. in your dictionary, you have a different name for the field in the fields declaration and the feature attributes. To solve your problem, create an empty dictionary, then loop through the FeatureSet and Push the corrected values into the feature array: var port = "https://--------------.arcgis.com"
var itemID = "---------------------------------"
var layerID = 3
var fields = ['AGE']
var geo = False
// Set up the FeatureSet with which to call:
var FS = FeatureSetByPortalItem(Portal(port), itemID, layerID, fields, geo)
// return the set of features to use within indicator:
var newagesdictionary = {
'fields': [
{ 'name': 'age_recalc', 'type': 'esriFieldTypeInteger'}
],
'geometryType':'',
'features':[]
}
for(var f in FS) {
var new_age = When(f.AGE == 'BB', '0', f.AGE == 'NN', '0', f.AGE)
var new_feature = {'attributes': {'age_recalc': Number(new_age)}}
Push(newagesdictionary.features, new_feature)
}
var recalcagedict = FeatureSet(Text(newagesdictionary));
return recalcagedict
... View more
08-14-2022
11:32 PM
|
0
|
0
|
1186
|
|
POST
|
Again, no idea how to do it in the JS API. Arcade has the functions ToUTC() and ToLocal(), which convert your local date to UTC or vice versa.
... View more
08-14-2022
10:41 PM
|
0
|
1
|
2837
|
|
POST
|
code block: def get_factor(class_name):
if class_name == "Alfalfa":
return 100
if "Wheat" in class_name:
return 80
return 0 DollarPerAcre = get_factor(!CLASS_NAME!) * !Acres!
... View more
08-12-2022
12:24 PM
|
0
|
0
|
1129
|
|
POST
|
OK, so does this do what you want? You can use this as Attribute Rule or in the Field Calculator: // get all buildings in block
var block_id = $feature.BlockID
var buildings = Filter($featureset, "BlockID = @block_id")
// get the distances between all buildings
var distances = []
for(var b1 in buildings) {
var building_id = b1.BuildingID
var other_buildings = Filter(buildings, "BuildingID <> @building_id")
for(var b2 in other_buildings) {
Push(distances, Distance(b1, b2))
}
}
// return the smallest distance between buildings in the block of the current building
return Sort(distances)[0] (If you have many buildings in a block, this will take some time!)
... View more
08-12-2022
08:21 AM
|
0
|
2
|
2609
|
|
POST
|
Yeah, it's your id values. Some of them contain apostrophes/single quotes. These characters are used in SQL to denote string values, so the where clause got corrupted. For example, in this part, it recognizes the commas as string values and everything you actually want to select as mumbo jumbo: (for the record, putting the where clause in there froze my PC for over 5 minutes. Can't imagine why, it's only 404.000 characters long :D) Well, turns out there is only one id with an apostrophe: [i for i in existing_ids if "'" in i]
["YOUNG'S POND"] So either fix that id or make the code safer. Online search suggests that to escape a single quote in SQL, you just put another single quote in front of it. So the code gets a tiny bit more complicated (replace call in line 12): import arcpy
target_class = "C:\\Rex\\WQM_STATIONS_FINAL\\WQM_STATIONS_DELTA_LOAD.gdb\\WQM_STATIONS_FINAL"
append_class = "C:\\Rex\\WQM_STATIONS_FINAL\\WQM_STATIONS_DELTA_LOAD.gdb\\WQM_STATIONS"
id_field = "STATION_ID"
# read the ids that are already in the target class
existing_ids = [row[0] for row in arcpy.da.SearchCursor(target_class, [id_field])]
# create a SQL where clause "STATION_ID NOT IN (1, 2, 3)"
if isinstance(existing_ids[0], str):
id_list = ["'{}'".format(i.replace("'", "''")) for i in existing_ids]
#print id_list
else:
id_list = ["'{}'".format(i) for i in existing_ids]
#print id_list
where_clause = '{} NOT IN ({})'.format(id_field, ", ".join(id_list))
print (where_clause)
# create a layer of all append features that are not in the target class, append
append_layer = arcpy.management.MakeFeatureLayer(append_class, "append_layer", where_clause)
arcpy.management.Append(append_layer, target_class) And it works! (And then the Append throws an exception, because your fields don't match, but that's besides the point...)
... View more
08-12-2022
08:01 AM
|
1
|
1
|
3576
|
|
POST
|
What I suggested should work, but in hindsight it seems overly complicated. I just copied code from my attribute rules where I need access to the closest feature and its attributes. If you just need the shortest distance and have a feature class like this: Then you can get the distance to the closest building in the same block like this: // get the whole featureset
var buildings = $featureset
// get the $feature's BuildingID and exclude it from the featureset
// also get its BlockID and only include buildings from the same block
var building_id = $feature.BuildingID
var block_id = $feature.BlockID
var filtered_buildings = Filter(buildings, "BuildingID <> @building_id AND BlockID = @block_id")
// get the distance between the $feature and each other building in the same block
var distances = []
for(var b in filtered_buildings) {
Push(distances, Distance($feature, b))
}
// return the shortest distance
return Sort(distances)[0] If this doesn't work or you need something else, then you'll have to describe it better. What value do you want to get? Is this for a Popup, Attribute Rule, Field Calculation, something else?
... View more
08-12-2022
05:32 AM
|
0
|
4
|
2621
|
|
POST
|
Yeah, Python toolboxes have some weird quirks you have to work around. Personally, I've never gotten Parameter.altered to work. I always do the check myself by comparing the current parameter value to the previous value stored in a variable. But it doesn't work with a variable of the Tool class. Something to do with the internal conversion into C code, I guess. My workaround for this: Create an empty class in the toolbox file. Use this class to store variables from your tool classes: # Toolbox.pyt
class ABC():
"""This class is used to store tool variable."""
pass
class FieldNames(object):
def __init__(self):
self.label = "FieldNames"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
fc = arcpy.Parameter(
displayName="fc",
name="fc",
datatype="GPFeatureLayer",
parameterType="Required",
direction="Input")
names = arcpy.Parameter(
displayName="field names",
name="fields",
datatype="GPString",
parameterType="Required",
direction="Input"
)
names.multiValue = True
# set the variable. Doesn't work with self!
ABC.fc = ""
params = [fc,names]
return params
def isLicensed(self):
return True
def updateParameters(self, parameters):
# instead of Parameter.altered, do the check yourself
if ABC.fc != parameters[0].valueAsText:
ABC.fc = parameters[0].valueAsText
parameters[1].values = [field.name for field in arcpy.ListFields(ABC.fc)]
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
fc = parameters[0].valueAsText
fields = parameters[1].valueAsText
arcpy.AddMessage(f"fc: {fc}")
arcpy.AddMessage(f"fields: {fields}")
class Toolbox(object):
def __init__(self):
self.label = "test"
self.alias = "test"
self.tools = [FieldNames]
... View more
08-12-2022
12:58 AM
|
1
|
0
|
2966
|
|
POST
|
I don't know about the Javascript API, but in Arcade (which seems to share a big part of the feature set declaration with the JS API), you have to supply an integer (epoch, number of milliseconds since 1970-01-01) to the date field. This is how it would look in Arcade: Number(Date(2019, 4, 25))
... View more
08-11-2022
11:27 PM
|
0
|
4
|
2885
|
|
POST
|
Syntax looks fine. Could maybe be something with your weird id format. Is the field in the append class really called STATION_ID? Are you able to use the query in the Select By Attributes tool? Can you post the gdb, either here or in a pm?
... View more
08-11-2022
11:15 PM
|
1
|
3
|
3587
|
|
POST
|
There should be settings for the category and value axes (literal translation from German, no idea what they are actually called in English) which have a title attribute:
... View more
08-11-2022
07:18 AM
|
0
|
1
|
1510
|
|
POST
|
To insert code: It might be because you're inserting an invalid geometry into the FeatureSet. You're calling Geometry() on a Dictionary, which results in a null value. So you return a point FeatureSet with one row that has an invalid geometry. A FeatureSet isn't required to have a geometry column, it can also be a simple table. Try this: // create data schema
var dict = {
'fields': [
{'name': 'number', 'type': 'esriFieldTypeInteger'}],
'geometryType': '', // no geometry
'features': []
};
// fill the data schema with the data
dict.features[0] = {
'attributes': {'number': total}
};
// return the featureset
return FeatureSet(Text(dict));
... View more
08-11-2022
12:13 AM
|
0
|
1
|
1554
|
|
POST
|
You could use Graduated Colors, but that wouldn't be dynamic. You could probably rig something up with a calculation attribute rule. Add an integer field. When you insert/delete a feature or when you update the Sequence field, get the minimum Sequence value of the featureset, then update the new field of all features to 0 or 1, depending on whether their Sequence is the lowest. Symbolize with Unique Values on the new field. It might be easier to just add the layer to the map a second time and set its definition query: Sequence IN (Select MIN(Sequence) AS SmallestSequence FROM DatabaseName.DataOwner.TableName) This will only show the feature(s) with the smallest Sequence value. Then you can use that layer to highlight these features:
... View more
08-11-2022
12:01 AM
|
0
|
0
|
978
|
| 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
|