terraformer 0.0.7 → 0.0.8

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: 54582188df43611a0c97f98da5aa5cb4d4536930
4
- data.tar.gz: 0980f0f42c63fbc4467f1d6cc8fbcf2d8f05b35a
3
+ metadata.gz: fee193b46a63e77c85cc7e9038265f18f4354330
4
+ data.tar.gz: 4e6ccf353873c97779a5a9adfd382fca1560dafe
5
5
  SHA512:
6
- metadata.gz: 5179f0a38c1f9be3484033b314b5a9ae9ebee77f887df1ab42473a3249851ff67761039905bb863be4ce8bc914f73fef974a6182ceb29e7c373a3eff526c94e7
7
- data.tar.gz: 83a1031d1f5721640184cd5fe0f5bdc6ac88294549622693dd0a747aa84a8081b9d11ade0b07e31a59b04773bcf9763d93f42fcc90c94fa3d776773d264c94c6
6
+ metadata.gz: e388553715283647e19799cd4cce2a9c1081b20fff457c9c64be5697e9ac912680f617c5f4b8d02ab77ca20628a2cac918eed94b911aa5b6589b98405daaa2ab
7
+ data.tar.gz: 800a2242a2e9736d1a205be2308727f5d8d029a61127bde45a8948d72ebc645c04a9fe4c488999a1e79ff377e29c9979df548ee80ddd289a231a2080c09b8553
data/Gemfile CHANGED
@@ -1,11 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake'
4
- gem 'launchy', require: nil
3
+ gem 'launchy', '~>2.4', require: nil
5
4
 
6
5
  group :test do
7
- gem 'http'
8
- gem 'pry'
9
- gem 'pry-nav'
10
- gem 'ruby-prof'
6
+ gem 'httpclient', '~>2.5'
7
+ gem 'pry', '~>0.10'
8
+ gem 'pry-nav', '~>0.2'
9
+ gem 'ruby-prof', '~>0.15'
11
10
  end
data/README.md CHANGED
@@ -2,3 +2,53 @@ terraformer-ruby
2
2
  ================
3
3
 
