Select to view content in your preferred language

How to Test Whether A Lot is On a Corner

5497
9
10-25-2011 05:31 AM
ElliotHartley1
Emerging Contributor
I've been using code like the extract below to test whether a lot is on a corner (i.e. has two streetwidth variables greater than 0).

Is there a better way to do this?  I know you can create LotCorners but these are triangular lots that I don't want.

Lot -->
 setback(0.1) {streetSide: nil | remainder : test(comp.index)}

test(compIndex) -->
 case streetWidth(0) > 0 && streetWidth(1) > 0 : building
 case streetWidth(0) > 0 && streetWidth(2) > 0 : building
 case streetWidth(0) > 0 && streetWidth(3) > 0 : building
 case streetWidth(1) > 0 && streetWidth(1) > 0 : building
 case streetWidth(1) > 0 && streetWidth(2) > 0 : building
 case streetWidth(1) > 0 && streetWidth(3) > 0 : building
 case streetWidth(2) > 0 && streetWidth(1) > 0 : building
 case streetWidth(2) > 0 && streetWidth(2) > 0 : building
 case streetWidth(2) > 0 && streetWidth(3) > 0 : building
 case streetWidth(3) > 0 && streetWidth(1) > 0 : building
 case streetWidth(3) > 0 && streetWidth(2) > 0 : building
 case streetWidth(3) > 0 && streetWidth(3) > 0 : building
 else : nil

building-->
 offset(-2, inside)
 extrude(rand(3,15))
9 Replies
MatthiasBuehler1
Deactivated User
hi .. you're using the component index, that's not so good.


I'd try and create a recursion with geometry.nVertices. like this, you could be independent of the actual number of edges per Lot.
0 Kudos
MatthiasBuehler1
Deactivated User
Like so :

attr streetWidth(i) =  0


LotInner --> NIL

Lot -->
 CornerRecursion(geometry.nVertices - 1, 0)
 

CornerRecursion ( edgeID, nStreetEdges ) -->
 case edgeID >= 0 :
  case streetWidth(edgeID) > 0 :
   #print (edgeID)
   CornerRecursion ( edgeID - 1, nStreetEdges + 1 )
  else:
   #print (edgeID)
   CornerRecursion ( edgeID - 1, nStreetEdges )   
 else:
  case nStreetEdges >= 2 :
   IsCornerLot
  else:
   IsNotCornerLot


IsCornerLot -->
 color("#ff0000")

IsNotCornerLot -->
 color("#00ff00")



ok ?
0 Kudos
MatthiasBuehler1
Deactivated User
see screenshot for a result.
0 Kudos
ElliotHartley1
Emerging Contributor
That's fantastic, thank you!
0 Kudos
MatthiasBuehler1
Deactivated User
sure.

the idea itself was actually interesting to wrap in code. I've never thought so far about that corner lots themselves should be isolated, but obviously it makes sense.

it's been good homework.
0 Kudos
JackCurran
Occasional Contributor

Hi! I know a lot of time has passed since this original thread was created, but I'm really struggling with the solution above. The solution is completely logical, and I can follow what the code is intending to do just fine. The only problem is...the streetWidths returned on any lot I run the code on just return 0! I'm missing something, but I'm not sure what. The streetwidth values are there in the Object Attributes in the Inspector when I select the lot, so why isn't the code returning them?!

Can anyone out there help, because this is driving me crazy!!

0 Kudos
CherylLau
Esri Regular Contributor

The rule works for me if I apply it to dynamic lot shapes generated inside street blocks.  Can you be more specific about the problem?  Do you see the streetWidth attr as a rule attribute in the Inspector?  Does rule attribute's value match the value of the object attribute streetWidth?  What is the exact code that returns 0?  What prints if you insert print(streetWidth(0)) as the first line of the Lot rule?  What is your input shape?

0 Kudos
CherylLau
Esri Regular Contributor

Note that the rule only counts whether the lot has two or more edges that border a street.  This means that it won't work in some cases such as when a lot borders streets on two opposite sides but isn't a corner lot.

0 Kudos
JackCurran
Occasional Contributor

Hmm...I am revisiting this now and, inexplicably, the streetWidth attributes are now being picked up. I'm not sure whether it is a system reboot, the update to CityEngine 2019 I performed or (let's be honest) some kind of user error, but at least the attributes are now coming through.

Ultimately, it doesn't look as though it's going to be of use to me, as the streets in my scene can be quite curvy, so any corresponding lot incorrectly gets picked up as a corner lot (as shown below)

Thank so much for your help though!