Welcome to mirror list, hosted at ThFree Co, Russian Federation.

README.md - github.com/mapsme/just_gtfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7cfbef3f323dc4936e42efa7f503cd40c691999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# just_gtfs - header-only modern C++ library for reading and writing GTFS feeds

[![GTFS parser for C++](https://github.com/mapsme/just_gtfs/blob/add-the-most-important-readers/docs/logo.jpeg)](https://github.com/mapsme/just_gtfs)

[![C++](https://img.shields.io/badge/c%2B%2B-17-informational.svg)](https://shields.io/)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
![](https://github.com/mapsme/just_gtfs/workflows/C%2FC%2B%2B%20CI/badge.svg)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/mapsme/just_gtfs/issues)

 - Fast reading and writing of GTFS feeds
 - Supports [extended GTFS route types](https://developers.google.com/transit/gtfs/reference/extended-route-types)
 - Header-only
 - C++17
 - Tested on GCC and Clang
 - STL-compatible containers
 
## Table of Contents
- [Working with GTFS feeds](#working-with-gtfs-feeds)
- [How to use library](#how-to-use-library)
- [Used third-party tools](#used-third-party-tools)
- [Contributing](#contributing)
- [Resources](#resources)

## Working with GTFS feeds
The library implements reading and writing static transit data in GTFS - [General Transit Feed Specification](https://developers.google.com/transit/gtfs/reference).
It provides main class `gtfs::Feed` for working with GTFS feeds and classes for each of 17 GTFS entities: `Route`, `Stop`, `Pathway`, `Translation` and others.
GTFS csv files are mapped to the corresponding C++ classes. Every GTFS entity can be accessed through `gtfs::Feed`.

:pushpin: Example of providing `gtfs::Feed` the feed path, reading it and working with GTFS entities such as stops and routes:
```c++
Feed feed("~/data/SFMTA/");
if (feed.read_feed() == ResultCode::OK)
{
	Stops stops = feed.get_stops();
	std::cout << stops.size() << std::endl;

	Route route = feed.get_route("route_id_1009");
	if (route)
	{
		std::cout << route->route_long_name << std::endl;
	}
}
```

GTFS feed can be wholly read from directory as in the example above or you can read GTFS files separately. E.g., if you need only shapes data, you can avoid parsing all other files and just work with the shapes.

:pushpin: Example of reading only `shapes.txt` from the feed and working with shapes:
```c++
Feed feed("~/data/SFMTA/");
if (feed.read_shapes() == ResultCode::OK)
{
	Shapes all_shapes = feed.get_shapes();
	Shape shape = feed.get_shape("9367");
}
```


### Methods for reading and writing GTFS entities
Methods of the `Feed` class for working with agencies:

Read agencies from the corresponding csv file.
```c++
Result read_agencies()
```

Get reference to `Agencies` - `std::vector` of `Agency` objects.
```c++
const Agencies & get_agencies()
```

Find agency by its id. This method returns `std::optional` so you should check if the result is `std::nullopt`.
```c++
std::optional<Agency> get_agency(const Id & agency_id)
``` 

Add agency to the feed.
```c++
void add_agency(const Agency & agency)
```

Add agency to the feed by filling agency object fields with parsed csv values. `row` is `std::map` with csv column titles as keys ans csv row items as values. 
```c++
Result add_agency(ParsedCsvRow const & row)
```


:pushpin: **There are similar methods for all other GTFS entities** for getting the list of entities, finding and adding them.
For some of them additional methods are provided. 
For example, you can find all the stop times for current stop by its id:
```c++
StopTimes get_stop_times_for_stop(const Id & stop_id)
```

Or you can find stop times for the particular trip:
```c++
StopTimes get_stop_times_for_trip(const Id & trip_id, bool sort_by_sequence = true)
```


## How to use library
- For including the library in your own project: just_gtfs is completely contained inside a single header and therefore it is sufficient to copy include/just_gtfs/just_gtfs.h to your include pathes. The library does not have to be explicitly build.
- For running library tests:
Clone just_gtfs with `git clone --recursive` or run `git submodule update --init --recursive --remote` after cloning.
In the just_gtfs project directory build the project and run unit tests: 
```
cmake .
make
ctest --output-on-failure --verbose
```
The library makes use of the C++17 features and therefore you have to use appropriate compiler version.
- For including as a submodule: use branch "for-usage-as-submodule" which consists of a single header.

## Used third-party tools
- [**doctest**](https://github.com/onqtam/doctest) for unit testing.

## Contributing
Please open a [Github issue](https://github.com/mapsme/just_gtfs/issues/new) with as much of the information as you're able to specify, or create a [pull request](https://github.com/mapsme/just_gtfs/pulls) according to our [guidelines](https://github.com/mapsme/just_gtfs/blob/master/docs/CPP_STYLE.md).

## Resources
[GTFS reference in Google GitHub repository](https://github.com/google/transit/blob/master/gtfs/spec/en/reference.md)

[GTFS reference on Google Transit API](https://developers.google.com/transit/gtfs/reference?csw=1)