ViziCities Dev Diary #1: Visualising Cities in 3D using WebGL
rawkes.com
rawkes.com
That is the magic of having and utilising the power of free and open-source software. Imagine not having three.js, QGIS, PostGIS etc.
Gorgeous work and a highly interesting "how we are doing it" insight. Thanks! Please more!
I'm glad you like it, we'll make sure to write up more as we progress.
Keep on the awesome work.
And likewise, sounds like you're working on cool things too ;)
You got a lot farther than me when I tried Three.js before hitting performance problems. I was trying to make a WebGL 3d warehouse visualization app: http://chir.ag/projects/wh/ and stopped because it was too slow once I loaded 1000 bins. I also never quite figured how to handle rotation/panning nicely (src: http://chir.ag/projects/wh/main.js). I came up with a shorthand http://chir.ag/projects/wh/bins/wh.txt that expands to http://chir.ag/projects/wh/bins/bins.php - I was going to make it an easy to use app where you could describe how the warehouse was organized with 20-30 lines of bin#s and positions and let the system generate the rest. Then it could parse APIs containing various properties per bin (full/empty, inventory amount, frequency of usage, days-since-last-used etc.) Clicking on any bin would open up a panel with more information and you'd have filtering/highlighting capability for the whole warehouse.
I made good progress initially but got busy with life and never got around to solving the too-many-bins problem. I still don't know how to improve the performance. Even when entire objects are outside the view, they still take up resources and time. I see you mentioned LOD support in Three.js - no idea if it would help me or not because each object is already as simple as it can be - just a box.
If someone wants to hack on this and make it functional, I'll help however I can.
Thanks so much! Everyone is welcome to share/extend this. If the 3D part works better, I can make a JS function to convert: 1-WH-[001:011]{A:D}, 30,{0},[20] into:
{"1-WH-001A":[30,0,20,1,1,1,10329599],"1-WH-001B":[30,1,20,1,1,1,10198015],"1-WH-001C":[30,2,20,1,1,1,10987519]}
The data is in the format bin:[x,y,z,sx,sy,sz,color] - the color will obviously be dependent on the data. Position and size are fixed in most warehouse simulations.
http://learningthreejs.com/blog/2011/10/05/performance-mergi...
But since we were writing the WebGL ourselves, I just added a bit of code to batch up all the objects into as big a bucket as WebGL could handle (up to 65k verts per draw call), thereby reducing the number of draw calls (drawElements). For our larger models, we went from 1100 ms per frame, down to 1-5ms per frame. We've done other things as well, but none had so large an impact as merging the geometry into larger chunks.
But I can't speak to doing that in Three.js, since I didn't use it. But you should easily be able to handle the geometry you've got at 60 fps.
THREE.GeometryUtils.merge
does that.You should be hired by the uk.gov team to work on this full-time.
This, combined with various statistical information (crime, traffic, other stuff from the ONS) would be a huge boon to anyone using it and the interface makes it beginner friendly.
We'd love to talk to the data.gov.uk guys about working together, though I have no contacts there atm.
We do plan to visualise huge quantities of data, including the datasets you mentioned. Most of what we've been using so far is from the 2011 Census, as well as the Indices of Multiple Deprivation.
Traffic too, we're looking into using the live data from TFL to do some cool stuff.
While I appreciate some of the game related stuff this looks most promising for allowing people to easy see statistical information at-a-glance, data journalism etc.
The NapTAN datbase would be an awesome addition that should be relatively easy to add.
Regarding the data.gov.uk team. They do have a twitter account and website, hit them, hit them hard. Even if they can only smooth the way for data access (Like the building heights) that would be awesome.
How did you implement your data path from getting GIS data (shapefiles I presume) to PostGIS then GeoJSON and finally into ThreeJS?
What about combining the statistical data with the location?
And the heatmap/choropleth, is that something Three.js can do?
I have no knowledge of developing 3D stuff, but I have been looking into using D3 with canvas rendering just for this kind of visualizations. I'm playing with multidimensional data as stacked 3D cubes. So, getting something like this would really bootstrap my project to another level. Any thoughts about open sourcing?
In all, this looks very useful and expendable. The sky is the limit. Literally, when is sky coming? ;)
Definitely one of my favourite comments about the project so far! =p
The rough and ready approach we took to transforming data was to import the shapefiles into PostGIS using pgShapeLoader, doing any manipulation in PostGIS and exporting straight out to GeoJSON using the ST_ToGeoJSON method in PostGIS, or using the GeoJSON options in ogr2ogr. From there it's a simple case of importing the JSON into Three.js and constructing the objects from the vertex coordinates.
Re: Combining statistical data with the geographic data, we can do that with GeoJSON and you can use ogr2ogr to include related data about each location when exporting to GeoJSON.
The choropleth map is something we constructed from scratch. In reality, it's nothing more than a bunch of shapes in Three.js that each have a different material colour – it's very simple.
D3.js is a fantastic place to start. In fact, that's exactly where we started with all this. We actually use the Geo module within D3 for a few parts of ViziCities.
We haven't decided yet about opening the full project but we'll certainly be documenting and releasing aspects of it (most of the juicy bits). We'll announce that via the @ViziCities Twitter account.
As for the sky… it's coming ;)
There was a WebGL 3D flying simulator on HN few weeks back which used the sky and light changes to great effect. Perhaps something like morning rush hour traffic against evening or rainy days againts sunny.
I'll definetely have to delve more into PostGIS. Three.js should follow when I get a better graps of D3. I think there was an example on how to generate a satellite 3D like map from GeoJSON at Mike Bostocks example site.
Very exciting stuff!
I also tried a multi-device approach for visualisation: http://www.youtube.com/watch?v=-TiZzovx5YE
Any chance of collaboration?
From this thread I reckon there are quite a few people working on something similar. I guess it would be extremely cool if we could join forces.
We haven't yet worked out what we're doing re: opening the project and collaboration but we're open to talk more. Mind reaching out to us via hello@vizicities.com?
Holler if you need somebody to make some music. Heavily into making ambient stuff right now anyways...
Re: Music. Do you have any examples of your stuff anywhere? We'll be having music and effects of some sort but haven't yet looked into it much.
It's somewhat mixed, but there is a good amount of ambient stuff in there as well. (Also note that almost all of it - except for the one remix - is CC licensed.)
Would sure love to help out any way I can!
Another interesting idea could be turning a city into a sort of MMORPG where each user has control over a smaller section of the city (instead of the whole thing). If the user only pays attention to optimizing a small part of the city, interesting patterns could emerge in the overall model.
There are indeed a number of ways this could make for an interesting multiplayer experience. I'd particularly prefer it if it was fully P2P and networks would emerge by people offering and making connections. Oh one can dream.
You might want to look to Germany and CityGML. You might discover some town datasets that are complete in height and geometry detail.
If you happen on a LIDAR data source you've then got to tidy up against the buildings but you will run into errors caused by the time spent between the two data capture points. There's SRTM but i'm sure it'll be too coarse for your needs. I'm sure there's a replacement to SRTM but the name escapes me.
There's LandXplorer - now owned by Autodesk which will generate models from oblique aerial photogrammetry. There's also CityEngine that'll create fake cities based upon road networks.
@AndyBMapMan.
I'll definitely look into the CityGML stuff, it sounds great.
LIDAR is certainly something we're keen to explore further. If anything, it'll get us a much more accurate estimation of height, at least better than an educated guess or via SRTM (which is way to low detail and can't be relied on for buildings).
The CityEngine stuff is amazing. I've not actually played with it myself yet but I've been having a good look at it during my research. Would be cool to have a go on it at some point.
The Kinect could be a fun way to explore your visualizations -- seen here hooked up to Google Earth: https://github.com/jawj/pigeonsim
Also, I'm sure http://www.bartlett.ucl.ac.uk/casa would love to hear from you.
I saw Pigeon Sim via Andy @ CASA the other day, it looks like awesome fun! We'd also like to play with Leap Motion and create something similar to the Google Liquid Galaxy stuff.
Quite keen to work with CASA, I'm sure there is a tonne that we can help each other with. I told Andy about the project a while back but that was before we had anything visual. I'll try pinging Andy again, unless you have another suggestion?
Would a simulation component be added in? Cause if it is, It'll be nothing short of awesome.
All the best!
We've been thinking a little about simulation and, although not likely for the first release, it's something we'd love to explore in the future. It's not a huge step to go from our basic AI to a full-on simulated game-type world.
We're not ruling anything out.
Are you teasing us with the prospect of 3d weather (perhaps by using radar data)?
If not that's cool, but if so, great idea.
But seriously, weather and night/day cycles is something we're looking into.