Skip to content

Instantly share code, notes, and snippets.

@jsanz

jsanz/README.md Secret

Created June 24, 2016 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsanz/5b04b1d296b7223479125d9e08826dcc to your computer and use it in GitHub Desktop.
Save jsanz/5b04b1d296b7223479125d9e08826dcc to your computer and use it in GitHub Desktop.
DO Madrid

Data Observatory

  • Create an empty table with the editor: do_madrid
  • Remove the description and name field an create a geo_id field of string type
  • Execute this query to get the boundaries:
INSERT INTO do_madrid (the_geom, geo_id)
  SELECT *
  FROM OBS_GetBoundariesByGeometry(
    st_makeenvelope(-4.18,40.13,-3.29,40.72, 4326),
    'es.cnig.muni'
);
  • Get the total population:
UPDATE do_madrid
  SET total_pop =
    ROUND(
      OBS_GetMeasure(
        the_geom,
        'es.ine.t1_1'
      )
    );
  • Segmented population:
UPDATE do_madrid
  SET pop_20_40 =
    ROUND(
      OBS_GetMeasure(
        the_geom,
        'es.ine.pop_20_24'
      ) +
      OBS_GetMeasure(
        the_geom,
        'es.ine.pop_25_29'
      ) +
      OBS_GetMeasure(
        the_geom,
        'es.ine.pop_30_34'
      ) +
      OBS_GetMeasure(
        the_geom,
        'es.ine.pop_35_39'
      )
    ) ;
  • Get the supermarkets and the other grocieries
UPDATE do_madrid
  SET supermarkets =
    OBS_GetMeasureById(
      geo_id,
      'es.lacaixa.supermarkets',
      'es.cnig.muni'
  );

UPDATE do_madrid
  SET supermarkets =
    OBS_GetMeasureById(
      geo_id,
      'es.lacaixa.supermarkets',
      'es.cnig.muni'
  );
  • Same with other measures: malls, automobiles, etc.

  • Calculated normalized columns using this kind of queries:

alter table do_madrid
add column supermarkets_km numeric ;

update do_madrid
set supermarkets_km =
ROUND(
  (supermarkets/ST_Area(the_geom::geography)::numeric * 10e6)::numeric,
  1
);
  • Created a dashboard to render by default automobiles per person but allow to filter and change the simbology by other metrics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment