terragona 0.2.1 → 0.3.0

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: 8960cea1763219e0706e07cd4f972d62c57a87ff
4
- data.tar.gz: 0377f3156e42d39426927b353aaf68bade666536
3
+ metadata.gz: 3262e299d7235463ec2c190c7a135cca36fd8a7d
4
+ data.tar.gz: 52e1fe48936cf4e903b0ee842f47cdc3bee1a4e4
5
5
  SHA512:
6
- metadata.gz: a841fbf0d6f63e54492ed030388d85075a5e92199cf44a3443e89c39db13b4d8b076ae478fff06d6e0fcbdfd4681710006e66953794e4127729ca360a69ccbec
7
- data.tar.gz: 523101fea46f423189c81b62cabc80ef3fd46ba30a414547542b662c909e283cf733450db0494f3d7845eef549e4aa70b677859b9ced0cd7dc8123231923ad05
6
+ metadata.gz: 99b2033b1c95c6fd402a01b5ab772c63289a9a79221fed7b6d5b689cd03d6ee861db6e844f7b081692104576a7fea80fd4a16df51274b4f86420f23b81dc9cf4
7
+ data.tar.gz: fd604ce36230c33f8cc30658a4bc7742fc4c045faa27aac96fea27e1392113ea355107d814f09b2849bf5837d5d7ca7ade7d4a25a3d27fb93d9eb927dd058b4b
data/README.md CHANGED
@@ -31,7 +31,8 @@ First, create a db in postgres and install the postgis extension.
31
31
 
32
32
  Right now, as sources you can use:
33
33
  * GeoNames API, with the `Terragona::Geonames::API` class,
34
- * A Geonames dump, (`Terragona::Geonames::Dump` class) and specify the dump file path in opts.
34
+ * A Geonames dump, (`Terragona::Geonames::Dump` class) and specify the dump file path in opts.
35
+ * A hash (actually an array of hashes) (`Terragona::Geonames::FromHash` class)
35
36
  * A CSV (`Terragona::CSVParser` class) (with headers: `name,x,y`)
36
37
 
37
38
  The API is faster but less accurate than the dump (max 1000 points per request).
