Working with Arrays and Lists

836
8
01-12-2023 02:10 AM
Kevin_Z
New Contributor II

Hi 

Would like to know how to work with arrays and lists, it seems to me that they can only work in a global setting through declaration, and not within a function. So is there a way to work with arrays and lists in a function similar to working with constants and integers.

As such through a recursive setback; the length of the face edge changes  after each iteration, this can be shown via printing the array after a setback iteration. What I would like to do is to store  the results of each iteration onto a fresh array 

 

Also is there a way to write to the edge attributes array set via cga?  as edge attributes can be edited manually?

0 Kudos
8 Replies
JonasObertuefer
Esri Contributor

Good morning @Kevin_Z,

Not sure if I 100% understand what you want to achieve, a code snippet or screenshot would probably help 🙂

There was a similar question a couple of days ago where you will find an answer with a basic example where an array is passed as an argument for each iteration.

Another way would be to define an attribute and then set the value using the set operation on each iteration. For a code snippet see second example on the doc page of the set operation.

hope this helps!

Cheers
Jonas

0 Kudos
Kevin_Z
New Contributor II

Thank you Jonas for replying, as you can see from the image below , the console results of the rectangle is something of the first step I want to achieve as the intial state of the polygon have the same amount of edges as the final stage and that there are two arrays showing there initialand final edge lengths. But in real life the polygon we get are  more like the polygon on the right and hence there is more stages in between to reach the final stage. Hence I would like to know how to store the arrays of the inbetween stages.While having the ability to reuse it t later stages or until it is overwriten.

sample.png


Attached are the sample file thats similar to what I am currently using. Using set attribute operation to create a simple lookup table, but it is only good if the polygon doesnt have a many edges, and that at the later stages the extruded level are limited to single digits. Other wise it will be very messy and creates so much redundancies handful.

So if an array can be used in a function(rather than as a global declearation) while its result is global and be used any level child of the parent polygon like the Set operation for constants and floats, 

as such:

arrayA= comp(fe) { all : scope.sx

@StartRule

saveArray-->

cleanupGeometry(all, 0)

set( arrayB, arrayA)

godosomethingelse.

X.

sample1.png

i

 

The Second question 


My understand of in order to use the setback per edge we must first edit the edge attribute function  

and for a hand full of test samples working with the way as suggested by the page would be ok.

However when trying to use  it on a large scale of dataset of say 50K -500k polygon set with an average of 4-8 edges per polygon, where do you think it will be sitting on this graph?

 

Hence my second question of; is there any code based way of altering the edge attribute array?

0 Kudos
JonasObertuefer
Esri Contributor

Hi again @Kevin_Z,

Below you find a code snippet which gets you the same results as in your rule. Instead of going through each value recursivly it just passes on the return of ar_length as parameter:

lot--> 
    cleanupGeometry(all, 0) 
    innerRectangle(edge) { shape : LoType(ar_length) X. | remainder = NIL }

LoType(a) -->
    setbackToArea(area, minDists, maxDists)
    	{ all       = NIL   |
          remainder = showit(a,ar_length) X. }      

showit(a,b) --> 
	print(a)
    print(b)
    print(a.-b)

Note: a.-b is calculating array a minus array b (see Array type operators)

Hope this helps you to point you in the right direction, alltough I still don't quite understand how the final result should look like...

Regarding your second question: setbackPerEdge operation is not depending on any edge attributes, you simply set the setback distance for each edge of the current shape indvidually.

Cheers,
Jonas

0 Kudos
Kevin_Z
New Contributor II

Hi Jonas

Thanks for the solution, it didnt really work for my case, it crashes CE without as such as a notice. As result I think I might have flooded the memory. The purpose of this exercise really trying to find the resultant setback distance from edge  in order to calculate setbacks for extrudes to allow sky view.

As for the second question can you please provide a proper setbackPerEdge  example for  the white polygon in the image below, as each colour representing  zone requires a specific setback distance.  Here where none of the setback selectors have a solid relationship with the adjacent polygon. except for manually changing the edgeAttr function

zoning.png

0 Kudos
JonasObertuefer
Esri Contributor

Maybe you have to split up your dataset in smaller parts then? Did you got any error message in the log? Anotherway is to do the shape cleanup before applying any rule using "Shapes -> Cleanup shapes..."  or via python.

Here is a basic example of setbackPerEdge:

const setbackDistance = [1,3,6,2,1.5,2] // connect this attribute to the object attribute on your shape with the same name
dist = setbackDistance[comp.index] // or edgeAttr.getFloat() when you want to use edge attributes

Lot --> setbackPerEdge(dist) { all = Green | remainder = Blue}

when getting the distance from an object attribute you need to make sure that you define the first edge accordingly.

Hope this helps

Best,
Jonas

0 Kudos
Kevin_Z
New Contributor II

Thanks Jonas 
I think the first question was resulted from a bug, that CE doesnt show street direction correctly after Inner Rectangle and convexify function

for the second question I just have to make sure that the I can create a list from Arcpro for each polygon then I'd able to use the comp index as the setback relationship?

0 Kudos
JonasObertuefer
Esri Contributor

Did you do a matching comp split afterwards? The sampling only works properly when there is something to sample in the outwards direction the face/edge is pointing. If you look at bottom three example in the cga ref about edgeAttribute functions the concept should become clearer.


for the second question I just have to make sure that the I can create a list from Arcpro for each polygon then I'd able to use the comp index as the setback relationship?

In theory yes but it could be that the relation from your list is not the same in CE and pro, because the vertices/edges order is the otherway around. So when importing from pro the first edge will be matched to the first edge of pro, but the others are different:

verticeAndEdgesOrderDifferenceBetweenCEandPro.png

 

0 Kudos
romainjanil
New Contributor III

combination of set() setElems() and with are indeed the way to go for this kind of stuff. You can do a lot of geometrical calculation in some kind of loop, iterating on the initialShape, storing calculated values in arrays trough comp(), sets feeding arrays, incrementing, resetGeometry and eventually exit the loop when condition are met

0 Kudos