Building a Unified Geographic Knowledge Graph for Spain
Integrating Wikidata, Official GIS Data, and Semantic Web Technologies
Spain has no shortage of geographic data.
Government agencies publish official cartographic datasets. Wikidata contains millions of geographic entities. DBpedia provides rich descriptions and category structures. Cultural institutions maintain controlled geographic vocabularies.
Yet despite this abundance of information, answering seemingly simple questions remains surprisingly difficult.
Questions such as:
- Which protected natural areas are located inside a specific administrative region?
- Which municipalities belong to historical cultural routes?
- What infrastructure exists within a given geographic context?
- Which coastal towns contain protected beaches and Natura 2000 areas?
The problem is not the lack of data.
The problem is fragmentation.
Each source describes geography differently, using different identifiers, hierarchies, and conceptual models.
As a result, Spain’s geographic knowledge exists across multiple disconnected silos.
I wanted to see whether these sources could be unified into a single semantic knowledge graph capable of supporting geographic reasoning at a national scale.
The result was a graph containing more than 120,000 harmonized places connected through a common ontology and enriched through multi-source semantic integration.
Why Geographic Data Is Harder Than It Looks
Traditional GIS systems excel at storing coordinates, geometries, and spatial relationships.
But they are not designed to represent knowledge.
A GIS can tell you where a municipality is located.
A knowledge graph can tell you:
- what type of place it is,
- what larger administrative entities contain it,
- which cultural regions it belongs to,
- what nearby infrastructure exists,
- what historical or environmental concepts are associated with it,
- and how it connects to thousands of other entities.
This distinction becomes critical when working across multiple datasets.
While geographic coordinates may be precise, conceptual relationships are often inconsistent.
The same location may appear differently in:
- Wikidata
- DBpedia
- official cartographic datasets
- institutional thesauri
Each source provides valuable information.
None provides a complete picture.
Designing a Geographic Ontology
The first challenge was creating a conceptual framework capable of integrating heterogeneous geographic sources.
Rather than importing every existing model, I designed a lightweight ontology centered around a single core abstraction:
Place
Every geographically identifiable entity inherits from this concept.
From there, several high-level categories emerge:
- Human Settlements
- Administrative Places
- Maritime and Fluvial Places
- Transportation Places
- Mountain and Terrain Features
The objective was not to maximize complexity.
It was to maximize interoperability.
A small set of carefully defined classes and containment relationships proved sufficient to model a surprisingly large portion of Spain’s geography.
Combining Official and Collaborative Knowledge
One of the key design decisions was adopting a hybrid model.
Administrative structures were aligned with official standards from Spain’s geographic institutions and European statistical frameworks.
Physical geography, however, benefited from the flexibility found in Wikidata.
This combination created a graph capable of answering questions that traditional databases often struggle with.
For example:
A river can now be connected to:
- municipalities,
- provinces,
- autonomous communities,
- protected areas,
- transportation infrastructure,
through a shared semantic model.
Administrative geography and physical geography become part of the same reasoning space.
Extracting the Relevant Subgraph from Wikidata
Processing the entire Wikidata dump would have been computationally expensive and unnecessary.
Instead, I implemented a semantic slicing strategy using Wdumper.
The goal was simple:
Extract only the subset of Wikidata relevant to Spanish geography.
This dramatically reduced processing costs while preserving the relationships needed for reasoning and integration.
Rather than importing millions of unrelated entities, the graph focused on a coherent geographic domain.
Fixing One of Wikidata’s Biggest Challenges
One of the most difficult problems involved the famous P131 property:
“located in the administrative territorial entity.”
Anyone who has worked extensively with geographic data in Wikidata knows that P131 is incredibly useful but often inconsistent when traversing large hierarchies.
Different administrative levels are modeled differently.
Relationships are sometimes incomplete.
Inference chains can become unreliable.
To solve this, I implemented a series of SPARQL update operations that normalized territorial dependencies.
The graph automatically transformed generic containment relationships into explicit semantic relationships.
For example:
Municipality → Province
became:
- contained in province
- province contains municipality
The result was a cleaner hierarchy that supports robust geographic inference.
Entity Matching Across Four Knowledge Sources
Perhaps the most valuable part of the project was entity reconciliation.
A knowledge graph becomes exponentially more useful when entities are connected across multiple sources.
The project integrated:
- Wikidata
- DBpedia
- BTN100
- Geographic Thesaurus of the Ministry of Culture
Several matching strategies were combined.
Structural Matching
Wikidata ↔ Wikipedia ↔ DBpedia
Using direct semantic mappings based on shared identifiers.
Fuzzy Linguistic Matching
Wikidata ↔ Geographic Thesaurus
Get Javier Murcia Zomeño’s stories in your inbox
Join Medium for free to get updates from this writer.
Using normalized labels and textual similarity techniques.
Geographic Harmonization
Wikidata ↔ BTN100
Combining naming normalization with geographic context.
Future versions will incorporate GeoSPARQL-based matching using spatial proximity and geometry comparison to resolve ambiguous place names.
Letting Categories Generate Knowledge
One experimental aspect of the project involved leveraging DBpedia categories.
Instead of treating categories as simple labels, I explored them as semantic containers capable of generating additional knowledge.
Categories such as:
- Camino de Santiago
- Coastal Geography
- Historical Regions
contain rich semantic signals.
By propagating properties inductively through these categories, the graph can discover additional relationships that were never explicitly stated.
In effect, categories become a lightweight inference mechanism.
This creates an additional semantic layer beyond the ontology itself.
Building a Semantic Geographic Platform
To demonstrate the graph’s capabilities, I developed a web application that exposes its structure through multiple interfaces.
The platform includes:
- interactive maps,
- graph visualizations,
- SPARQL querying,
- ontology exploration,
- semantic navigation.
Users can move seamlessly between spatial and semantic perspectives.
A location is no longer just a point on a map.
It becomes a node inside a connected knowledge system.
Results
The final graph contains:
- 120,000+ integrated geographic entities
- 100 ontology classes
- 17 consolidated object properties
- tens of thousands of reconciled entities
- harmonized administrative hierarchies
More importantly, it enables reasoning that was previously difficult or impossible.
Examples include:
- finding beaches within coastal municipalities,
- identifying protected areas inside administrative regions,
- analyzing healthcare infrastructure by territory,
- discovering places related to cultural or geographic concepts,
- contextualizing real estate and tourism data.
What GraphRAG Can Learn From Geography
One of the most interesting aspects of this project is that it was never designed for generative AI.
The original goal was to build a unified geographic knowledge graph capable of integrating heterogeneous sources and supporting semantic reasoning.
However, many of the challenges solved during its construction are remarkably similar to those currently faced by GraphRAG systems.
Most GraphRAG implementations focus on improving retrieval by adding graph structures on top of vector search. Yet the effectiveness of those graphs ultimately depends on the quality of the underlying knowledge representation.
Geographic data offers a useful example.
Consider a simple place name such as Murcia.
Without a semantic model, the term may refer to:
- a municipality,
- a province,
- a historical region,
- a metropolitan area,
- or even multiple entities sharing similar names.
A vector-based retrieval system may retrieve relevant documents, but it cannot reliably determine which Murcia is being discussed or how it relates to surrounding entities.
A knowledge graph can.
By explicitly modeling containment, administrative hierarchy, geographic types, and relationships between places, the graph provides contextual information that retrieval systems can use to reduce ambiguity and improve relevance.
The same principle applies far beyond geography.
Many GraphRAG pipelines struggle with:
- entity disambiguation,
- inconsistent identifiers,
- fragmented data sources,
- missing hierarchical context,
- and incomplete relationships.
These were exactly the problems addressed in this project through:
- ontology design,
- entity reconciliation,
- hierarchy normalization,
- semantic enrichment,
- and multi-source integration.
In other words, the most valuable lesson is that GraphRAG is not fundamentally a retrieval problem.
It is a knowledge modeling problem.
Retrieval improves when entities are well-defined, relationships are explicit, and context is encoded directly into the graph.
Geographic knowledge graphs make this particularly visible because location itself is inherently hierarchical and relational.
A village belongs to a municipality.
A municipality belongs to a province.
A province belongs to an autonomous community.
Each relationship adds context.
Each layer reduces ambiguity.
Each connection improves the ability of a system to reason.
As GraphRAG architectures continue to evolve, many of the techniques developed within the Semantic Web community over the last two decades — ontology engineering, linked data, entity linking, and semantic normalization — may prove just as important as embeddings and vector databases.
The future of retrieval is likely to combine both worlds:
vectors for similarity, graphs for context.
Why Geographic Knowledge Graphs Matter
Most organizations already possess geographic information.
What they often lack is a semantic layer capable of connecting that information.
Knowledge graphs bridge that gap.
They allow geographic data to move beyond visualization and become part of a reasoning system.
This has applications in:
- GIS
- logistics
- tourism
- real estate
- market analysis
- recommendation systems
- digital twins
- GraphRAG architectures
- location intelligence
The future of geographic data is not simply mapping.
It is contextual understanding.
And contextual understanding begins with relationships.









