Key:ref:ine

From OpenStreetMap Wiki
Jump to navigation Jump to search
Public-images-osm logo.svg ref:ine
Instituto Nacionalde Estadística (Spain) logo.svg
Group: references
Used on these elements
may be used on nodesshould not be used on waysshould not be used on areasmay be used on relations
Status: de facto

Is a sub key of ref=* and its values are numbers used as identifiers for Spanish population units by the Spanish Statistical Office ([W] INE), [W]P772.

Province Municipality Collective entity Singular entity Nucleus/scattering
PP MMM CC SS NN

Interactive map

You may check the current status of the missing references through the following visualization: https://osm-es.github.io/validador-ine/

Validation queries

Nodes

The spanish localities (i.e. place=*) ref:ine=* code lies in the value of ine:municipio=* plus 6 digits, therefore we can check it out using maths.

The next overpass query checks if the nodes contain the proper value, that is ine:municipio * 1e6 < ref:ine < ine:municipio * 1e6 + 1e6. If the following query returns nothing, it means everything is OK.

Note: The next query takes several minutes to run.

try it yourself in overpass-turbo
[out:xml][timeout:900];
area["ISO3166-1"="ES"]->.searchArea;
relation["admin_level"="8"]["ine:municipio"]["boundary"="administrative"](area.searchArea);
map_to_area;
foreach->.mun(
  (
    // como no existe un operador de substring, convertimos ambas etiquetas a números
    // (debido a un error de parseo de variables que empiezan en cero, se añade y luego se resta, un número superior a los códigos)
    // como el ref:ine tiene 6 cifras añadidas a su ine:municipio, multiplicamos por 1 millón
    // de tal modo que los ref:ine deberá pertenecer al rango: 
    // ine:municipio * 1e6 < ref:ine < ine:municipio * 1e6 + 1e6
    //
    // ejemplo:
    // ine:municipio=47140
    // ref:ine=47140000100
    //
    // 47140 * 1e6 < 47140000100 < 47140 * 1e6 + 1e6
    node(area.mun)["ref:ine"](if: (number(1e12 + t["ref:ine"]) - 1e12) < ((number(1e12 + mun.u(t["ine:municipio"])) - 1e12) * 1e6));
    node(area.mun)["ref:ine"](if: (number(1e12 + t["ref:ine"]) - 1e12) > ((number(1e12 + mun.u(t["ine:municipio"])) - 1e12) * 1e6 + 1e6));
  );
  out;
);

Likewise, we can further refine the entities validation, instead of consulting by municipality we do so by a lower unit, such as, the civil parishes for Galicia or Asturias. A reference will be correct whenever: ref:ine parish < ref:ine locality < ref:ine parish + 1e4. If the following query returns nothing, it means everything is OK.

Note: This query will make sense whenever the municipalities contain boundary=administrative and admin_level=9 relations.

try it yourself in overpass-turbo
[out:xml][timeout:900];
area["ISO3166-2"="ES-GA"]->.searchArea;
relation["admin_level"="9"]["boundary"="administrative"](area.searchArea);
map_to_area;
foreach->.mun(
  (
    node(area.mun)["ref:ine"](if: (number(1e12 + t["ref:ine"]) - 1e12) < (number(1e12 + mun.u(t["ref:ine"])) - 1e12));
    node(area.mun)["ref:ine"](if: (number(1e12 + t["ref:ine"]) - 1e12) > (number(1e12 + mun.u(t["ref:ine"])) - 1e12 + 1e4));
  );
  out;
);

Relations

The spanish municipalities (i.e. admin_level=8) ref:ine=* code lies in the value of ine:municipio=* plus 6 zeros, therefore we can check it out using maths.

The next overpass query checks if the relations contain the proper value, that is ine:municipio * 1e6 = ref:ine. If the following query returns nothing, it means everything is OK.

try it yourself in overpass-turbo
[out:xml][timeout:900];
area["ISO3166-1"="ES"]->.searchArea;
relation["admin_level"="8"]["ine:municipio"]["boundary"="administrative"](area.searchArea)->.all;
relation.all["ref:ine"]->.ok;
// relaciones cuyo código ref:ine difiere del ine:municipio
// (debido a un error de parseo de variables que empiezan en cero, se añade y luego se resta, un número superior a los códigos)
//
// ejemplo:
// ine:municipio=47140
// ref:ine=47140000000
//
// 47140 * 1e6 = 47140000000
relation.ok(if: ((number(1e12 + _.set(t["ine:municipio"])) - 1e12) * 1e6) != (number(1e12 + _.set(t["ref:ine"])) - 1e12))->.wrong;
// relaciones sin código ref:ine
(.all; - .ok;)->.missing;
(.missing;.wrong;);
out geom;