2

I created this map in cartodb: http://cdb.io/1xBj4Xo

Now I have to merge some of the districts to a bigger district. Is it possible to do this in Cartodb? Using a SQL query for instance?

I can also provide a .csv-file: http://tradukt.ch/owncloud/public.php?service=files&t=2fe413428dd38103705fa4191236b8fc

Screenshot of the table:

enter image description here

2 Answers 2

2

Based on your CSV,

Tablename: Wahlkreise
Column containing value to union on: wahlkreis
Other Columns use an aggregate function to grab one of the values (all of them are the same for each district / wahlkreis

In the SQL window in CartoDB, type:

   SELECT   

wahlkreis  
, cartodb_id  
, max(strong_party) as strong_party  
, max(einwohner) as einwohner  
, max(mandate) as mandate  
, max(kandidaten) as kandidaten  
, max(frauen) as frauen  
, max(maenner) as maenner  
, max(fdp) as fdp  
, max(svp) as svp  
, max(sp) as sp  
, max(glp) as glp  
, max(gruene) as gruene  
, max(evp) as evp  
, max(cvp) as cvp  
, max(bdp) as bdp  

, st_union(the_geom_webmercator) as the_geom_webmercator      


FROM wahlkreise_bl_1

group by wahlkreis, wahlkreise_bl_1.cartodb_id

At this point, map interaction must be enabled by adding the CartoDB_id to the SQL and GROUP BY clause, but there seems to be a bug that removes the st_union function from working properly (I will keep digging in).

The workflow instead could be to simply use the 'create table from query' option to write your query to a new file, and you can take advantage of the full interactivity based on your SQL processing.

7
  • Sorry, I am not able to do it. What would districtName and districtID be? If you clone the map, you can see several communities. I need like four or five communities to become a larger district. That would be gmdnr (column) and 2761, 2762 and 2763 (rows). So that I can have a larger district to manipulate it further (color, popup etc.)
    – Felix
    Commented Jan 6, 2015 at 21:50
  • can you post a screen grab of the table portion of your data? The CSV isn't entirely necessary... Commented Jan 6, 2015 at 22:45
  • I updated the post
    – Felix
    Commented Jan 7, 2015 at 9:35
  • @Felix I updated my answer, but you might want to share your CSV if possible... Commented Jan 7, 2015 at 15:59
  • 1
    awesome, that works! I just had to adapt the table name! Thanks a lot!
    – Felix
    Commented Jan 7, 2015 at 22:19
0

An another solution for a basic use (just merge all polygons):

Select ST_Union(the_geom_webmercator) as the_geom_webmercator      
FROM Tablename
group by cartodb_id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.