GRAX
GRAX is a lightweight Python library for transforming geospatial shapefiles into machine-learning-ready graph networks using NetworkX.
It automates the full pipeline from raw GIS data → graph structure → ML-ready inputs, enabling seamless integration with:
- Graph Neural Networks (GNNs)
- Complex Network Analytics (CNA)
- Spatial ML models
- Routing and navigation algorithms
- Digital twin simulations
- Infrastructure ML pipelines
Whether you are building a road network classifier, a pipeline failure predictor, a mobility model, or a full city-scale digital twin, GRAX converts raw line data into a structured graph with accurate topology and geometry.
📦 Installation
Install from PyPI
pip install grax
🔥 Why GRAX?
Most ML/AI models require structured graph data, not shapefile polylines.
GRAX bridges this gap by:
- Converting shapefile line geometries into numerical matrices
- Automatically detecting intersections using Shapely
- Building a topologically correct NetworkX graph
- Embedding node attributes (x, y)
- Producing a graph that is directly usable for:
- PyTorch Geometric
- DGL
- StellarGraph
- NetworkX-based ML
- Custom GNN pipelines
The goal:
Turn raw geospatial networks into graph datasets that you can directly feed into ML models.
⚙️ Features
- ✅ Converts shapefiles into clean numerical tensors (NumPy matrices)
- ✅ Builds graphs for graph theory and ML tasks
- ✅ Automatic node creation at all intersections (crucial for routing & GNNs)
- ✅ Each node stores geometry → perfect for spatial embeddings
- ✅ Produces NetworkX graphs ready for: node classification/link prediction/graph embeddings/centrality-based ML features
- ✅ Ideal preprocessing step before feeding data into PyTorch Geometric or DGL
- ✅ Designed for digital twins & infrastructure ML (roads, utilities, pipelines)
📚 API Reference
Class grax
grax(
verbose=0 # prints intersection detection logs
)
Function digitize_shape()
Converts a list of LineString geometries into ML-friendly numerical matrices.
digitize_shape(shapefile)
Function create_network()
Takes digitized matrices and constructs a full-resolution graph with:
- Accurate topology
- Intersection nodes (is_i_j_k)
- Node attributes (x, y)
- Edges representing real connectivity
create_network(L)
🚀 Quickstart: From Shapefile to ML-Ready Graph
from grax import grax
# Initialize GRAX
g = grax(verbose=1)
# Step 1 — Digitize the shapefile
L = g.digitize_shape("city_roads.shp")
# Step 2 — Build the full network graph
G = g.create_network(L)
print("Nodes:", len(G.nodes()))
print("Edges:", len(G.edges()))
🧠 How GRAX Enables ML
1. ML-Ready Node Features
Every node comes with spatial features:
{x: longitude, y: latitude}
You can extend this with:
- elevation
- traffic flows
- utility capacity
- population density
- environmental layers
2. Topologically Correct Graphs
Many ML tasks require correct topology:
- shortest paths
- flow simulation
- infrastructure interdependency models
- GNNs using neighborhood aggregation
- GRAX ensures that all intersections become actual nodes, which is critical for ML accuracy.
3. Perfect for Graph Neural Networks
GNN performance depends on:
- Proper graph structure
- Correct adjacency
- Meaningful node features
- GRAX creates exactly that from raw spatial data.
🗺️ Real-World ML Applications
GRAX is used in:
🚗 Traffic prediction models
💧 Water or gas pipeline monitoring
🌆 Urban digital twin systems
🚉 Transit network optimization
🛣️ Road network risk modeling
🌪️ Disaster response routing ML
🧠 CNA (Complex Network Analytics) models
🛰️ Spatial graph embeddings
It is engineered for modern AI workflows in civil engineering, infrastructure, and geospatial ML.
📜 License
This project is licensed under the MIT License.
© 2025 Dr. Ahmed Moussa
🤝 Contributing
Pull requests are welcome.
For major changes, please open an issue first to discuss what you would like to change.
📫 Contact
For feedback, bugs, or collaboration ideas:
- GitHub: @real-ahmed-moussa
⭐️ Show Your Support
If you find this project useful, consider giving it a ⭐️ on GitHub!
Metadata
Release files for grax 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| grax-0.1.0.tar.gz | 6.0 kB | Without provenance | Details for grax-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| grax-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for grax-0.1.0-py3-none-any.whl |
Total release size: 11.8 kB
Release files / grax-0.1.0.tar.gz
| Download URL | grax-0.1.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
899bbc978b20c280e2d8b3af5837820911a08793c53919a387604e2b8cda1d71
|
|
BLAKE2b-256 checksum How to use checksums |
f40d1fbf1a7ad326f3de85ede18675148b79904c18fac41daa9899a82e18b6d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.8
|
Release files / grax-0.1.0-py3-none-any.whl
| Download URL | grax-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6653484fd9ef85dffbd87e1288b1c0a9cf8febec21a728a185efb103db2a5b8a
|
|
BLAKE2b-256 checksum How to use checksums |
24c52559e647d21dddefeb2b3153fb30af37600932d81572145e72be8c25ba0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.8
|
Security for grax 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.