“How many layers does CartoDB support?” It’s a question we hear often. The word “layer” has been a part of the GIS nomenclature since the times of John Snow, and the geospatial community is used to thinking in terms of layers. Many of the prevailing desktop GIS software packages support this mode of thinking with “layer browsers” that have checkboxes for roads, parks, tax lots, pipes - in short, each and every type of dataset in the user’s project.
Aye, but there’s the word: dataset! A “layer” is often really just a dataset. Nothing more, nothing less. In a relational database environment, like CartoDB, individual datasets are stored as tables. And since PostgreSQL (and therefore CartoDB) can support thousands and thousands of tables of data, the answer to “how many layers does CartoDB support?” is pretty much as many as you would like! If you need to, this makes creating a “geoportal” site to all your organization’s geospatial datasets no problem at all.
Given this reality, you’d be forgiven for being confused by the “limit” of 4-6 layers (think tables!) in visualizations/maps made through the CartoDB Editor on our monthly plans (10 layers on Enterprise). Each CartoDB visualization/map corresponds to one set of map tiles, and so these “layers” are really better described as “sublayers” that come together (with their constituent CartoCSS, SQL, and other parameters) to form a single tile layer. Sublayers are referenced as such in the CartoDB.js documentation, and can be added with CartoDB.js’ “createLayer” function and others.
Sometimes, maps and visualizations with more than just a few datasets/tables/layers can be useful. Moreover, sometimes you want your tables and datasets in separate tile layers, or even to use multiple multi-table visualizations in your app. Having many datasets to visualize at once means you need to think carefully about your visualization choices and the user experience you’re providing through your app. Making multi-table maps through the CartoDB Editor, as powerful as it is, will not give you or your users the fine-grained capabilities and positive user experience as building your own custom app on the CartoDB APIs and platform will once you get beyond 4-6 “sublayers”.
There’s another good word: platform! CartoDB is not just the Editor. You have full access to all our APIs to make your own custom apps, with all the control you might want when building a large geoportal site to suit tens or hundreds or even thousands of geospatial datasets. My Madrid-based colleague on our Sales Engineering team, Daniel Carrión, and I recently put together some demonstration geoportal sites using a custom Angular.js front-end and a crafty use of CartoDB tables and the SQL API. Unique from other multi-layer visualization techniques we’ve posted in the past, this template gives you a scrollable list for a more enjoyable browsing experience when you’ve got 10+ layers. And, this technique has the benefit of being able to display multiple datasets at once and toggle them each on and off independently.
You can see a demo at http://multilayer.cartodb.io/, and even use it with your own table using the URL instructions on that page. A complete example with many datasets and even multiple, multi-layer visualizations I made to correspond with this blog post is here. Follow along below and make your own multi-layer mini-geoportal app in just a few minutes with our template!
We need a convenient place to store all the information related to each dataset and the viz.json, or CartoCSS, SQL, and other parameters to create each layer in our multi-layer geoportal app. CartoDB’s heart is the PostgreSQL/PostGIS database, so a CartoDB table makes a convienient place to edit and store this information that our application can easily retrive over the web via the SQL API. It won’t have any geospatial information, but that’s OK: this table will just be for the app’s layer “metadata,” in a way.
cartodb_idis needed here)
sql_usercolumn (if your CartoDB tables are in an organization account)
viz_jsoncolumn, if you’d rather use the viz.json file to your layer. Note that layers with a viz.json file don’t need any other information in the table, as the linked file contains it all.
It may be easiest for you to “export” Dani’s or my table as a CSV and import it into your own account, which will give you all the required columns, and just modify/enter in your own data.
The order of rows in most SQL databases is undefined, which means for any given database, unless you use an “ORDER BY” clause in your query, the rows will be returned in a random order or the database manufacturer will define an arbitrary order. With CartoDB, absent an ORDER BY, rows are returned from the SQL API sorted by the
updated_at column. If you’re just using the demo app that Dani and I created, this means your layers will be listed in your selector in the order of earliest-update-first.
Upload the datasets you want to visualize into their own tables, and create visualizations (maps) with them using the CartoDB Editor. Or hand-code your CartoCSS and SQL if you’re feeling adventurous. After you’ve tweaked each individual visualization to your liking, you can either copy its CartoCSS, SQL, and other details into your “multilayer” table. You can also copy just the viz.json link from the Editor into the respective column.
An advantage of using the viz.json link is you can create visualizations with multiple “sublayers” in the Editor, and view them through the geoportal app. For example, I have the following visualizations with only one sublayer:
Also, I created two visualizations with multiple sublayers:
Now, if you’re using the geoportal, you can check on/off “All Pennsylvania Infrastructure Layers” or “All Philadelphia Infrastructure Layers” to see these full collections of layers at a glance, rather than checking them all on individually. Also note that in each layer can have its own CartoCSS - highway districts are green in the all-Pennsylvania layer, but orange in the all-Philadelphia layer.
If you want to use the template we have at http://multilayer.cartodb.io/, you’re all set! Your app URL will have a few URL parameters that are described on that main page. The Angular.js app will parse those out, access your multilayer table via CartoDB’s SQL API, and list your visualizations with checkboxes to toggle them on and off.
This is just a simple example of what can be accomplished visualizing multiple datasets via the CartoDB Platform. To give you an idea, just recently we found a great example (shown above) at DataFrance.info using CartoDB to display dozens of layers across all of France. What multilayer visualizations will you make?
When building new software applications, developers wrestle with doubts on whether their design decisions will deliver users the best possible experience. From interface la...App Development
On Friday, February 9th, the 2018 Winter Olympic Games kicked off in Pyeongchang, South Korea. Featuring athletes from 92 countries around the world, this Winter Games prov...App Development
Please fill out the below form and we'll be in touch real soon.