@@ -84,11 +85,35 @@ result.each {|r|
84
85
  terragona.create_polygons_family(italian_rest,'province','comuni')
85
86
  ```
86
87
 
88
+ With the FromHash class
89
+
90
+ ```ruby
91
+ require 'terragona'
92
+
93
+ my_hash = [{:name=>'some_tag',:y=>some_lat,:x=>some_lon},
94
+ {:name=>'some_tag',:y=>some_lat,:x=>some_lon},
95
+ ...]
96
+
97
+ opts={
98
+ :target_percent=> 0.85,
99
+ :max_distance_ratio=>1.6,
100
+ :db_username=>'mydbuser',
101
+ :db_password=>'mydbpsswd',
102
+ :db_name=>'mydb',
103
+ :hash=>my_hash}
104
+
105
+ italy=[] #Don't need input but the hash option.
106
+
107
+ terragona = Terragona::FromHash.new(opts)
108
+ terragona.create_polygons_family(italy,'italy','italian_regions')
109
+ ```
110
+
87
111
  With the CSVParser class
88
112
 
89
113
  ```ruby
90
114
  require 'terragona'
91
115
 
116
+ # csv with headers: name,x,y
92
117
  opts={
93
118
  :target_percent=> 0.85,
94
119
  :max_distance_ratio=>1.6,
@@ -137,39 +162,55 @@ The methods create the tables, fill them with polygons and return the following
137
162
  Options
138
163
  ------
139
164
 
140
- ```
141
- dump Only for Dump. Path to dump file.
142
- max_points Only for Dump. Max number of points to consider from
143
- dump file.
144
- csv_filename Only for CSV.
145
- default_country Default country. Only for Geonames.
146
- geonames_username Only for API. Geonames API username.
147
- use_cache Boolean. Default: false.
148
- cache_expiration_time Default: 7200.
149
- projection Default: EPSG 4326 (WGS84).
150
- target_percent Require to draw the concave polygons.
151
- Closer to 1: convex. Closer to 0, concave. Default: 0.8.
152
- allow_holes Can the polygons have holes? Default: false.
153
- max_distance_ratio Points distant more than this ratio times from the average
154
- distance between points are not considered. Default: 1.6.
155
- minimal_polygon_points Minimal number of points to build a polygon.
156
- force_homogeneity Uses max_distance_ratio also to compare with the avg distance
157
- between points of all the other polygons of the same family level.
158
- This helps to discard outliers. The result are homogeneous polygons.
159
- dont_create_polygons (boolean) Default: false.
160
- table Table where polygons are saved. This option is overriden
161
- by args of create_polygons_family method.
162
- ```
165
+ ### General options
166
+
167
+ Option | Explanation
168
+ --------|-------------
169
+ use_cache | Boolean. Default: false.
170
+ cache_expiration_time | Default: 7200.
171
+ projection | Default: EPSG 4326 (WGS84).
172
+ target_percent | Require to draw the concave polygons. Closer to 1: convex. Closer to 0, concave. Default: 0.8.
173
+ allow_holes | Can the polygons have holes? Default: false.
174
+ max_distance_ratio | Points distant more than this ratio times from the average
175
+ | distance between points are not considered. Default: 1.6.
176
+ minimal_polygon_points | Minimal number of points to build a polygon.
177
+ force_homogeneity | Uses max_distance_ratio also to compare with the avg distance between points of all the other polygons of the same family level. This helps to discard outliers. The result are homogeneous polygons.
178
+ dont_create_polygons | (boolean) Default: false.
179
+ table | Table where polygons are saved. This option is overriden by args of create_polygons_family method.
180
+
181
+ #### Geonames classes options
182
+
183
+ Option | Explanation
184
+ --------|------------
185
+ default_country | Default country.
186
+ geonames_username | **API class**. Geonames API username.
187
+ dump | **Dump class**. Path to dump file.
188
+ max_points | **Dump class**. Max number of points to consider from dump file.
189
+
190
+ #### FromHash class options
191
+
192
+ Option | Explanation
193
+ --------|------------
194
+ hash | Array of hashes. Each hash should be something like `{:tag=>'tag',:y=>some_lat, :x=>some_lon}`
195
+
196
+ #### CSVParser
197
+
198
+ Option | Explanation
199
+ --------|------------
200
+ csv_filename | Path to CSV file.
201
+
202
+
203
+ #### Postgres options
204
+
205
+ Option | Explanation
206
+ --------|------------
207
+ db_name | The db *must* have the Postgis extension installed.
208
+ db_username |
209
+ db_password |
210
+ db_host | Default: localhost.
211
+ db_port | Default: 5432.
212
+ db_max_connections | Default: 10.
163
213
 
164
- Postgres options
165
- ```
166
- db_name The db *must* have the Postgis extension installed.
167
- db_username
168
- db_password
169
- db_host Default: localhost.
170
- db_port Default: 5432.
171
- db_max_connections Default: 10.
172
- ```
173
214
 
174
215
  TODO
175
216
  ----
@@ -15,8 +15,9 @@ module Terragona
15
15
 
16
16
  concave_hull = ConcaveHull.new(opts)
17
17
 
18
- if (!names or names.empty?) and @input.class == Generic::CSVParser
19
- n = {:name => 'CSV'}
18
+ if (!names or names.empty?) and
19
+ (@input.class == Generic::CSVParser or @input.class == Generic::FromHash)
20
+ n = {:name => :generic}
20
21
  name = @input.search(n)
21
22
  process_points(n,name,concave_hull,opts)
22
23
  return [name]
@@ -82,4 +83,11 @@ module Terragona
82
83
  @input = Generic::CSVParser.new(options)
83
84
  end
84
85
  end
86
+
87
+ class FromHash < Base
88
+ def initialize (options={})
89
+ super
90
+ @input = Generic::FromHash.new(options)
91
+ end
92
+ end
85
93
  end
@@ -18,7 +18,7 @@ module Terragona
18
18
 
19
19
  points = []
20
20
 
21
- if name == 'CSV'
21
+ if name == :generic
22
22
  children = []
23
23
 
24
24
  @csv.each {|p|
@@ -37,5 +37,41 @@ module Terragona
37
37
  {:children_places=>children_places, :points => points, :place_name=> name, :place_id=>@id_counter}
38
38
  end
39
39
  end
40
+
41
+ class FromHash
42
+ def initialize(args = {})
43
+ # @hash should be actually an array of hashes
44
+ @hash = args[:hash]
45
+
46
+ return unless @hash
47
+
48
+ @id_counter = 0
49
+ end
50
+ def search(options = {})
51
+ @id_counter +=1
52
+
53
+ name = options[:name]
54
+
55
+ points = []
56
+
57
+ if name == :generic
58
+ children = []
59
+
60
+ @hash.each {|p|
61
+ points.push({:x => p[:x], :y => p[:y]})
62
+ children.push({:name => p[:name]})
63
+ }
64
+
65
+ children.uniq!
66
+
67
+ children_places = (children.count > 1 )? children : []
68
+ else
69
+ @hash.select{|row| row[:name] == name}.each {|p| points.push({:x => p[:x], :y => p[:y]})}
70
+ children_places = []
71
+ end
72
+
73
+ {:children_places=>children_places, :points => points, :place_name=> name, :place_id=>@id_counter}
74
+ end
75
+ end
40
76
  end
41
77
  end
@@ -1,3 +1,3 @@
1
1
  module Terragona
2
- VERSION = "0.2.1"
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terragona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Salerno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg