Skip to content

Instantly share code, notes, and snippets.

Source: American Community Survey, 2011 5-Year Estimate

This map was inspired by a similar map found on Wikipedia. I wasn’t wild about the diverging color scale, so I thought it would be a fun challenge to recreate.

Finding the shapefiles was easy; I used the U.S. National Atlas 1:1,000,000 scale dataset, conveniently packaged in my U.S. Atlas repository. I reprojected the shapefiles to the California Albers projection using ogr2ogr:

ogr2ogr \
	-f 'ESRI Shapefile' \
	-t_srs 'EPSG:3310' \
@jatorre
jatorre / gist:5773783
Created June 13, 2013 13:44
Example for Nutiteq
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.nutiteq.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
@jatorre
jatorre / gist:5773807
Created June 13, 2013 13:49
Nutiteq CartoDB example
public class HelloMap3DActivity extends Activity {
private MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
// now start init of MapView, see below...
// define new configuration holder object
mapView.setComponents(new Components());
// Define base layer. Here we use MapQuest open tiles which are free to use
// Note that almost all online maps use EPSG3857 projection, but Nutiteq SDK supports also other projections if needed
TMSMapLayer mapLayer = new TMSMapLayer(new EPSG3857(), 0, 18, 0,
"http://otile1.mqcdn.com/tiles/1.0.0/osm/", "/", ".png");
mapView.getLayers().setBaseLayer(mapLayer);
TMSMapLayer cartoDbTileLayer = new TMSMapLayer(new EPSG3857(), 0, 18, 15,
”http://nutiteq.cartodb.com/tiles/tm_world_borders/”, “/”, “.png”);
mapView.getLayers().addLayer(cartoDbTileLayer);
LineStyle lineStyle = LineStyle.builder().setWidth(0.05f).setColor(Color.WHITE).build();
PolygonStyle polygonStyle = PolygonStyle.builder().setColor(0xFFFF6600 & 0x80FFFFFF).setLineStyle(lineStyle).build();
StyleSet<PolygonStyle> polygonStyleSet = new StyleSet<PolygonStyle>(polygonStyle);
// note the SQL has special string !bbox! as bounding box dynamic value placeholder
String sql = "SELECT name,iso2,pop2005,area,the_geom_webmercator FROM tm_world_borders WHERE the_geom_webmercator && ST_SetSRID('BOX3D(!bbox!)'::box3d, 3857) LIMIT 3000";
CartoDbVectorLayer cartoLayer = new CartoDbVectorLayer(new EPSG3857(), "nutiteq", sql, null, null, polygonStyleSet);
mapView.getLayers().addLayer(cartoLayer);
./cdb_import.sh <cdb_username> <api_key> <file_name>
@jatorre
jatorre / gist:6222402
Last active December 21, 2015 00:39
Here is a bit better
#locales_de_votaci_n_paso_2013_caba[vot_parcodigo=8] {::shadow {
marker-opacity: 1;
marker-allow-overlap: true;
marker-line-width: 0;
marker-line-opacity: 0;
image-filters: agg-stack-blur(5,5);
marker-fill: #2ca02c; [zoom<=12] {
marker-width: 8;
}
[zoom=13] {
@jatorre
jatorre / gist:6622239
Last active December 23, 2015 10:29
Small update example optimized
UPDATE wahlen_by_2013_test o
SET averagevalue=n.averagevalue,
constituencyname=n.constituencyname,
electionwinnerpartyname1=n.electionwinnerpartyname1,
electionwinnerpartyname2=n.electionwinnerpartyname2,
electionwinnerpartypercent1=n.electionwinnerpartypercent1,
electionwinnerpartyperson1=n.electionwinnerpartyperson1,
freie_waehler_percent2=n.freie_waehler_percent2,
gruene_percent2=n.gruene_percent2,
piraten_percent2=n.piraten_percent2,
curl 'http://sz2.cartodb.com/tiles/layergroup' -H 'Pragma: no-cache' -H 'Origin: http://gfx.sueddeutsche.de' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host: sz2.cartodb.com' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.37 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Cache-Control: no-cache' -H 'Referer: http://gfx.sueddeutsche.de/politik/2013-09-15_LandtagswahlBayernWahlkarte/' -H 'Connection: keep-alive' --data-binary '{"version":"1.0.1","stat_tag":"f8515466-04da-11e3-ad81-938373fbfdcf","layers":[{"type":"cartodb","options":{"sql":"Select * FROM wahlen_by_2013","cartocss":"#wahlen_by_2013{ polygon-fill: #dedcd0; line-opacity: 1; polygon-comp-op: multiply; line-width: .5; line-color: #fff; polygon-opacity: 0;} ","cartocss_version":"2.1.0","interactivity":["cartodb_id"]}},{"type":"cartodb","options":{"sql":"Select * FROM wahle