Set street width based on (non numeric) object attribute

3070
4
02-05-2014 01:23 PM
Tom-PierreFrappé-Sénéclauze
New Contributor II
Hi folks,


I understand that the streetWidth shape parameter is generated when the shape is created.

But is there no way to change it dynamically through CGA coding?

I'd like to set it based on the type of road, as specified in the original network data attribute table; ie 'arterials' would set street width to 20m, 'collectors' to 16 m, etc.

Any suggestions?

thanks!
Tom
0 Kudos
4 Replies
MatthiasBuehler1
Frequent Contributor
Hi !


Street graphs create blocks, blocks create street and lot shapes, with respective attribution.

CGA ALWAYS starts with a shape and it's attributes > CGA can not alter street graphs or blocks.


Thus, what you need is to set up the system so that the streets inherit attributes down to the shapes, for use in CGA. ( I know, this may sound a bit abstract at first, before playing around with it. )

An other thing you can in CGA is to check the 'width' of a street shape based on the actual dimension with checking
geometry.du / .dv, a specific CGA function that gives back the length and width of the geometry of a shape.


Otherwise, Python can be used to get and set attributes.
E.g. if a street segment is wider than 20 meters, set the street shapes' attribute 'street type' to 'hugeFrigginBoulevard', ...

There's many options to reach what you need.

Matt
0 Kudos
NathanBrigmon
New Contributor
Hi Matthias,

I have been experimenting with setting the street width based on layer attributes like this:

width              = getObjectAttr("StreetType", false)

streetWidthDefault = 7

attr streetWidth =
    case width == "Alley" : 4    * streetscale
    case width == "Arterial" : 12     * streetscale
    case width == "Collector" : 8     * streetscale 
    else           : streetWidthDefault


Unfortunately, this same logic hasn't been working for sidewalk widths... any suggestions?

Here is part of my code:

sidewalkr       = getObjectAttr("SidewalkR",false)

attr sidewalkWidthRight = 
    case sidewalkr == "Alley" : 2     * streetscale
    case sidewalkr == "Arterial" : 6     * streetscale
    case sidewalkr == "Collector" : 4     * streetscale 
    else           : streetWidthDefault


For some reason, it has been returning 0 for my sidewalkWidthRight.
0 Kudos
MatthiasBuehler1
Frequent Contributor
Hi,

but for the street widths it works ?

lemme know..

m.
0 Kudos
NathanBrigmon
New Contributor
Hi,

but for the street widths it works ?

lemme know..

m.



Yes, it was a strange thing, but I figured out the answer. Not sure why I had to take this route, but I needed to set the attribute source to "OBJECT", because it wasn't completely making the connection. So, I added a few extra lines of code as a fail-safe:


        ce.setAttributeSource(streetsegment, "/ce/street/streetWidth", "OBJECT")
        ce.setAttributeSource(streetsegment, "/ce/street/sidewalkWidthLeft ", "OBJECT")
        ce.setAttributeSource(streetsegment, "/ce/street/sidewalkWidthRight", "OBJECT")

 


I've made a little progress in my python understanding and have changed my approach. After first selecting the objects from the scene with my specified attributes, I then run the above lines of code in a new context:

    selectedSegments = ce.getObjectsFrom(ce.selection())
    for streetsegment  in selectedSegments:
        ce.setAttributeSource(streetsegment, "/ce/street/streetWidth", "OBJECT")
        ce.setAttribute(streetsegment , 'streetWidth', W1)
        ce.setAttributeSource(streetsegment, "/ce/street/sidewalkWidthLeft", "OBJECT")
        ce.setAttribute(streetsegment , 'sidewalkWidthLeft', W2)
        ce.setAttributeSource(streetsegment, "/ce/street/sidewalkWidthRight", "OBJECT")
        ce.setAttribute(streetsegment , '/sidewalkWidthRight', W3)
0 Kudos