graph network layer attributes not mapping

1751
2
03-26-2014 04:10 PM
ChristianGass
New Contributor
Hello,

I'm attempting to implement a custom layer attribute rule for graph networks, but am running into some trouble. I modified the ce.lib\shp.ceattr file so I could automatically adjust graph network parameters from specific shapefile attributes (generated through a schema I regularly use).

The street width adjusts, but the sidewalk widths don't. Even if I remap the attributes directly to the shapefile, where I know there are values > 0 (instead of relying on an expression in the rule), still no go. The attached image shows how it looks in CE.

Other than adding a new attribute for the new landWidth parameter, I haven't changed anything since implementing this successfully code in version 2012.1...?

The layer attribute rule is as follows:

// Shape Tag Mapping

streetscale = 1  // street width scale factor

width = getObjectAttr("width")
swide = getObjectAttr("sidewalk")
lwide = getObjectAttr("VEH_WIDE")

check = getObjectAttr("ROW_WIDE")

default_road = 0
default_side = 0

attr streetWidth = 
 case check == 0:
  default_road * streetscale 
 else:
  width * streetscale
  
attr sidewalkWidthLeft = 
 case check == 0: 
  default_side * streetscale 
 else:
  swide * streetscale
  
attr sidewalkWidthRight =
 case check == 0: 
  default_side * streetscale 
 else:
  swide * streetscale
  
attr laneWidth = 
 case check == 0:
  default_road * streetscale 
 else:
  lwide * streetscale



Thanks in advance!


[ATTACH=CONFIG]32546[/ATTACH]
0 Kudos
2 Replies
ChristianGass
New Contributor
For those interested, I created a work around with Python, which is shown below. It seems to be a more robust approach than my previous fiddling with the ce.lib\shp.ceattr file.

from scripting import *

# get a CityEngine instance
ce = CE()

# helper function
def update_attr(shape, get_name="", set_name="",check_name=""):
    """helper function: used to get attribute values from the shape and 
    set them in the layer"""
    
    # get the value from the shape attribute that will be written 
    value = ce.getAttribute(shape, get_name)
    # get the check value from the shape that will be written
    check = ce.getAttribute(shape, check_name)
    
    if check == 0:
        ce.setAttribute(x , set_name, 0)
    else:
        ce.setAttribute(x, set_name, value)
    
    ce.setAttributeSource(x, "/ce/street/%s" % set_name, "OBJECT") 
        

# selection
graph_network = ce.getObjectsFrom(ce.selection())

# iteration
for x in graph_network:
    
    # check parameter
    check_name = "check_attr"
    
    # run update function for each attribute
    update_attr(x, "in_carriageway", "street_width", check_name)
    update_attr(x, "outside_carriageway", "sidewalkWidthLeft", check_name)
    update_attr(x, "outside_carriageway", "sidewalkWidthRight", check_name)
    update_attr(x, "lane_width", "laneWidth", check_name)

if __name__ == '__main__':
    pass


I'm still wondering why my modified ce.lib\shp.ceattr file wasn't working, though...
0 Kudos
MohsenNazemi
New Contributor II

Hi Christian,

I have a question regarding your Python script. Did it work?
I am using CE Python API and came into your topic. I want to know why didn't you put the variables "set_name" and "get_name" inside quotation marks in setAttribute and getAttribute methods?!

0 Kudos