Wednesday, October 1, 2014

Rugby Analysis in 3D


After 3 months of distractions and traveling I had to actually force myself to sit down and write this post. That is why the post (mostly about sport statistics) comes a couple of days before the end of the tournament that is the focus point of the post. My apologies. In any case...I finally had a chance to sit down and play around with CityEngine again. Being a big sports fan (rugby in particular) I thought it would be a cool to find a way to use CityEngine to display sport stats in a new way.

The Rugby Championship is rugby championship with four participating countries: South Africa, New Zealand, Australia and Argentina. Each team play two matches against all opponents home and away, resulting in 12 championship fixtures.

I decided to create a CityEngine web scene for each fixture. The web scenes shows an aerial image export (from ArcGIS.com basemap), a 3D model of the stadium (from Trimble’s 3D warehouse) and a polygon drawn manually in CityEngine which will be used to visually display the stats of the game by assigning a CGA rule.


The Rule

Step 1:

Creating attributes

The first step of the rule was to create attributes for the Home Team, Away Team and the Stats to Display (1st half, 2nd half, and Full Time). These attributes are used in later parts of the rule to add the team logo, as well as for the stats.

Step 2:
More attributes

The next set of attributes represents the actual statistics of the match. The stats were obtained from Rugby Stats - www.rugbystats.com.au

The attributes below represents percentage time in opponent’s half, percentage time in Own half and percentage possession for the First Half, Second Half and Full Time.


More attributes...
Step 3:
Display stats


The CGA rule starts by reading the Home team, Away team and which statistic type to display from the attributes. Next the rule splits the polygon horizontally into 2 parts according to the territorial attributes, as seen in the image below as the Split rule.

The Split rule (to show territory)

More territorial advantage = Greater area of the polygon


Each block is then extruded according to the percentage possession of the ball


Higher % possession = Higher block 

Finally, add a 3D model of each stadium as obtained from Trimble's 3D warehouse and its done! This is a simple example of how CityEngine can be very versatile. It is a quick rule, set up once, which I then used multiple times (10 so far). And it is really not difficult.

Have a look at the links below to view the web scenes:

Australia vs New Zealand - 16 August
South Africa vs Argentina - 16 August
New Zealand vs Australia - 23 August
Argentina vs South Africa - 23 August
New Zealand vs Argentina - 06 September
Australia vs South Africa - 06 September
New Zealand vs South Africa - 13 September
Australia vs Argentina - 13 September
South Africa vs Australia - 27 September *
Argentina vs New Zealand - 27 September


Congratulations to the All Blacks that clinched the title last weekend. As well as to the Springboks for taking sweet revenge on the Aussies. I will upload the final 2 web scenes after this coming weekend's games.