4
4
  mostly faithful port of [terraformer](https://github.com/Esri/Terraformer)
5
+
6
+ ### Installation
7
+
8
+ `gem install terraformer`
9
+
10
+ or include in an application's `Gemfile`
11
+
12
+ `gem terraformer`
13
+
14
+ ### Basic usage
15
+
16
+ [terraformer-ruby](https://github.com/esripdx/terraformer-ruby) is a port of [terraformer](https://github.com/Esri/Terraformer).
17
+
18
+ ##### Create a Terraformer primitive from GeoJSON
19
+
20
+ ```
21
+ > polygon = Terraformer.parse '{
22
+ "type": "Polygon",
23
+ "coordinates": [
24
+ [
25
+ [-122.66589403152467, 45.52290150862236],
26
+ [-122.66926288604736, 45.52291654238294],
27
+ [-122.67115116119385, 45.518406234030586],
28
+ [-122.67325401306151, 45.514000817199715],
29
+ [-122.6684260368347, 45.5127377671934],
30
+ [-122.66765356063841, 45.51694782364431],
31
+ [-122.66589403152467, 45.52290150862236 ]
32
+ ]
33
+ ]
34
+ }'
35
+
36
+ > point = Terraformer.parse '{
37
+ "type": "Point",
38
+ "coordinates": [-122.66947746276854, 45.51775972687403]
39
+ }'
40
+
41
+ ```
42
+ Now that you have a point and a polygon primitive you can use the primitive helper methods.
43
+
44
+ ```
45
+ # add a new vertex to our polygon
46
+ > new_point = Terraformer::Point.new -122.6708507537842, 45.513188859735436
47
+ > polygon.insert_vertex 2, new_point
48
+ ```
49
+ You can also have Terraformer perform many geometric operations like convex hulls and bounding boxes.
50
+ ```
51
+ > convex_hull = polygon.convex_hull
52
+ > point.within? convex_hull #returns true
53
+ > bounding_box = polygon.bbox #returns the bounding box for this object.
54
+ ```
@@ -9,16 +9,21 @@ require 'ext/enumerable'
9
9
  require 'ext/hash'
10
10
  require 'forwardable'
11
11
 
12
+ # terraformer.rb - a toolkit for working with geojson in ruby
13
+ #
12
14
  module Terraformer
13
15
 
16
+ # number of decimal places of precision to limit bigmath calculations to
17
+ #
14
18
  PRECISION = BigDecimal.double_fig
15
19
  BigDecimal.limit PRECISION
20
+
16
21
  PI = BigMath.PI PRECISION
17
22
  DEFAULT_BUFFER_RESOLUTION = 64
18
-
19
23
  EARTH_RADIUS = 6378137.to_d
20
24
  DEGREES_PER_RADIAN = 180.0.to_d / PI
21
25
  RADIANS_PER_DEGREE = PI / 180.0.to_d
26
+
22
27
  MERCATOR_CRS = {
23
28
  type: "link",
24
29
  properties: {
@@ -26,6 +31,7 @@ module Terraformer
26
31
  type: "ogcwkt"
27
32
  }
28
33
  }
34
+
29
35
  GEOGRAPHIC_CRS = {
30
36
  type: "link",
31
37
  properties: {
@@ -34,6 +40,10 @@ module Terraformer
34
40
  }
35
41
  }
36
42
 
43
+ # parses geojson into a terraformer object. parameter must be a +Hash+,
44
+ # +String+ or +File+ containing a valid geojson object. return class type
45
+ # is determined by +type+ property.
46
+ #
37
47
  def self.parse geojson
38
48
  if String === geojson
39
49
  geojson = File.read geojson if File.readable? geojson
@@ -48,13 +58,20 @@ module Terraformer
48
58
  end
49
59
  end
50
60
 
61
+ # open OS's default browser to geojson.io with param data
62
+ #
51
63
  def self.geojson_io data
52
64
  require 'launchy'
53
65
  Launchy.open "http://geojson.io/#data=data:application/json,#{URI.encode_www_form_component data.to_json}"
54
66
  end
55
67
 
68
+ # abstract base class for terraformer objects. implements +bbox+ and
69
+ # +envelope+.
70
+ #
56
71
  class Primitive
57
72
 
73
+ # handles basic JSON parsing for terraformer object constructors.
74
+ #
58
75
  def initialize *args
59
76
  arg = String === args[0] ? JSON.parse(args[0]) : args[0]
60
77
  raise ArgumentError.new "invalid argument(s): #{args}" unless Hash === arg
@@ -62,18 +79,28 @@ module Terraformer
62
79
  yield arg if block_given?
63
80
  end
64
81
 
82
+ # terraformer object type as a +String+.
83
+ #
65
84
  def type
66
85
  self.class.to_s.sub 'Terraformer::', ''
67
86
  end
68
87
 
88
+ # returns a bounding envelope as a +Hash+ of the geometry. the envelope has
89
+ # keys for coordinates +x+ and +y+, and dimensions +w+ and +h+.
90
+ #
69
91
  def envelope
70
- Bounds.envelope self
92
+ Bounds.envelope self.respond_to?(:geometry) ? self.geometry : self
71
93
  end
72
94
 
95
+ # returns a bounding box array of values, with minimum axis values followed
96
+ # by maximum axis values.
97
+ #
73
98
  def bbox type = :bbox
74
- Bounds.bounds self, type
99
+ Bounds.bounds self.respond_to?(:geometry) ? self.geometry : self, type
75
100
  end
76
101
 
102
+ # base +to_json+ implementation for all terraformer objects.
103
+ #
77
104
  def to_json *args
78
105
  h = self.to_hash *args
79
106
  args.pop if Hash === args.last
@@ -1,3 +1,3 @@
1
1
  module Terraformer
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -12,4 +12,5 @@ Gem::Specification.new do |gem|
12
12
  gem.require_paths = ["lib"]
13
13
  gem.version = Terraformer::VERSION
14
14
  gem.license = 'apache'
15
+ gem.add_runtime_dependency 'launchy', '~>2.4'
15
16
  end
@@ -11,9 +11,12 @@ require 'terraformer'
11
11
  module MiniTest::Expectations
12
12
 
13
13
  GEOJSON_VALIDATE_URL = 'http://geojsonlint.com/validate'
14
+ GEOJSON_VALIDATE_HEADERS = {'Content-Type' => 'application/json'}
15
+
16
+ HC = HTTPClient.new
14
17
 
15
18
  def validate_geojson geojson_h
16
- r = JSON.parse HTTP['Content-Type' => 'application/json'].post(GEOJSON_VALIDATE_URL, json: geojson_h).body
19
+ r = JSON.parse HC.post(GEOJSON_VALIDATE_URL, geojson_h.to_json, GEOJSON_VALIDATE_HEADERS).body
17
20
  r['status'].must_equal 'ok'
18
21
  end
19
22
 
@@ -40,6 +40,12 @@ describe Terraformer::Primitive do
40
40
  bbox.must_equal expected
41
41
  end
42
42
 
43
+ it 'works on features' do
44
+ wc = Terraformer.parse EXAMPLES[:waldocanyon]
45
+ bbox = wc.bbox
46
+ bbox.dont_be_terrible_ok
47
+ end
48
+
43
49
  end
44
50
 
45
51
  describe 'to_json' do
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraformer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: launchy
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
13
27
  description: ''
14
28
  email:
15
29
  - kenichi.nakamura@gmail.com
@@ -81,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
95
  version: '0'
82
96
  requirements: []
83
97
  rubyforge_project:
84
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.4.1
85
99
  signing_key:
86
100
  specification_version: 4
87
101
  summary: ''