Viewing Geotechnical Data in QGIS
In this guide, you will convert AGS files into a GeoPackage format that can be opened and visualized in QGIS. This process transforms specialized geotechnical data into standardized geospatial features that GIS software can understand.
Prerequisites
Section titled “Prerequisites”Before starting, ensure you have:
- Python installed with
bedrock-ge
package- We recommend using
uv
to manage Python
- We recommend using
- QGIS installed on your system
- AGS files containing geotechnical data
- Knowledge of your project’s coordinate reference system (CRS)
Step 1: Set Up Your Python Environment
Section titled “Step 1: Set Up Your Python Environment”Install the required packages if you haven’t already:
uv add bedrock-ge geopandas
Step 2: Define Coordinate Reference Systems
Section titled “Step 2: Define Coordinate Reference Systems”Identify the spatial reference systems used in your geotechnical data. You need both horizontal (projected) and vertical coordinate systems.
from pyproj import CRS
projected_crs = CRS("EPSG:2326") # Hong Kong 1980 Grid Systemvertical_crs = CRS("EPSG:5738") # Hong Kong Principle Datum
# Other common examples:# projected_crs = CRS("EPSG:27700") # OSGB36 / British National Grid (UK)# vertical_crs = CRS("EPSG:5701") # Ordnance Datum Newlyn (UK)
Use EPSG.io to find the correct codes for your project location.
Step 3: Convert Single AGS File
Section titled “Step 3: Convert Single AGS File”For a single AGS file, use this code to convert it to GeoPackage:
from pyproj import CRSfrom bedrock_ge.gi.mapper import map_to_brgi_dbfrom bedrock_ge.gi.ags import ags_to_brgi_db_mappingfrom bedrock_ge.gi.geospatial import create_brgi_geodbfrom bedrock_ge.gi.write import write_brgi_db_to_file
projected_crs = CRS("EPSG:2326")vertical_crs = CRS("EPSG:5738")
with open("your_data.ags") as ags_file: brgi_mapping = ags_to_brgi_db_mapping(ags_file, projected_crs, vertical_crs) brgi_db = map_to_brgi_db(brgi_mapping)
geodb = create_brgi_geodb(brgi_db)write_brgi_db_to_file(geodb, "gi_data.gpkg", driver="GPKG")
Step 4: Convert Multiple AGS Files
Section titled “Step 4: Convert Multiple AGS Files”When working with multiple AGS files from the same project:
import zipfilefrom pathlib import Pathfrom pyproj import CRSfrom bedrock_ge.gi.mapper import map_to_brgi_dbfrom bedrock_ge.gi.ags import ags_to_brgi_db_mappingfrom bedrock_ge.gi.geospatial import create_brgi_geodbfrom bedrock_ge.gi.write import write_brgi_db_to_filefrom bedrock_ge.gi.db_operations import merge_dbs
projected_crs = CRS("EPSG:2326")vertical_crs = CRS("EPSG:5738")
folder_path = Path("./ags_files")ags_files = list(folder_path.glob("*.ags"))
ags_file_brgi_dbs = []
for file_path in ags_files: print(f"Processing {file_path.name}...") with open(file_path) as ags_file: brgi_mapping = ags_to_brgi_db_mapping(ags_file, projected_crs, vertical_crs) brgi_db = map_to_brgi_db(brgi_mapping) ags_file_brgi_dbs.append(brgi_db)
merged_brgi_db = merge_dbs(ags_file_brgi_dbs)geodb = create_brgi_geodb(merged_brgi_db)write_brgi_db_to_file(geodb, "combined_gi_data.gpkg", driver="GPKG")
Step 5: Open GeoPackage in QGIS
Section titled “Step 5: Open GeoPackage in QGIS”-
Launch QGIS and create a new project
-
Add the GeoPackage layer:
- Go to Layer > Add Layer > Add Vector Layer
- Set Source Type to “File”
- Click Browse and select your
.gpkg
file - Click Add
-
Select tables to load:
- QGIS will show a dialog with available tables
- Key tables include:
LonLatHeight
: Ground investigation locations in WGS84 coordinatesLocation
: Borehole locations with 3D geometryInSituTests_GEOL
: Geological descriptions with depth intervalsInSituTests_ISPT
: Standard Penetration Test resultsInSituTests_WETH
: Weathering grade information
- Select the tables you want to visualize and click OK
Step 6: Style and Explore the Data
Section titled “Step 6: Style and Explore the Data”Basic Visualization
Section titled “Basic Visualization”-
View location points:
- The
LonLatHeight
table displays best as points on the map - Right-click the layer > Properties > Symbology
- Choose appropriate symbols and colors
- The
-
Examine test results:
- Tables like
InSituTests_ISPT
contain point data with test values - Use graduated symbols or colors based on values like
ISPT_NVAL
(SPT N-value)
- Tables like
Advanced Styling
Section titled “Advanced Styling”-
Filter data by values:
- Right-click layer > Filter
- Example:
"ISPT_NVAL" BETWEEN 1 AND 10
to show soft soils - Example:
"WETH_GRAD" NOT LIKE '%V%'
to show competent rock
-
Create thematic maps:
- Use Properties > Symbology > Graduated
- Classify by geological or geotechnical parameters
- Apply color ramps to visualize spatial patterns
Step 7: Working with 3D Data
Section titled “Step 7: Working with 3D Data”The converted data includes 3D geometries representing boreholes and test intervals:
-
Enable 3D view:
- Go to View > 3D Map Views > New 3D Map View
- Configure terrain and layer elevation properties
-
Vertical profiles:
- Use QGIS plugins like Profile Tool to create cross-sections through boreholes
- Examine geological layers and test results along specific alignments
Understanding the Output
Section titled “Understanding the Output”The GeoPackage contains multiple related tables:
- Project: Project-level information
- Location: Borehole/test locations with coordinates and ground levels
- LonLatHeight: Location points in WGS84 for web mapping compatibility
- InSituTests_: Various in-situ test results (GEOL, ISPT, WETH, etc.)
- Samples: Sample information if available in source data
- LabTests_: Laboratory test results if available
Each table includes:
- Geometry: 3D points or lines representing spatial location and depth
- Attributes: Test results, descriptions, and metadata
- Relationships: Links between projects, locations, samples, and tests
Next Steps
Section titled “Next Steps”After visualizing your data in QGIS, you can:
- Export styled maps as images or PDFs
- Perform spatial analysis using QGIS geoprocessing tools
- Integrate with other geospatial datasets
- Share data through web services or export to other formats
- Use QGIS plugins for specialized geotechnical analysis
Troubleshooting
Section titled “Troubleshooting”No geometry displayed: Ensure your coordinate reference systems are correct and match your data location.
Empty or missing data: Check that your AGS files contain location coordinates and the required data groups.
Coordinate system issues: Verify the EPSG codes match your project’s spatial reference systems using EPSG.io.
Large file performance: For projects with many boreholes, consider loading only essential tables initially.