Returning Jenks or CartoCSS value?

167 views
Skip to first unread message

Randy Brown

unread,
Jun 25, 2013, 1:52:43 PM6/25/13
to car...@googlegroups.com
Is there a way to query and return the Jenks bin values?  Or is there a way to query and return the full set of CartoCSS values for a specific table?

I need to be able to dynamically set the CSS used for display when building maps from 3 separate fields.  Each field creates a unique set of Jenks bins.  I either need to know what those are (dynamically) or what the CartoCSS that is generated for those bins.

The documentation shows info on Jenks (SELECT CDB_JenksBins(array_agg(numeric), integer)), but I'm not sure that the API includes access.

Thanks.


Randy

Florian Lengyel

unread,
Jun 25, 2013, 2:09:58 PM6/25/13
to car...@googlegroups.com
I'm interested in this as well. 

I'd like to use the CSS generated by the cartodb classifications (Jenks, Equal Value, Quantiles, Long Tail) to set the colors of  histograms bins for histograms generated by user selected points on a map. (I'm generating the histograms and know what the bins are.)  I'd also like to use the CSS to dynamically generate legends. The histogram data is generated by a REST endpoint (for now, until the river network and sampled data is in PostGIS/CartoDB and is queryable from there) based on a user selection. 

Developers seem to be on their own when it comes to synchronized interactive displays of legends and histograms. Desktop GIS systems can handle this. The web seems to present an opportunity for development.

Thanks!

F Lengyel
gmail/skype/twitter florianlengyel





Randy

--
 
---
You received this message because you are subscribed to the Google Groups "cartodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cartodb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Andrew Hill

unread,
Jun 25, 2013, 2:14:50 PM6/25/13
to cartodb
Hey Randy,

The Jenks bins are calculated by a special function we have here,


You can read the description and use the function in an SQL whenever you like. The only thing is that when we run it through the UI for you, we supply the data as a SELECT * FROM table WHERE column != NULL; like we talked about in the other thread.

So on your table, to get the same result as the UI go,

SELECT CDB_JenksBins(array_agg(column_name::numeric), 7) FROM table_name WHERE column_name IS NOT NULL; 

or something close to that...

Cheers,

a






Randy

--
 
---
You received this message because you are subscribed to the Google Groups "cartodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cartodb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

Andrew W. Hill, PhD, Senior Scientist 
www.vizzuality.com | @andrewxhill

Map, analyze and build applications with your data

carvingcode

unread,
Jun 25, 2013, 3:21:07 PM6/25/13
to car...@googlegroups.com
Cool.  Will give it a go.


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "cartodb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cartodb/UN2XWCfwKdk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cartodb+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Javier Santana

unread,
Jun 26, 2013, 2:34:44 AM6/26/13
to car...@googlegroups.com
If you are interested the code that generates the sql query is here:


we are working on 2.1 release right now, i think the next improvement in the UI will be the legends, so any feedback would be really appreciated

carvingcode

unread,
Jun 26, 2013, 8:21:16 AM6/26/13
to car...@googlegroups.com
Thanks for the link.  I will dig in.

Regarding legends:

- Allow for specifying textual labeling within legend.
- Allow for CSS control of the legend, i.e.: vertical, horizontal, top, left, right, bottom, etc.

Thanks.

Randy

carvingcode

unread,
Jun 26, 2013, 8:29:53 AM6/26/13
to car...@googlegroups.com
Javier -

Without locking you to a deadline, do you anticipate legend support in the next few months, end of year...?

Randy


On Wed, Jun 26, 2013 at 2:34 AM, Javier Santana <jsan...@vizzuality.com> wrote:

Javier Santana

unread,
Jun 26, 2013, 8:33:10 AM6/26/13
to car...@googlegroups.com
thanks for your feedback.

the plan is:
- release cartodb 2.1 with multilayer support in the following weeks
- after that we will work on legends, so I suppose it will be ready within 3 months 

carvingcode

unread,
Jun 26, 2013, 8:55:34 AM6/26/13
to car...@googlegroups.com
Andrew - What do I actually pass into the 'array_agg(numeric)' parameter?  I did some tests, entering the column name and numeric position.  The first returns an error.  The second returns a break scale of [null,6,6,6,6].

What is the actual data you need passed into  'array_agg(numeric)'?

Thanks.

Randy




On Tue, Jun 25, 2013 at 2:14 PM, Andrew Hill <and...@vizzuality.com> wrote:

--
 
---
You received this message because you are subscribed to a topic in the Google Groups "cartodb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cartodb/UN2XWCfwKdk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cartodb+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

carvingcode

unread,
Jun 26, 2013, 8:56:56 AM6/26/13
to car...@googlegroups.com
Nice!

Andrew Hill

unread,
Jun 26, 2013, 9:13:08 AM6/26/13
to cartodb
Hi Randy,

You pass it the column name (numeric type), so in the email I sent you before, I ensured that I cast it with, array_agg(column_name::numeric).

Cheers,

a


carvingcode

unread,
Jun 26, 2013, 9:28:35 AM6/26/13
to car...@googlegroups.com
Awesome!  Got it!

carvingcode

unread,
Jun 26, 2013, 10:33:29 AM6/26/13
to car...@googlegroups.com
For what it's worth, here's a Javascript function that will return the Jenks bins values.  It currently displays to the console, but can easily be modified for specific use.

    function getJenksBins(column_name, how_many_bins, table_name) {

        var sql = new cartodb.SQL({ user: 'cartodb_user' });
        sql.execute('select CDB_JenksBins(array_agg(' + column_name + '::numeric), ' + how_many_bins + ') from ' + table_name + ' where ' + column_name + ' is not null')
                .done(function (data) {

                    console.log(data.rows[0].cdb_jenksbins[0]);
                    console.log(data.rows[0].cdb_jenksbins[1]);
                    console.log(data.rows[0].cdb_jenksbins[2]);
                    console.log(data.rows[0].cdb_jenksbins[3]);
                    console.log(data.rows[0].cdb_jenksbins[4]);
                })
                .error(function (errors) {
                    // errors contains a list of errors
                    console.log("error:" + err);
                })

    }
    window.onload = getJenksBins("the_column", 5, "the_table");
Reply all
Reply to author
Forward
0 new messages