gtfs-geojson 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf0802ca353854ab37535916e773d218dd124777
4
- data.tar.gz: 0fbfd39b2ba56f71fbe012d14d8bcced4ff103a4
3
+ metadata.gz: 0cf8cde58aae1fc47ea83fc736c9098dda567c7b
4
+ data.tar.gz: fdafe8a7355e0a96085dc985551bc4a825287adc
5
5
  SHA512:
6
- metadata.gz: 9c7170ff74b74d89ba3c53eaed0ef0be9c403cd758f645ae0b25792c4f78c2cd29903302bf4c735141d33ed1aa7bc4ac9c1f5e1b651b3505904861cd6c328fa7
7
- data.tar.gz: 77f0ff96a0526e6ac966bf4df2b47fe7bbba3323d6c6ac5b0463351f29b0fed0fd02965b9b3ee41bdc4a494420fc755bd94255bb6a89b2d41aba41535e4bef5d
6
+ metadata.gz: 1e87025d9031bb79f5bf70a8f1abfd84a02bbf6077664b4e4666a8aa883c6a433682b2abfa634b2f4b1682a577a8554e61b3c0835607c53b17c629bdf9cee4bd
7
+ data.tar.gz: 656d7cdf40cc6269d517b2e3c8d711fa51b668856a74bd001bacbb4a44a3373672179933a3b0df078b1ac41558387e99cf5861c9132cc14b45e2f4caa8ffae94
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'gtfs'
4
- gem 'minitest'
5
- gem 'simplecov'
3
+ gem 'gtfs', '~>0.2.5'
4
+ gem 'minitest', '~>5.8.4'
5
+ gem 'simplecov', '~>0.11.2'
6
+ gem 'gtfs-realtime-bindings', '~>0.0.5'
@@ -1,30 +1,50 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
+ activesupport (4.2.6)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
4
10
  docile (1.1.5)
5
11
  gtfs (0.2.5)
6
12
  multi_json
7
13
  rake
8
14
  rubyzip (~> 1.1)
15
+ gtfs-realtime-bindings (0.0.5)
16
+ protobuf (>= 3.0)
17
+ i18n (0.7.0)
9
18
  json (1.8.3)
19
+ middleware (0.1.0)
10
20
  minitest (5.8.4)
11
- multi_json (1.11.2)
12
- rake (10.5.0)
13
- rubyzip (1.1.7)
21
+ multi_json (1.11.3)
22
+ protobuf (3.6.7)
23
+ activesupport (>= 3.2)
24
+ middleware
25
+ thor
26
+ thread_safe
27
+ rake (11.1.2)
28
+ rubyzip (1.2.0)
14
29
  simplecov (0.11.2)
15
30
  docile (~> 1.1.0)
16
31
  json (~> 1.8)
17
32
  simplecov-html (~> 0.10.0)
18
33
  simplecov-html (0.10.0)
34
+ thor (0.19.1)
35
+ thread_safe (0.3.5)
36
+ tzinfo (1.2.2)
37
+ thread_safe (~> 0.1)
19
38
 
20
39
  PLATFORMS
21
40
  ruby
22
41
  x64-mingw32
23
42
 
24
43
  DEPENDENCIES
25
- gtfs
26
- minitest
27
- simplecov
44
+ gtfs (~> 0.2.5)
45
+ gtfs-realtime-bindings (~> 0.0.5)
46
+ minitest (~> 5.8.4)
47
+ simplecov (~> 0.11.2)
28
48
 
29
49
  BUNDLED WITH
30
50
  1.11.2
data/README.md CHANGED
@@ -1,18 +1,49 @@
1
1
  # gtfs-geojson
