Fcd2pgsql
A small Java tool to mapmatch Floating Car Data and import it as Linestring ZM (x, y, speed, time) to PostGIS
Install / Use
/learn @MAGDa-BeuthHS/Fcd2pgsqlREADME
FCD2pgSQL
FCD2pgSQL is a small Java tool to map match Floating Car Data (FCD) and import it as Linestring ZM (x, y, speed, time) to PostGIS.
Setup
As of v0.1, FCD2pgSQL reads raw FCD already imported a PostgreSQL database and not directly from GPX or GPS files. If you want to use the tool straight away you need to import your data to PostgreSQL first. This is the relevant part of the schema we are using:
Table: FLOATING_CAR_DATA
| gps_time | car_id | longitude | latitude | speed | | --------- |:-------:|:---------:|:---------:|:-----:| | | | | | |
Execute
Build FCD2pgSQL with Maven and run the jar file with the following arguments:
- host address of Postgres server
- port of Postgres server
- database name
- user name
- user password
- path to OSM file
- path for Graphhopper files (just an empty directory where Graphhopper creates the routing graph)
How it works
1. Read from DB
For each FCD sender (car id) FCD2pgSQL fetches a list of all recorded GPS points. It connects multiple points to a GPX track as long as the time and distance between two point does not exceed 1 minute and 1 kilometer.
2. Map Matching using Graphhopper's MapMatching API
When a track is complete we send it to the map matcher class where it is matched against the Graphhopper routing graph. Note, that Graphhopper relies on OpenStreetMap, but the resulting tracks are not 100% identical to the OSM roads.
3. Copy timestamps and speed values
Up till now, Graphhopper's Map Matching algorithm does not return the time at the resulting points. So we tried to build a workaround for this. First, we try to find points in the matched track that come very close (> 50m) to the points of the original GPS track. This is not trivial, as for each point there can be multiple matching candidates. We are choosing the one with minimum distance. We then copy the timestamp and the speed value to the list of matched points.
Still, the matched tracks can have gaps with no time and speed. To fill the gaps we are interpolating the speed linearly between points that have a measure. With the speed value we can calclulate the time at each point (2s/V). When there is a gap at the start or end of the track we simply copy the speed value unless the gap is not bigger than 200m.
4. Importing the matched track
We import th track as a PostGIS linestring with speed as the Z value and time as the M. The target Postgres database needs to have the PostGIS extension installed. FCD2pgSQL creates the target table (and sequence) on the first run. Therefore, the selected user role need to have sufficient database privileges. The target table has the following schema:
| id | start_time | end_time | geom | | --- |:----------:|:--------:|:----:| | | | | |
5. Working with the data
The resulting linestrings allow for some intersting queries using linear referecing methods. More explanation coming soon.
Changelog
v0.1
- reads FCD from Postgres
- performs MapMatching using Graphhopper
- interpolates time and speed
- writes results to PostGIS as LineString ZM
Future Plans
- Direct import from CSV,GPX
- Include parallelization
Developers
- Felix Kunde
- Manal Faraj
- Stephan Pieper
Contact
- fkunde [at] beuth-hochschule.de
- spieper [at] beuth-hochschule.de
- sauer [at] beuth-hochschule.de
Special Thanks
- Graphhopper for their MapMatching API and support
- TU Dresden for FCD test data
Acknowledgement
FCD2pgSQL has been realized within the ExCELL project funded by the Federal Ministry for Economic Affairs and Energy (BMWi) and German Aerospace Center (DLR) - agreement 01MD15001B.
Related Skills
feishu-drive
339.5k|
things-mac
339.5kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
339.5kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
yu-ai-agent
2.0k编程导航 2025 年 AI 开发实战新项目,基于 Spring Boot 3 + Java 21 + Spring AI 构建 AI 恋爱大师应用和 ReAct 模式自主规划智能体YuManus,覆盖 AI 大模型接入、Spring AI 核心特性、Prompt 工程和优化、RAG 检索增强、向量数据库、Tool Calling 工具调用、MCP 模型上下文协议、AI Agent 开发(Manas Java 实现)、Cursor AI 工具等核心知识。用一套教程将程序员必知必会的 AI 技术一网打尽,帮你成为 AI 时代企业的香饽饽,给你的简历和求职大幅增加竞争力。
