geo-cli 0.0.1.pre2 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4636a266ddd9104cc19e1f45a67135f200789ac9
4
- data.tar.gz: b794b6c2d0c5adff836dbf7925737b3c039fe536
3
+ metadata.gz: fe4a7f6a7976742fcd78ec2ed65c93f565202453
4
+ data.tar.gz: 00d8e7c4c7daed2c09606adb1df3db806dab4274
5
5
  SHA512:
6
- metadata.gz: ddb013a6d8131ef1b0ee5468032723c319220c0d7777dd87d4a0d868d196a958a4d144f0caff090782607b7e46ebd0653c6ac4eefd464cee0d6889d80e6a15fd
7
- data.tar.gz: 31bd21346a46d36bb85f1c7567b0df968b0afa2642824aa424253c1b472ee5d81b3743a9232ff2313126095bc51e302807188b0c5fbf6c19f98a0eaad4f829b6
6
+ metadata.gz: aec4b2c462c757cee0aa69a199544e7384f07065a638ad5278e5d3de8a833fc4724c669894a61ff2c4c04b593c9951523e1267b1ecb36d3280934d86a62eb131
7
+ data.tar.gz: 4cd9eeb76df744d9b1c9cf8d978add9db9b64a844bb0eb0ee9d13417f5f2a023496dd8c08ce33a171387f761572ab0af0d3554c191f5e055dfc070dfaecbb0a6
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geo-cli (0.0.1)
5
- gli (= 2.17.1)
4
+ geo-cli (0.0.1.pre2)
5
+ gli (~> 2.17)
6
6
  pr_geohash (~> 1.0)
7
- rgeo
8
- rgeo-geojson
7
+ rgeo (~> 1.0)
8
+ rgeo-geojson (~> 2.0)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -73,13 +73,13 @@ PLATFORMS
73
73
  ruby
74
74
 
75
75
  DEPENDENCIES
76
- aruba
76
+ aruba (~> 0.14)
77
77
  geo-cli!
78
78
  minitest (~> 5.11)
79
- minitest-reporters
80
- pry
81
- rake
82
- rdoc
79
+ minitest-reporters (~> 1.2)
80
+ pry (~> 0.11)
81
+ rake (~> 12.3)
82
+ rdoc (~> 6.0)
83
83
 
84
84
  BUNDLED WITH
85
85
  1.16.1
@@ -14,22 +14,22 @@ include GLI::App
14
14
  program_desc <<-desc
15
15
  Geospatial utility belt
16
16
 
17
- geo-cli is a command-line tool for converting between various
18
- GIS serialization formats. For example:
17
+ geo-cli is a command-line tool for converting between various
18
+ GIS serialization formats. For example:
19
19
 
20
- echo 9q5 | geo-cli gj geometry
20
+ echo 9q5 | geo-cli gj geometry
21
21
 
22
- Will output the geohash 9q5 as a geojson geometry.
22
+ Will output the geohash 9q5 as a geojson geometry.
23
23
 
24
- Most commands will accept a Geohash (base 32 encoded), a WKT,
25
- or a GeoJSON input, and should recognize the input based on its
26
- format.
24
+ Most commands will accept a Geohash (base 32 encoded), a WKT,
25
+ or a GeoJSON input, and should recognize the input based on its
26
+ format.
27
27
 
28
- Commands expect one geo entity per line.
28
+ Commands expect one geo entity per line.
29
29
 
30
- See COMMANDS for more possible commands.
30
+ See COMMANDS for more possible commands.
31
31
 
32
- See geo-cli <COMMAND> --help for more info on a given command.
32
+ See geo-cli <COMMAND> --help for more info on a given command.
33
33
  desc
34
34
 
35
35
  version GeoCli::VERSION
@@ -63,7 +63,8 @@ command :gj do |c|
63
63
  c.desc "Combine entities into a geojson feature collection"
64
64
  c.command :fc do |c|
65
65
  c.action do |global_options,options,args|
66
- puts GeoCli::FeatureCollection.new(GeoCli::GeomReader.new(STDIN)).to_geojson
66
+ entities = GeoCli::GeomReader.new(STDIN)
67
+ puts GeoCli::Commands::GeoJson::FeatureCollection.new(entities).output
67
68
  end
68
69
  end
69
70
  end
@@ -3,6 +3,30 @@ require "rgeo"
3
3
  require "rgeo/geo_json"
4
4
 
5
5
  module GeoCli
6
+ module Commands
7
+ class Base
8
+ attr_reader :global_opts, :opts, :args, :instream
9
+ def initialize(instream, global_opts = {}, opts = {}, args = [])
10
+ @global_opts = global_opts
11
+ @opts = opts
12
+ @args = args
13
+ @instream = instream
14
+ end
15
+
16
+ def output
17
+ raise "Not implemented"
18
+ end
19
+ end
20
+
21
+ module GeoJson
22
+ class FeatureCollection < Base
23
+ def output
24
+ GeoCli::FeatureCollection.new(instream).to_geojson
25
+ end
26
+ end
27
+ end
28
+ end
29
+
6
30
  class Entity