2
+ [![Circle CI](https://circleci.com/gh/tyleragreen/gtfs-geojson.svg?style=svg)](https://circleci.com/gh/tyleragreen/gtfs-geojson)
2
3
 
3
- A Ruby utility to convert the shapes.txt file of a GTFS feed into a GeoJSON file.
4
+ gtfs-geojson is a Ruby utility to convert the shapes.txt file of a GTFS feed into a GeoJSON file. It uses the [GTFS](https://github.com/nerdEd/gtfs) gem to validate GTFS feeds and wrap the feed data into usable objects. Two command-line utilities are also included with a gem install.
5
+
6
+ ## Installation
7
+
8
+ Add the following to your Gemfile.
9
+ ```
10
+ gem 'gtfs-geojson'
11
+ ```
12
+ or install the gem through the command line.
13
+ ```
14
+ gem install `gtfs-geojson`
15
+ ```
16
+
17
+ ## Command-Line Utilities
18
+ Convert a GTFS feed shapes.txt file into a GeoJSON file.
19
+ ```
20
+ gtfs_to_geojson gtfs.zip output.geojson
21
+ ```
22
+ Print a human-readable form of a GTFS-realtime feed.
23
+ ```
24
+ gtfs-rt_to_json http://developer.mbta.com/lib/GTRTFS/Alerts/VehiclePositions.pb positions.json
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ require 'gtfs-geojson'
31
+ geojson = GTFS::GeoJSON.generate("gtfs.zip")
32
+ File.open("gtfs.geojson",'w') do { |f| f.write(geojson) }
33
+ ```
4
34
 
5
35
  ## Develop Locally
36
+ To develop locally, clone the repository and run bundler to setup the necessary gems.
6
37
  ```
7
38
  bundle install
8
39
  ```
9
- ### Run Tests
40
+ #### Run Tests
10
41
  ```
11
- rake
42
+ bundle exec rake
12
43
  ```
13
- ### Run Tests and Collect Code Coverage
44
+ #### Run Tests and Collect Code Coverage
14
45
  ```
15
- rake coverage
46
+ bundle exec rake coverage
16
47
  ```
17
- ## Issues
48
+ ## Contribute
18
49
  Please contact Tyler at [greent@tyleragreen.com](mailto:greent@tyleragreen.com) or file a GitHub Issue with any ideas or suggestions.
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # A command-line tool to convert a GTFS-realtime protocol buffer (*.pb)
4
+ # into a human-readable JSON output. This is useful to verify the
5
+ # data from the GTFS-realtime feed before consuming it in another application.
6
+ #
7
+ # Usage: gtfs-rt_to_json <gtfs-realtime_feed_path> <json_output_path>
8
+ #
9
+ # Author: Tyler A. Green (greent@tyleragreen.com)
10
+ #
11
+ require 'google/transit/gtfs-realtime.pb'
12
+ require 'net/http'
13
+ require 'json'
14
+
15
+ raise StandardError, "Two arguments required." if ARGV.length < 2
16
+
17
+ data = Net::HTTP.get(URI.parse(ARGV[0]))
18
+ feed = Transit_realtime::FeedMessage.decode(data)
19
+
20
+ f = File.open(ARGV[1],'w')
21
+ f.write(JSON.pretty_generate(feed))
22
+ f.close
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # A command-line tool to convert a GTFS feed shapes.txt file
4
+ # into a GeoJSON file.
5
+ #
6
+ # Usage: gtfs_to_geojson <gtfs_feed_path> <geojson_output_path>
7
+ #
8
+ # Author: Tyler A. Green (greent@tyleragreen.com)
9
+ #
10
+ require_relative '../lib/gtfs-geojson'
11
+
12
+ raise StandardError, "Two arguments required." if ARGV.length < 2
13
+
14
+ geojson = GTFS::GeoJSON.generate(ARGV[0])
15
+ f = File.open(ARGV[1],'w')
16
+ f.write(geojson)
17
+ f.close
@@ -14,11 +14,13 @@ Gem::Specification.new do |gem|
14
14
  gem.license = 'MIT'
15
15
 
16
16
  gem.add_dependency 'gtfs', '0.2.5'
17
+ gem.add_dependency 'gtfs-realtime-bindings', '0.0.5'
17
18
 
18
19
  gem.add_development_dependency 'simplecov', '0.11.2'
19
20
  gem.add_development_dependency 'minitest', '5.8.4'
20
21
 
21
22
  gem.files = `git ls-files`.split("\n")
22
23
  gem.test_files = `git ls-files -- test/*`.split("\n")
24
+ gem.executables = ["gtfs-rt_to_json","gtfs_to_geojson"]
23
25
  gem.require_path = 'lib'
24
26
  end
@@ -8,11 +8,15 @@ module GTFS
8
8
  module GeoJSON
9
9
 
10
10
  def self.generate(path)
11
+ raise ArgumentError if !File.exist?(path)
12
+
13
+ # Confirm the GTFS feed is valid
11
14
  source = GTFS::Source.build(path,{strict:true})
12
15
 
13
16
  routes = {}
14
17
  features = []
15
-
18
+
19
+ # Group the routes by the route id
16
20
  source.shapes.each do |shape|
17
21
  if routes[shape.id]
18
22
  routes[shape.id] << shape
@@ -21,14 +25,21 @@ module GTFS
21
25
  end
22
26
  end
23
27
 
28
+ # Process the data a route at a time
24
29
  routes.each do |route,points|
25
30
  coordinates = []
31
+
32
+ # Sort the points by their point sequence ID, as it may be
33
+ # out of order in the GTFS feed, but must be in order to appear
34
+ # correct for GeoJSON
26
35
  points.sort! { |a,b| a.pt_sequence.to_i <=> b.pt_sequence.to_i }
27
36
 
37
+ # Add each sorted point to a list of coordinates for this route
28
38
  points.each do |point|
29
39
  coordinates << [ point.pt_lon.to_f, point.pt_lat.to_f ]
30
40
  end
31
-
41
+
42
+ # Construct a feature and add it to the feature list for this route
32
43
  features << { type: 'Feature',
33
44
  properties: { name: route
34
45
  },
@@ -39,6 +50,8 @@ module GTFS
39
50
 
40
51
  end
41
52
 
53
+ # Create the GeoJSON file by generating a JSON string wrapped
54
+ # in a FeatureCollection
42
55
  return JSON.generate({type: 'FeatureCollection', features: features})
43
56
  end
44
57
  end
@@ -1,5 +1,5 @@
1
1
  module GTFS
2
2
  module GeoJSON
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -3,6 +3,11 @@
3
3
  require_relative 'test_helper'
4
4
 
5
5
  class TestGtfs < Minitest::Test
6
+
7
+ def test_invalid_file_fails_cleanly
8
+ assert_raises(ArgumentError) { GTFS::GeoJSON.generate("non_existent_file") }
9
+ end
10
+
6
11
  def test_valid_gtfs
7
12
  geojson = GTFS::GeoJSON.generate("test/fixtures/valid_gtfs.zip")
8
13
  shapes = File.read("test/fixtures/shapes.geojson")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtfs-geojson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tyleragreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-12 00:00:00.000000000 Z
11
+ date: 2016-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtfs
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.2.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: gtfs-realtime-bindings
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.5
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: simplecov
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,7 +70,9 @@ description: gtfs-geojson is a Ruby utility to convert the shapes.txt file from
56
70
  GTFS feed into a GeoJSON file.
57
71
  email:
58
72
  - greent@tyleragreen.com
59
- executables: []
73
+ executables:
74
+ - gtfs-rt_to_json
75
+ - gtfs_to_geojson
60
76
  extensions: []
61
77
  extra_rdoc_files: []
62
78
  files:
@@ -65,6 +81,8 @@ files:
65
81
  - Gemfile.lock
66
82
  - README.md
67
83
  - Rakefile
84
+ - bin/gtfs-rt_to_json
85
+ - bin/gtfs_to_geojson
68
86
  - gtfs-geojson.gemspec
69
87
  - lib/gtfs-geojson.rb
70
88
  - lib/gtfs-geojson/version.rb
@@ -93,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
111
  version: '0'
94
112
  requirements: []
95
113
  rubyforge_project:
96
- rubygems_version: 2.5.1
114
+ rubygems_version: 2.4.8
97
115
  signing_key:
98
116
  specification_version: 4
99
117
  summary: Convert GTFS to GeoJSON