*This scene does not have a 3D Model of the stadium    (because I couldn't find one of Newlands in Cape Town)

Friday, June 6, 2014

Levels of Detail - Building Interiors

I've been focusing on CityEngine CGA rules for building interiors lately. The aim was to create a rule file (or set of rule files) to create a generic layout of a building from 2D shapes at various levels of detail (LOD).

The image below shows various levels of detail of the same shape.


The levels are:

Level 0: The first image (although not actually a LOD) shows a plain 2D shape in its original form.

Level 1: This is simply an extrusion of the building footprint. As the shape does not have any height values associated with it (in this example), the rule file chooses a random height value.

Level 2: This LOD takes the extruded block from Level 1 and divides it into a roof (which creates a simple roof ledge) and sides (which are split horizontally into floors as well as vertically into windows and ledges). An attribute called floor_height is created and implemented by the rule file to split the sides into equal floors.

Level 3: The 3rd LOD creates a detailed 2D layout of each floor. Although in this example the floors are all identical, I plan to extend the rule by creating layouts floor based on floor number (for example creating commercial layouts for ground floors; office spaces for the three following floors and create a residential layout for the remaining floors. For this example all the floors are allocated as office spaces. Each room is color-coded according to the specified use: Blue - Office ; Yellow - Hallway : Red - Conference Room ; and Green - Printer Room.

LOD 3


Level 4: The final level of detail extends the previous levels by displaying a much higher level of building floor utilization. The focus of this LOD is to place, rotate and align building furniture (mostly Collada features obtained from SketchUp 3D warehouse) on the various floors. This LOD also creates stairs which links floors vertically.*


Conference Room
Stairs


Offices

The various LODs were created by selecting the appropriate Level from a rule attributed named LOD. This is what the attribute looks like in the code, as well as the Inspector window:

LOD attribute

This scene is a great example of how CityEngine provides the ability use attributes (and when there is none...create attributes) to dynamically assign various scenarios to the same 2D data and generating 3D geometries.

Explore the scene here.

P.s. If you are bored of the usual office life you can always replace the humans with cyborgs...




*I might have a look at displaying elevators next ;)

Monday, May 19, 2014

The light at the end of the Tunnel

A very important aspect of urban design is the ability to model underground infrastructure. Most of this blog's posts are about CityEngine's ability to model urban infrastructure above ground level, however this post will have a closer look at different ways of modeling infrastructure, depending on the position above (or below) the earth's surface.

View from inside the tunnel

Large amounts of urban infrastructure is located underground. These range from electrical-, water-, and waste management elements. The focus of this post will look at how transport networks (railways) can be located above as well as below the ground.

The first step is to determine what the study area's surface looks like. This can be done by adding a heightmap (.tif) image as a terrain layer.

10 m terrain image

After your data infrastructure data is added to the scene, select the features and go to Graph > Align Graph to Terrain > Select the Height map (your terrain) and click on finish.


Now that the data is aligned to the surface of the earth, we can do a simple check, to see whether the data is located underneath or above the surface.

The rule developed in this post was similar to the Redland Redevelopment Rail Guideway rule, which can be downloaded here.

By inserting a small piece of code to the existing CGA rule, we can check if the features are located above or below the terrain and model it appropriately.

heightOverTerrain = convert(y,scope,world,pos,scope.sx,scope.sy,scope.sz)-elevation

@StartRule
Platform--> case heightOverTerrain > 0:
 Divide_Platform
else:  TunnelSplit

TunnelSplit--> comp(f) {top: Tunnel}

Tunnel--> i("Tunnel.dae") s(scope.sx + 5, scope.sy+5, 10)center(xy) Yellow


The code above does the following:

  • Creates a heightOverTerrain function which takes the z-value of the geometry and subtracts the terrain value to determine the height above the terrain. If the value is less than 1, feature is below the surface. You can read more about the convert function at the CityEngine Online Help
  • Platform --> is inserted as the StartRule. The rule calls the heightOverTerrain function to check if the feature is located below or above the surface. 
    • In case the heightOverTerrain value is > 0, the Divide_Platform rule is called, which in turn creates railway and trains along the top part of the surface, and pillars on the bottom part of the graph shape.
    •  In case heightOverTerrain < 0 (which means the feature is below the surface), the Tunnel_Split rule is called. This rule assigns and scales a Tunnel.dae asset to the top part of the shape and colors it Yellow.

By inserting this small piece of code at the @StartRule of the CGA, CityEngine dynamically checks whether to build underground tunnels or above ground railways every time that the shape is edited, depending on the location of the feature regarding the terrain.

You can view the web scene here.



  

Thursday, April 17, 2014

NetCDF in CityEngine


What is NetCDF?


If you are like me and completely lost to the meaning of NetCDF when you first heard of it, the following internet descriptions might help...

"NetCDF (Network Common Data Form) is a set of software libraries and self-describing, machine- independent data formats that support the creation, access, and sharing of array-oriented scientific data." -Wikipedia

Still not sure? NetCDF and ArcGIS:

"ArcGIS versions after 9.2 support NetCDF files that follow the Climate and Forecast Metadata Conventions and contain rectilinear grids with equally-spaced coordinates. The Multidimensional Tools toolbox can be used to create raster layers, feature layers, and table views from NetCDF data in ArcMap, or convert feature, raster, and table data to NetCDF." - Also Wikipedia

The fundamentals of NetCDF are explained here.

For the purpose of this blog post a NetCDF file stores multidimensional data in a grid format. The focus of this example converted the NetCDF files to point features using ArcGIS GP tools.

2D points to 3D points


After converting the NetCDF files to point features, the resulting dataset was a points feature class which had numerous points in a grid format. The points represent wind conditions over time. The attributes included X and Y -coordinats; elevation; time; windspeed; and wind angle.

Using the elevation attribute and the Feature to 3D by attribute tool, the points were converted to 3D enabled points with Z values.


2D Point Features
3D Point Features



Using the data in CityEngine


The Z-enabled point features were exported to individual feature classes per date stamp. This was done in order to add the feature classes as seperate layers in CityEngine.

A simple rule file was created to assign a 3D arrow object to each point. The CGA rule then angles the cone according to the windangle attribute; colors the cone on a greenToRed color ramp basis in according to the windspeed attribute.

The code:


attr windangle = 0
attr windspeed = 0
attr maxwindspeed = 6.75
attr windcolor = windspeed/maxwindspeed

Lot --> i("Arrow/Arrow_object.obj")
color(colorRamp ("greenToRed", windcolor))
s(200, 400, 200)
r(270,windangle,0) 
center(xz)

CGA Wind Rule applied in CityEngine


The Result


The result is a 3D web viewer where you can compare wind data (showing speed and direction) in a grid format, as it changes over time.




Tuesday, March 25, 2014

Procedural Colosseum

Procedural rules are normally associated with creating detailed 3D models for a large set of data.

CGA (Computer Generated Architecture) rules are also effective in terms of reducing the time it takes to create a detailed landmark (such as the Colosseum) manually. This post shows a simple process and the code that was used to create a quick landmark.


A simple arch and ledge object (.dae) was created in Sketch Up, which was used on the outer level.

Arch collada object from SketchUp

The Colosseum footprint digitized manually as a shapefile from the ArcGIS Imagery basemap.

Oval footprint shapefile

The code with some comments is below:




The Result:





























Thursday, March 13, 2014

Random Tree Generation using 3D Vegetation Library

The 3D Vegetation Models Library from LumenRT is a very user friendly way of creating quick, realistic urban vegetation with a variety of plant species.

The library offers a large variety of trees (some of which I have never used). I wanted the CGA rule to create trees for my shapes at random, from a specified selection. A small alteration to the CGA code changes the default value.

For this example I used the Plant_Loader_with_LumenRT_Models.cga

The Plant_Loader_with_LumenRT_Models.cga uses the Name attribute to determine the file path of the model. The "Alder Buckthorn" model is used as a default. As seen below.



By changing the Name attribute to a conditional attribute, and setting a probability for specified plant models, the CGA rule will automatically assign models to shapes. In the example below, only 20 tree models were specified with a propablity of 5% each.



The resulting rule only assigns the models  that were specified as a default. Keeping the original @Range annotation in order to still be able to select any of the other available models.





Monday, February 17, 2014

Network Analysis in CityEngine!

OK, actually its network analysis in ArcScene...and viewing it in CityEngine :D

The aim of this task was to create a 3D routing workflow to calculate the route to the closest emergency assembly point from anywhere within a building.

I started with the floor layout of a building (which have been captured from CAD data). The floor layout polygons are z-enabled and the stairs have been included. As seen below in ArcScene.



Using the rooms, corridors and stairs as a guide, I proceeded to capture Z-enabled emergency evacuation routes for each floor. After a frustrating route capturing session the emergency routes were created.


The next step was to create a network dataset from my assembly points and emergency routes.It is vital that the emergency routes are split at each and every intersection, as well as to make sure that each assembly point is snapped (in 2D and 3D) to the endpoint of an emergency route.

Using Model Builder in ArcGIS, I developed a model which calculates the shortest route from a specified point to the nearest Assembly Point according to the network dataset in 3D.


The model does the following:

  1. Takes the Network Dataset and creates an empty Closest Facility layer
  2. It then takes the z-enabled assembly points and loads it into the Closest Facility as the facilities
  3. It then takes the user-specified points (interactively pointed on map - see image below) and loads it as the incidents features of the Closest Facility layer. To read more about Network Analyst's Closest Facility Layers click here.
  4. The model makes copies of both the incidents and the facilities and outputs it to a specified FGDB.
  5. Finally Model Builder uses the Solve tool to perform the analysis and determine the shortest route.
  6. Next step is to apply a pre-defined symbology layer to the resulting Closest facility route layer
  7. The final step consists of utilizing the Select Data tool to select the Route layer (line with 3D symbology applied) to export it to both a line and multipatch feature using the "Feature class to Feature class" and "3D layer to feature class" tools, respectively.
The Red flag represents the starting point, while the Green flags represent the Emergency assembly points
In this example, CityEngine was used minimally. It was used to create some of the walls around the rooms ans well as the steps for some of the staircases. The final ArcScene document was saved and exported to a web scene using the "Export to 3D Web Scene" tool (the next step will to include this tool in the model builder, creating a "one-click" solution from model builder to web scene.



View the 3D web scene here.

Thursday, February 6, 2014

Cape Town at a Glance - 3D

It took a while to remove all the cobwebs after the long break, but I finally got around to playing with CityEngine 2013 (could have just as well been CE 2014!).

The main talking point this year at the office is the first ever Esri Africa User Conference in Cape Town later in the year. Esri South Africa created an ArcGIS online story map to help guide visitors around the city. I then decided to create a 3D version of that map. This was the result...


The first thing that I noticed with CityEngine 2013 is the new way it displays raster images. When I draped an aerial image over a height map, I saw that raster values with a 0 height (at sea level) were displayed as white. Although the image layer appears to be a null, for cells with height values of 0; it displays the entire terrain once exported.

Aerial terrain layer in CE 2013

I decided to include the Cape Town building footprints in the scene as 3D basemap only. Since the buildings are not really the main focus area of the scene, and used as reference only, I applied a simple Extract rule to extrude all the buildings to their height attribute and set the transparency at 0.8 (1 = fully visible).

Cape Town buildings
The next step was to create simple rules to display the data from the ArcGIS online story map. The 4 feature classes that were used were point features for:

  • Breweries (always important!)
  • Food and Drink
  • Things to Do
  • Where to stay

  • A simple CGA rule then assigned a 3D symbol for each point type:
#GeoBeer
Where to Stay
Food
Things to Do

Using the web scene to display image info

The point feature classes already contained URL information for each point of interest (displaying images). I created a new field which would contain the URL value as part of an IFRAME string. Using Field Calculator in ArcMap the new IFRAME fields were calculated as:

"<iframe height = "410" src = ' " + [URL] + " '></iframe>"

Doing this enabled the web scene to access imagery from the web, once it has been published.

Using an IFRAME to include image information


Also included in the web scene are locations of traffic cameras which monitor the traffic density on some of the major highways. Using an IFRAME string, each camera pulls a live image from the web and displays up to date conditions for that road section.


Live traffic camera
The live feed for the example above can be seen below:



The live traffic feed was obtained from i-traffic.

The web scene provides a fun, very interactive alternative to a normal 2D map.
One of the major changes with CE 2013 is the compression of the web scenes. My previous Cape Town web scene had a download weight of about 30 MB. With more data in the scene, the Cape Town at a Glance scene has a total size of 10MB.

Cape Town

You can visit Cape Town here.

P.s. 1000 points to the person who finds the Clock Tower!