7
31
  attr_reader :entity
8
32
 
@@ -37,6 +61,19 @@ module GeoCli
37
61
  end
38
62
 
39
63
  class GeoJson < Entity
64
+ def as_geojson(feature = false)
65
+ if feature
66
+ if entity.is_a?(RGeo::GeoJSON::Feature)
67
+ RGeo::GeoJSON.encode(entity)
68
+ else
69
+ {type: "Feature",
70
+ properties: {},
71
+ geometry: RGeo::GeoJSON.encode(entity)}
72
+ end
73
+ else
74
+ RGeo::GeoJSON.encode(entity)
75
+ end
76
+ end
40
77
  end
41
78
 
42
79
  class FeatureCollection
@@ -80,7 +117,7 @@ module GeoCli
80
117
  geom = RGeo::Cartesian::BoundingBox.create_from_points(p1, p2).to_geometry
81
118
  Geohash.new(geom)
82
119
  elsif geojson?(line)
83
- Geojson.new(RGeo::GeoJSON.decode(line))
120
+ GeoJson.new(RGeo::GeoJSON.decode(line))
84
121
  else
85
122
  Wkt.new(wkt.parse(line))
86
123
  end
@@ -1,3 +1,3 @@
1
1
  module GeoCli
2
- VERSION = '0.0.1.pre2'
2
+ VERSION = '0.0.1'
3
3
  end
@@ -10,6 +10,23 @@ class TestGeomReader < Minitest::Test
10
10
  @reader = GeoCli::GeomReader.new(r)
11
11
  end
12
12
 
13
+ def stream(strings)
14
+ r,w = IO.pipe
15
+ strings.each do |s|
16
+ w.puts(s)
17
+ end
18
+ w.close
19
+ GeoCli::GeomReader.new(r)
20
+ end
21
+
22
+ def mixed_stream
23
+ inputs = ["9q5",
24
+ {type: "Point", coordinates: [0,1]}.to_json,
25
+ "POINT (1.0 2.0)",
26
+ {type: "Feature", properties: {a: "b"}, geometry: {type: "Point", coordinates: [3,4]}}.to_json]
27
+ stream(inputs)
28
+ end
29
+
13
30
  def test_recognizes_geohashes
14
31
  assert @reader.geohash?("9q5")
15
32
  assert @reader.geohash?("9Q5")
@@ -24,21 +41,31 @@ class TestGeomReader < Minitest::Test
24
41
  end
25
42
 
26
43
  def test_parse_objects
27
- inputs = ["9q5",
28
- {type: "Point", coordinates: [0,1]}.to_json,
29
- "POINT (1.0 2.0)"]
30
- parsed = make_reader(inputs).to_a
31
- assert parsed[0].is_a? RGeo::Geos::CAPIPolygonImpl
32
- assert parsed[1].is_a?(RGeo::Geos::CAPIPointImpl)
33
- assert parsed[2].is_a?(RGeo::Geos::CAPIPointImpl)
44
+ parsed = mixed_stream.to_a
45
+ assert parsed[0].is_a? GeoCli::Geohash
46
+ assert parsed[1].is_a? GeoCli::GeoJson
47
+ assert parsed[2].is_a? GeoCli::Wkt
48
+ assert parsed[3].is_a? GeoCli::GeoJson
34
49
  end
35
50
 
36
- def make_reader(strings)
37
- r,w = IO.pipe
38
- strings.each do |s|
39
- w.puts(s)
40
- end
41
- w.close
42
- GeoCli::GeomReader.new(r)
51
+ def test_feature_collection
52
+ fc = GeoCli::Commands::GeoJson::FeatureCollection.new(mixed_stream)
53
+ json = JSON.parse(fc.output)
54
+ assert_equal "FeatureCollection", json["type"]
55
+ assert_equal ["type", "features"].sort, json.keys.sort
56
+ features = json["features"]
57
+ assert_equal 4, features.count
58
+
59
+ # encodes properties
60
+ assert_equal [{}, {}, {}, {"a" => "b"}], features.map { |f| f["properties"] }
61
+ assert_equal Hash.new, features[0]["properties"]
62
+ assert_equal Hash.new, features[1]["properties"]
63
+ assert_equal Hash.new, features[2]["properties"]
64
+ assert_equal({"a" => "b"}, features[3]["properties"])
65
+
66
+ assert_equal ["Polygon", "Point", "Point", "Point"], features.map { |f| f["geometry"]["type"] }
67
+
68
+ gh = [[[-119.53125, 33.75], [-118.125, 33.75], [-118.125, 35.15625], [-119.53125, 35.15625], [-119.53125, 33.75]]]
69
+ assert_equal [gh, [0.0,1.0], [1.0, 2.0], [3.0, 4.0]], features.map { |f| f["geometry"]["coordinates"] }
43
70
  end
44
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre2
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Horace Williams
@@ -197,9 +197,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
197
  version: '0'
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - ">"
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
- version: 1.3.1
202
+ version: '0'
203
203
  requirements: []
204
204
  rubyforge_project:
205
205
  rubygems_version: 2.5.1