|
POST
|
I have edited the model to work as intended, please review comments in model.
... View more
01-17-2024
03:13 AM
|
2
|
0
|
3134
|
|
POST
|
My apologies I missed that you wanted the top four values. I'm not sure (but I could be wrong) that a file geodatabase can support the functions that would allow you to answer this question and you need to approach it in a two-step approach in modelbuilder, this how I would have done it. I show this below, in my example I am processing a layer called ORN: The Calculate Value tool is set up as-is, note it returns double: The code block is: def Fourth(layer):
# You need to set field to the appropriate field
field = "SourceID"
s = set()
with arcpy.da.SearchCursor(layer, field) as cursor:
for row in cursor:
if row[0] is not None:
s.add(row[0])
l = sorted(s, reverse=True)
ml = l[0:4] # first 4 values in sorted list
mv = min(ml) # Get min value
return mv The select by attribute tool is: This logic will select the top four values in the field sourceID, be aware that the selection may return a selection greater than 4 if you have duplicate values in your field. Also underlying assumption of the code is that you have a minimum of 4 unique values in your field.
... View more
01-16-2024
03:54 AM
|
1
|
2
|
3181
|
|
POST
|
As long as your data is in a file geodatabase (so not a shape file) you can use a subquery to answer this. An example is shown below, in this example ORN is the layer.
... View more
01-15-2024
06:21 AM
|
2
|
0
|
3335
|
|
POST
|
No, I came to the conclusion its some sort of bug based upon number of unique values, so my code just traps the error and fails gracefully.
... View more
01-15-2024
06:07 AM
|
0
|
1
|
2815
|
|
POST
|
Good find! That is hard to find on the esri github site. What blows my mind is that it appears to be the only sample in VB...
... View more
12-13-2023
08:14 AM
|
0
|
1
|
3052
|
|
POST
|
Hi, Thanks for the pointer to the website. I had actually seen this thread before I posted (i.e. had done my research) and followed the link to the code conversion website and tried their example; problem was is when you paste it into visual studio 2022 it throws an error but gives no real indication why. In my random stumbling around in the vastness of the internet I had seen some comment, probably on this forum, about what seems to be an undocumented addition to the code that needs to be done if you are developing a button for the ArcPro ribbon and that's the inclusion of the command "Async" in the OnClick Sub declaration. I've posted the solution over on GIS StackExchange but provide it here too. It provides a simple VISUAL BASIC template for building code that requires running as a QueuedTask. Protected Overrides Async Sub OnClick()
' Code assumes layerfile is referencing a geodatabase featureclass.
Dim b As Boolean
b = Await QueuedTask.Run(Function()
' Connect to layer file
Dim sLayerFilePath As String
sLayerFilePath = "c:\scratch\ORN2.lyrx"
Dim lyrDoc As LayerDocument
lyrDoc = New LayerDocument(sLayerFilePath)
' Create a CIM layer document object
Dim cimLayerDoc As CIMLayerDocument
cimLayerDoc = lyrDoc.GetCIMLayerDocument
' Create a CIM Feature Layer object
Dim cimFeaturelyr As CIMFeatureLayer
cimFeaturelyr = CType(cimLayerDoc.LayerDefinitions(0), CIMFeatureLayer)
' Create a CIM Standard Data Connection
Dim cimSDCon As CIMStandardDataConnection
cimSDCon = CType(cimFeaturelyr.FeatureTable.DataConnection, CIMStandardDataConnection)
' Create a full path name string to feature class
Dim sPath As String
Dim sFC As String
sPath = cimSDCon.WorkspaceConnectionString
sFC = cimSDCon.Dataset
Dim sFullpath As String
sFullpath = sPath & "\" & sFC
sFullpath = sFullpath.Remove(0, 9) ' Removes DATABASE= from start of string
MsgBox(sFullpath, MsgBoxStyle.Exclamation, "Feature class Path")
Return True
End Function)
End Sub If there is anyone from the ESRI documentation team reading this, it would be good if you expand your snippets on the GITHUB site to include some sample code in Visual Basic. Why has ESRI abandoned VB? When you go to the esri git hub site and search for code language in VB it returns nothing!
... View more
12-13-2023
07:43 AM
|
0
|
3
|
3065
|
|
POST
|
Hi I'm hoping someone from esri can shed some light on some simple coding style. As requested in this idea there is a remarkable lack of sample code in Visual Basic. I've spent much of my career using VB and ArcObjects in ArcMap and now facing the challenge of developing in ArcPro. I would like to avoid having to sink months/possibly years into becoming proficient in c# when I know VB! I understand that beneath the hood ArcPro is a very different beast requiring different coding styles because of its multi-threaded nature and that many things have to be done differently. That's OK when simple, easy to digest samples are provided to fast track ones self. I've discovered that many of the objects I need to use must be run in a queuedtask but all the examples on the esri github site are all in the cryptic c# language. I have some simple code that opens a layerfile on a onclick of a button. I cannot for the life of me work out the syntax that must be used in the line QueuedTask.Run(). Friend Class Button1
Inherits Button
Protected Overrides Sub OnClick()
' How To complete the Next line?
Await QueuedTask.Run()
End Sub
Private Function myCode() As LayerDocument
Dim sp As String
sp = "c:\scratch\mydata.lyrx"
Dim ld As LayerDocument
ld = New LayerDocument(sp)
Return ld
End Function
End Class Can someone show how this code should be written and best practise?
... View more
12-12-2023
07:04 AM
|
0
|
6
|
3168
|
|
POST
|
This does seem like a bug, I can replicate the issue too. Set it as line then it defaults back to point. If you want this fixed you need to contact ESRI support and log it as a bug and point them to this thread. I did do the following, exposed the output event table properties as a parameter, this allowed the tool to run, that might help?
... View more
12-04-2023
07:05 AM
|
0
|
0
|
1785
|
|
POST
|
I would suggest you explore the Pivot Table tool then do a row sum to get that final field.
... View more
12-01-2023
06:33 AM
|
1
|
1
|
835
|
|
POST
|
Without showing your model this is hard to answer, best shot in the dark guess is you have an element in your model that you are feeding into that parameter and that's overriding it?
... View more
12-01-2023
06:28 AM
|
0
|
0
|
1803
|
|
POST
|
I would feed that table into a select by attribute tool and select rows where Percent Is Null. The output of that tool is a table\featureclass with a selection, that simply feeds into a calculate field tool and you set it to zero. Remember all geoprocessing tools honour selections first, if nothing is selected then the whole dataset is processed.
... View more
12-01-2023
06:22 AM
|
1
|
0
|
1838
|
|
POST
|
You can do what you want, I have just tried to provide you with clear instructions so you get the overall logic of what you need to do. How you access your layers is up to you. The index error is likely because you have failed to provide the correct map\layer names?
... View more
12-01-2023
03:29 AM
|
1
|
1
|
2409
|
|
POST
|
I don't believe the variant of SQL used in ArcPro supports regular expressions in the Select by Attribute tool. You can still use regular expressions but you need to step through your data with a search cursor, then update the selection set. I provide the code below: # Import modules
import arcpy
import re
# Initialise objects
layername = "p3"
mapname = "ORN"
fields = ["OBJECTID", "name"]
oids = list()
exp = '[A] \d+'
# Get layer object
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps(mapname)[0]
l = m.listLayers(layername)[0]
# Step through layer using regexp to test text in field
with arcpy.da.SearchCursor(l, fields) as cursor:
for row in cursor:
oid = row[0]
text = row[1]
mo = re.search(exp, text)
if mo is not None:
oids.append(oid)
# Set selection set for layer object
l.setSelectionSet(oids, "NEW")
... View more
12-01-2023
02:48 AM
|
2
|
1
|
2421
|
|
POST
|
@gis_KIWI4 offers a solution that will guarantee that empty polygons are given a value, but which one? In their screen shot there are clearly two polygons adjacent to polygons with differing values. So as the code runs now it simply overwrites with the last visited polygon. If that is sufficient then OK but you might want to explore the Polygon Neighbours tool to help quantify the importance of adjacency by shared boundary length?
... View more
11-28-2023
07:32 AM
|
0
|
0
|
1223
|
|
DOC
|
Reckon you could add a row to your table indicating level of supporting for source code encryption?
... View more
11-28-2023
07:21 AM
|
0
|
0
|
1523
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | a week ago | |
| 1 | 12-03-2025 04:30 PM | |
| 1 | 12-03-2025 04:06 PM | |
| 1 | 12-03-2025 04:17 PM | |
| 1 | 12-02-2025 07:05 AM |
| Online Status |
Offline
|
| Date Last Visited |
Wednesday
|