Municipality

The lowest level of territorial organization in Spain. Municipal boundaries do not cross between provinces.

INSERT INTO <table_to_update> (cartodb_id, the_geom, name, the_geom_webmercator)
SELECT ROW_NUMBER() OVER () AS cartodb_id,
       the_geom,
       geom_refs,
       ST_TRANSFORM(the_geom, 3857) the_geom_webmercator
FROM OBS_GetBoundariesByGeometry(
  ST_GeomFromText('POLYGON((-18.6 27.3,-18.6 44.1,4.5 44.1,4.5 27.3,-18.6 27.3))', 4326),
  'es.cnig.muni'
)

Update the boundaries in another table matching the table’s ID column.

WITH data AS (
  SELECT <geo_id> AS id
  FROM <table_to_update>
),
meta AS (
  SELECT OBS_GetMeta(ST_MakeEnvelope(-179, 89, 179, -89, 4326),
    '[{"geom_id": "es.cnig.muni"}]'
  ) meta
)
UPDATE <table_to_update> SET
      the_geom = (data->0->>'value')::Geometry,
      the_geom_webmercator = ST_Transform((data->0->>'value')::Geometry, 3857)
FROM OBS_GetData(
      (SELECT Array_agg(id) FROM data),
      (SELECT meta FROM meta)) obs_data
WHERE <table_to_update>.<geo_id> = obs_data.id

Obtain boundaries matched to another table’s ID column.

WITH ids AS (
  SELECT ARRAY_AGG(<geo_id>) ids
  FROM <table_with_ids>
),
meta AS (
  SELECT OBS_GetMeta(ST_MakeEnvelope(-179, 89, 179, -89, 4326),
    '[{"geom_id": "es.cnig.muni"}]'
  ) meta
)
SELECT ROW_NUMBER() OVER () AS cartodb_id,
       data->0->>'geomref' as geomref,
       (data->0->>'value')::Geometry as the_geom,
       ST_Transform((data->0->>'value')::Geometry, 3857) AS the_geom_webmercator
FROM OBS_GetData((SELECT ids FROM ids), (SELECT meta FROM meta))

Time (default is latest)

  • 20150101