This project includes LandXML parser (ver 0.3), civil model generation from LandXML, civil model server and web viewer.
- LandXML parser to read alignments, cross sections, vertical alignments and convert JSON, excel.
- Export landxml to sqlite, mongodb with test program.
- Civil model server to support OpenAPI as demonstration.
- Civil model web viewer to support visualization for landxml in web as demonstration.
It is easy to develop converter from LandXML to database, file such as JSON, MongoDB, sqlite etc.
By using LandXML parser, web-based model viewer, converter, application can be developed like below.
- 0.1: Sep 2023. draft version. xml parser
- 0.2: Feb 2024. landxml parser was released. support alignment, cross section, profile
- 0.3: Mar 2025. Open API server and web viewer for landxml as demo was released
- TBD: TIN, clothoid etc
pip install pandas numpy matplotlib openpyxl Pillow plotly pyquaternion regex scikit-learn scipy simplification tqdm zipp
If you want to test sqlite database, install the sqlite3. If there is error sqlite package error, refer to the below page.
- sqlite3 download to your python virtual environment or ananconda environment
pip install django uvicorn flask oauthlib pymongo
git clone https://github.com/mac999/landxml_parser
python test_landxml_parser.py
It's simple to use landxml parser.
- import landxml_parser, civil_model and civil_geo_engine
- make landxml() and load landxml file
- make civil model using the landxml dataset
- initialize model to calculate the design parameters of it
- use API like get_alignment, get point at station etc.
import landxml_parser as lxml, civil_geo_engine as cge
from civil_geo_engine import civil_model
def test_polyline_grid(cm):
align = cm.get_alignment(0) # Get the first alignment
if align == None:
print("No alignment")
return
align.show_polyline()
def main():
lp = lxml.landxml() # Define landxml parser
# model = lp.load('./landxml_railway_sample.xml') # Load landxml file
model = lp.load('./landxml_road_sample.xml')
# print(model)
lp.save('output_landxml.json') # Convert landxml file to json and save
cm = civil_model(model) # Define model for alignment calculation
cm.initialize() # Generate alignment calculation information
test_polyline_grid(cm)
You can run the web viewer of landxml as demo.
- run the below command and visit URL http://127.0.0.1:8000/map
cd web_app
python manage.py runserver
To upload your landxml file into MongoDB, visit http://127.0.0.1:8000/import_model/ and upload your landxml file.
In addition, the web viewer supports
- http://127.0.0.1:8000/import_model/: import model files into MongoDB
- http://127.0.0.1:8000/map/: show map
- http://127.0.0.1:8000/show_test_alignment_data/: show test alignment data
- http://127.0.0.1:8000/show_test_alignment_blocks_data/: show test alignment blocks data
- http://127.0.0.1:8000/show_test_alignment_xsections_parts_data/: show test alignment xsections parts data
This Open API server is demo version to show how to make server using landxml parser. It uses ./landxml_road_sample.xml file for demonstration.
- run the below command and visit URL http://127.0.0.1:8001
uvicorn open_api_server:app --reload --port 8001 --ws-max-size 16777216
It supports the below
- http://127.0.0.1:8001/v1/calc/align: end point to test massive calculation about landxml model
- http://127.0.0.1:8001/ws/align: end point to receive the large volume JSON dataset of landxml
To run client, execute the below, the two end points will be tested.
python open_api_client_call_api.py
This repository contains Python scripts for exporting and processing civil engineering alignment data from LandXML. The scripts support SQLite and MongoDB databases and include test modules for verifying calculations and data transformations.
install the below program.
π¦ Civil_Model_Export
βββ export_sqlite.py # Exports alignment data to SQLite
βββ export_mongodb.py # Exports alignment data to MongoDB
βββ export_xsections_mongodb.py # Exports cross-section data to MongoDB
βββ test_road_block_grid.py # Tests polyline and block grid generation
βββ test_sta_perp_offset.py # Tests perpendicular offset calculations
βββ test_sta_pos_calc.py # Tests station position calculations
βββ test_xsection.py # Tests cross-section visualization
βββ test_geo_calculation.py # Tests geographic coordinate conversions
βββ test_landxml_parser.py # Parses LandXML data
βββ README.md # Project documentation
- Reads alignment data from LandXML.
- Converts alignment coordinates.
- Stores alignment station points into a SQLite database (
civilmodel.db
).
-
SQLite3 Integration:
conn = sqlite3.connect('civilmodel.db') cursor = conn.cursor()
- Connects to SQLite and prepares a table (
test_alignment
).
- Connects to SQLite and prepares a table (
-
Alignment Processing:
sta_list, points = align.get_polyline(20.0) sta_offset_list, offset_points = align.get_offset_polyline(20, 10)
- Generates station points and offset points every 20 meters.
-
Coordinate Transformation:
gsr80_points = cge.convert_coordinates(x, y) gsr80_offset_points = cge.convert_coordinates(offset_x, offset_y)
- Converts coordinates to a specific reference system.
-
Data Storage in SQLite:
cursor.execute('''INSERT INTO test_alignment VALUES (?, ?, ?, ?, ?, ?)''', ...) conn.commit()
- Stores alignment data with station name, coordinates, and offsets.
-
Execution Flow:
- Loads LandXML.
- Initializes civil model.
- Extracts alignments and exports them to SQLite.
- Extracts cross-section data from alignments.
- Stores cross-section parts in MongoDB.
-
MongoDB Connection:
client = MongoClient('localhost', 27017) db = client['civil_model_db'] collection = db['test_alignment_xsections_parts']
- Connects to MongoDB and selects the test_alignment_xsections_parts collection.
-
Cross-Section Processing:
xsections = align.get_xsections()
- Retrieves all cross-sections.
-
Data Storage in MongoDB:
collection.insert_one(data)
- Stores each cross-section's station index, name, part details, and coordinates.
-
Execution Flow:
- Loads LandXML.
- Extracts alignments and cross-sections.
- Saves data in MongoDB.
- Extracts and exports alignment data and alignment blocks.
- Stores the results in MongoDB.
-
MongoDB Connection:
client = MongoClient('localhost', 27017) db = client['civil_model_db'] collection = db['test_alignment']
- Connects to the civil_model_db database.
-
Alignment Processing:
sta_list, points = align.get_polyline(20.0)
- Generates points every 20 meters.
-
Storing Data:
collection.insert_one(data)
- Saves alignment data, including:
- Station name (
1+140
,2+250
, etc.). - Coordinates (
x
,y
). - Offset values.
- Station name (
- Saves alignment data, including:
-
Block Processing:
blocks = align.get_block_points(10.0)
- Extracts block-level alignment data at 10-meter intervals.
-
Execution Flow:
- Loads LandXML.
- Extracts alignments and blocks.
- Saves results in MongoDB.
Script | Database | Purpose |
---|---|---|
export_sqlite.py |
SQLite | Exports alignment data to a local SQLite DB. |
export_xsections_mongodb.py |
MongoDB | Stores cross-section data in MongoDB. |
export_mongodb.py |
MongoDB | Exports alignments and blocks to MongoDB. |
Script | Purpose |
---|---|
test_road_block_grid.py |
Tests polyline and block grid visualization. |
test_sta_perp_offset.py |
Computes perpendicular offsets for alignment. |
test_sta_pos_calc.py |
Computes station positions and visualizes alignments. |
test_xsection.py |
Plots cross-section data. |
test_geo_calculation.py |
Converts geographic coordinates. |
test_landxml_parser.py |
Parses LandXML files and saves JSON output. |
- Run any test script:
python test_xsection.py
- Author: Kang Taewook
- Email: [email protected]
This project is licensed under the MIT License.