interior 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.swp
2
+ *.tmp
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.8.7-p352@interior
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in interior.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,461 @@
1
+ Interior
2
+ ========
3
+
4
+ Township GeoCoder Web Service
5
+ -----------------------------
6
+ This gem uses the GeoCommunicator GeoCoder Web Service provided by the
7
+ [US Department of the Interior](http://www.geocommunicator.gov/GeoComm/lsis_home/townshipdecoder/index.htm).
8
+ For detailed documentation on the web service API, consult the
9
+ [Methods, Parameters, and Results PDF](http://www.blm.gov/nils/GeoComm/documents/NILS_GeoCommunicator_Web_Services_TGC_Formats.pdf).
10
+
11
+ US Meridian Map
12
+ ---------------
13
+ The US is divided into several meridians. A [larger map](https://github.com/climate/interior/raw/master/maps/meridians.jpg)
14
+ is also available for reference.
15
+
16
+ ![USA Meridians](https://github.com/climate/interior/raw/master/maps/meridians_small.jpg "USA Meridians")
17
+
18
+ Each meridian has a corresponding numeric key mapping:
19
+
20
+ <table>
21
+ <tr>
22
+ <th>State</th>
23
+ <th>Meridian</th>
24
+ <th>Code</th>
25
+ </tr>
26
+ <tr>
27
+ <td>AL</td>
28
+ <td>HUNTSVILLE MER</td>
29
+ <td>16</td>
30
+ </tr>
31
+ <tr>
32
+ <td>AL</td>
33
+ <td>ST. STEPHENS MER</td>
34
+ <td>25</td>
35
+ </tr>
36
+ <tr>
37
+ <td>AL</td>
38
+ <td>TALLAHASEE MER</td>
39
+ <td>29</td>
40
+ </tr>
41
+ <tr>
42
+ <td>AR</td>
43
+ <td>5TH PM</td>
44
+ <td>05</td>
45
+ </tr>
46
+ <tr>
47
+ <td>AZ</td>
48
+ <td>GILA-SALT RIVER MER</td>
49
+ <td>14</td>
50
+ </tr>
51
+ <tr>
52
+ <td>AZ</td>
53
+ <td>NAVAJO MER</td>
54
+ <td>22</td>
55
+ </tr>
56
+ <tr>
57
+ <td>AZ</td>
58
+ <td>SAN BERNARDINO MER</td>
59
+ <td>27</td>
60
+ </tr>
61
+ <tr>
62
+ <td>CA</td>
63
+ <td>GILA-SALT RIVER MER</td>
64
+ <td>14</td>
65
+ </tr>
66
+ <tr>
67
+ <td>CA</td>
68
+ <td>HUMBOLDT MER</td>
69
+ <td>15</td>
70
+ </tr>
71
+ <tr>
72
+ <td>CA</td>
73
+ <td>MOUNT DIABLO MER</td>
74
+ <td>21</td>
75
+ </tr>
76
+ <tr>
77
+ <td>CA</td>
78
+ <td>SAN BERNARDINO MER</td>
79
+ <td>27</td>
80
+ </tr>
81
+ <tr>
82
+ <td>CO</td>
83
+ <td>6TH PM</td>
84
+ <td>06</td>
85
+ </tr>
86
+ <tr>
87
+ <td>CO</td>
88
+ <td>NEW MEX PM</td>
89
+ <td>23</td>
90
+ </tr>
91
+ <tr>
92
+ <td>CO</td>
93
+ <td>UTE MER</td>
94
+ <td>31</td>
95
+ </tr>
96
+ <tr>
97
+ <td>CT</td>
98
+ <td>CONNECTICUT</td>
99
+ <td>CT</td>
100
+ </tr>
101
+ <tr>
102
+ <td>DE</td>
103
+ <td>DELAWARE</td>
104
+ <td>DE</td>
105
+ </tr>
106
+ <tr>
107
+ <td>FL</td>
108
+ <td>TALLAHASEE MER</td>
109
+ <td>29</td>
110
+ </tr>
111
+ <tr>
112
+ <td>GA</td>
113
+ <td>GEORGIA</td>
114
+ <td>GA</td>
115
+ </tr>
116
+ <tr>
117
+ <td>IA</td>
118
+ <td>5TH PM</td>
119
+ <td>05</td>
120
+ </tr>
121
+ <tr>
122
+ <td>ID</td>
123
+ <td>BOISE MER</td>
124
+ <td>08</td>
125
+ </tr>
126
+ <tr>
127
+ <td>IL</td>
128
+ <td>2ND PM</td>
129
+ <td>02</td>
130
+ </tr>
131
+ <tr>
132
+ <td>IL</td>
133
+ <td>3RD PM</td>
134
+ <td>03</td>
135
+ </tr>
136
+ <tr>
137
+ <td>IL</td>
138
+ <td>4TH PM ILLINOIS</td>
139
+ <td>04</td>
140
+ </tr>
141
+ <tr>
142
+ <td>IN</td>
143
+ <td>1ST PM</td>
144
+ <td>01</td>
145
+ </tr>
146
+ <tr>
147
+ <td>IN</td>
148
+ <td>2ND PM</td>
149
+ <td>02</td>
150
+ </tr>
151
+ <tr>
152
+ <td>KS</td>
153
+ <td>6TH PM</td>
154
+ <td>06</td>
155
+ </tr>
156
+ <tr>
157
+ <td>KY</td>
158
+ <td>KENTUCKY</td>
159
+ <td>KY</td>
160
+ </tr>
161
+ <tr>
162
+ <td>LA</td>
163
+ <td>LOUISIANA MER</td>
164
+ <td>18</td>
165
+ </tr>
166
+ <tr>
167
+ <td>LA</td>
168
+ <td>ST. HELENA MER</td>
169
+ <td>24</td>
170
+ </tr>
171
+ <tr>
172
+ <td>MA</td>
173
+ <td>MASSACHUSETS</td>
174
+ <td>MA</td>
175
+ </tr>
176
+ <tr>
177
+ <td>MD</td>
178
+ <td>MARYLAND</td>
179
+ <td>MD</td>
180
+ </tr>
181
+ <tr>
182
+ <td>ME</td>
183
+ <td>MAINE</td>
184
+ <td>ME</td>
185
+ </tr>
186
+ <tr>
187
+ <td>MI</td>
188
+ <td>MICHIGAN MER</td>
189
+ <td>19</td>
190
+ </tr>
191
+ <tr>
192
+ <td>MN</td>
193
+ <td>5TH PM</td>
194
+ <td>05</td>
195
+ </tr>
196
+ <tr>
197
+ <td>MN</td>
198
+ <td>4TH PM MN-WI</td>
199
+ <td>46</td>
200
+ </tr>
201
+ <tr>
202
+ <td>MO</td>
203
+ <td>5TH PM</td>
204
+ <td>05</td>
205
+ </tr>
206
+ <tr>
207
+ <td>MS</td>
208
+ <td>CHICKASAW MER</td>
209
+ <td>09</td>
210
+ </tr>
211
+ <tr>
212
+ <td>MS</td>
213
+ <td>CHOCTAW MER</td>
214
+ <td>10</td>
215
+ </tr>
216
+ <tr>
217
+ <td>MS</td>
218
+ <td>HUNTSVILLE MER</td>
219
+ <td>16</td>
220
+ </tr>
221
+ <tr>
222
+ <td>MS</td>
223
+ <td>ST. STEPHENS MER</td>
224
+ <td>25</td>
225
+ </tr>
226
+ <tr>
227
+ <td>MS</td>
228
+ <td>WASHINGTON MER</td>
229
+ <td>32</td>
230
+ </tr>
231
+ <tr>
232
+ <td>MT</td>
233
+ <td>PRIN MER, MT</td>
234
+ <td>20</td>
235
+ </tr>
236
+ <tr>
237
+ <td>NC</td>
238
+ <td>NO CAROLINA</td>
239
+ <td>NC</td>
240
+ </tr>
241
+ <tr>
242
+ <td>ND</td>
243
+ <td>5TH PM</td>
244
+ <td>05</td>
245
+ </tr>
246
+ <tr>
247
+ <td>NE</td>
248
+ <td>6TH PM</td>
249
+ <td>06</td>
250
+ </tr>
251
+ <tr>
252
+ <td>NH</td>
253
+ <td>NEW HAMPSHIRE</td>
254
+ <td>NH</td>
255
+ </tr>
256
+ <tr>
257
+ <td>NJ</td>
258
+ <td>NEW JERSEY</td>
259
+ <td>NJ</td>
260
+ </tr>
261
+ <tr>
262
+ <td>NM</td>
263
+ <td>NEW MEX PM</td>
264
+ <td>23</td>
265
+ </tr>
266
+ <tr>
267
+ <td>NV</td>
268
+ <td>MOUNT DIABLO MER</td>
269
+ <td>21</td>
270
+ </tr>
271
+ <tr>
272
+ <td>NV</td>
273
+ <td>SAN BERNARDINO MER</td>
274
+ <td>27</td>
275
+ </tr>
276
+ <tr>
277
+ <td>NY</td>
278
+ <td>NEW YORK</td>
279
+ <td>NY</td>
280
+ </tr>
281
+ <tr>
282
+ <td>OH</td>
283
+ <td>1ST PM</td>
284
+ <td>01</td>
285
+ </tr>
286
+ <tr>
287
+ <td>OH</td>
288
+ <td>MICHIGAN MER</td>
289
+ <td>19</td>
290
+ </tr>
291
+ <tr>
292
+ <td>OH</td>
293
+ <td>OHIO RIVER SURVEY</td>
294
+ <td>35</td>
295
+ </tr>
296
+ <tr>
297
+ <td>OH</td>
298
+ <td>BETWEEN THE MIAMIS</td>
299
+ <td>36</td>
300
+ </tr>
301
+ <tr>
302
+ <td>OH</td>
303
+ <td>MUSKINGUM RIVER BASIN</td>
304
+ <td>37</td>
305
+ </tr>
306
+ <tr>
307
+ <td>OH</td>
308
+ <td>OHIO RIVER BASIN</td>
309
+ <td>38</td>
310
+ </tr>
311
+ <tr>
312
+ <td>OH</td>
313
+ <td>1ST SCIOTO RIVER BASE</td>
314
+ <td>39</td>
315
+ </tr>
316
+ <tr>
317
+ <td>OH</td>
318
+ <td>2ND SCIOTO RIVER BASE</td>
319
+ <td>40</td>
320
+ </tr>
321
+ <tr>
322
+ <td>OH</td>
323
+ <td>3RD SCIOTO RIVER BASE</td>
324
+ <td>41</td>
325
+ </tr>
326
+ <tr>
327
+ <td>OH</td>
328
+ <td>TWELVE MILE SQUARE</td>
329
+ <td>43</td>
330
+ </tr>
331
+ <tr>
332
+ <td>OH</td>
333
+ <td>WEST OF GREAT MIAMI</td>
334
+ <td>47</td>
335
+ </tr>
336
+ <tr>
337
+ <td>OH</td>
338
+ <td>US MILITARY SURVEY</td>
339
+ <td>48</td>
340
+ </tr>
341
+ <tr>
342
+ <td>OH</td>
343
+ <td>CT WEST RES-OHIO</td>
344
+ <td>91</td>
345
+ </tr>
346
+ <tr>
347
+ <td>OH</td>
348
+ <td>OHIO CO PUR-OHIO</td>
349
+ <td>92</td>
350
+ </tr>
351
+ <tr>
352
+ <td>OH</td>
353
+ <td>VA MILITARY SURVEY-OHIO</td>
354
+ <td>93</td>
355
+ </tr>
356
+ <tr>
357
+ <td>OH</td>
358
+ <td>OHIO</td>
359
+ <td>OH</td>
360
+ </tr>
361
+ <tr>
362
+ <td>OK</td>
363
+ <td>CIMARRON MER</td>
364
+ <td>11</td>
365
+ </tr>
366
+ <tr>
367
+ <td>OK</td>
368
+ <td>INDIAN MER</td>
369
+ <td>17</td>
370
+ </tr>
371
+ <tr>
372
+ <td>OR</td>
373
+ <td>WILLAMETTE MER</td>
374
+ <td>33</td>
375
+ </tr>
376
+ <tr>
377
+ <td>PA</td>
378
+ <td>PENNSYLVANIA</td>
379
+ <td>PA</td>
380
+ </tr>
381
+ <tr>
382
+ <td>RI</td>
383
+ <td>RHODE ISLAND</td>
384
+ <td>RI</td>
385
+ </tr>
386
+ <tr>
387
+ <td>SC</td>
388
+ <td>SO CAROLINA</td>
389
+ <td>SC</td>
390
+ </tr>
391
+ <tr>
392
+ <td>SD</td>
393
+ <td>5TH PM</td>
394
+ <td>05</td>
395
+ </tr>
396
+ <tr>
397
+ <td>SD</td>
398
+ <td>6TH PM</td>
399
+ <td>06</td>
400
+ </tr>
401
+ <tr>
402
+ <td>SD</td>
403
+ <td>BLACK HILLS MER</td>
404
+ <td>07</td>
405
+ </tr>
406
+ <tr>
407
+ <td>TN</td>
408
+ <td>TENNESSEE</td>
409
+ <td>TN</td>
410
+ </tr>
411
+ <tr>
412
+ <td>TX</td>
413
+ <td>TEXAS</td>
414
+ <td>TX</td>
415
+ </tr>
416
+ <tr>
417
+ <td>UT</td>
418
+ <td>SALT LAKE MER</td>
419
+ <td>26</td>
420
+ </tr>
421
+ <tr>
422
+ <td>UT</td>
423
+ <td>UINTAH SPEC MER</td>
424
+ <td>30</td>
425
+ </tr>
426
+ <tr>
427
+ <td>VA</td>
428
+ <td>VIRGINIA</td>
429
+ <td>VA</td>
430
+ </tr>
431
+ <tr>
432
+ <td>VT</td>
433
+ <td>VERMONT</td>
434
+ <td>VT</td>
435
+ </tr>
436
+ <tr>
437
+ <td>WA</td>
438
+ <td>WILLAMETTE MER</td>
439
+ <td>33</td>
440
+ </tr>
441
+ <tr>
442
+ <td>WI</td>
443
+ <td>4TH PM MN-WI</td>
444
+ <td>46</td>
445
+ </tr>
446
+ <tr>
447
+ <td>WV</td>
448
+ <td>WEST VIRGINIA</td>
449
+ <td>WV</td>
450
+ </tr>
451
+ <tr>
452
+ <td>WY</td>
453
+ <td>6TH PM</td>
454
+ <td>06</td>
455
+ </tr>
456
+ <tr>
457
+ <td>WY</td>
458
+ <td>WIND RIVER MER</td>
459
+ <td>34</td>
460
+ </tr>
461
+ </table>
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: Run all specs'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ t.rspec_opts = ['--color', '-d']
10
+ end
data/interior.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "interior/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "interior"
7
+ s.version = Interior::VERSION
8
+ s.authors = ["Chris Hunt"]
9
+ s.email = ["chunt@climate.com"]
10
+ s.homepage = "http://climate.com"
11
+ s.summary = %q{Convert PLSS to latitude and longitude}
12
+ s.description = %q{Find the center latitude/longitude for any grid in the PLSS given township, range, and section.}
13
+
14
+ s.rubyforge_project = "interior"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "ruby-debug"
23
+
24
+ s.add_runtime_dependency "nokogiri"
25
+ end
@@ -0,0 +1,51 @@
1
+ require 'net/http'
2
+ require 'cgi'
3
+ require 'nokogiri'
4
+ require 'interior/response'
5
+
6
+ module Interior
7
+ class Geocoder
8
+ API_DOMAIN = 'www.geocommunicator.gov'
9
+ API_PATH = 'TownshipGeocoder/TownshipGeocoder.asmx/GetLatLon'
10
+ API_PARAM = 'TRS'
11
+
12
+ # st : state
13
+ # me : meridian
14
+ # to : township
15
+ # to_dir : township direction
16
+ # ra : range
17
+ # ra_dir : range_direction
18
+ # se : section
19
+ def self.get_lat_lon(st, me, to, to_dir, ra, ra_dir, se)
20
+ trs = build_trs_param(st, me, to, to_dir, ra, ra_dir, se)
21
+ xml = get_response_body(trs)
22
+ result = parse_xml(xml)
23
+ result ? Interior::Response.new(result[:lat], result[:lon]) : nil
24
+ end
25
+
26
+ private
27
+
28
+ def self.build_trs_param(st, me, to, to_dir, ra, ra_dir, se = nil)
29
+ "#{st},#{me},#{to},0,#{to_dir},#{ra},0,#{ra_dir},#{se ? se : 0},,0"
30
+ end
31
+
32
+ def self.get_response_body(trs)
33
+ url = "http://#{API_DOMAIN}/#{API_PATH}?#{API_PARAM}=#{CGI::escape(trs.to_s)}"
34
+ uri = URI.parse(url)
35
+ Net::HTTP.get_response(uri).body
36
+ end
37
+
38
+ def self.parse_xml(xml)
39
+ begin
40
+ doc = Nokogiri::XML(xml)
41
+ data = Nokogiri::XML(doc.children[0].children[5].text)
42
+ points = data.xpath('//georss:point').first.child.text.split
43
+ lon, lat = points
44
+
45
+ { :lat => lat.to_f, :lon => lon.to_f }
46
+ rescue
47
+ nil # if XML is the wrong format, return nil
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ module Interior
2
+ class Response
3
+ attr_reader :latitude, :longitude
4
+
5
+ def initialize(latitude, longitude)
6
+ @latitude = latitude
7
+ @longitude = longitude
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Interior
2
+ VERSION = "0.8.0"
3
+ end
data/lib/interior.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'lib/interior/response.rb'
2
+ require 'lib/interior/geocoder.rb'
Binary file
Binary file
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <TownshipGeocoderResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.esri.com/">
3
+ <CompletionStatus>true</CompletionStatus>
4
+ <Message>Ok</Message>
5
+ <Data>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
6
+
7
+ &lt;rss version="2.0" xmlns:georss="http://www.georss.org/georss"&gt;
8
+ &lt;channel&gt;
9
+ &lt;title&gt;Township GeoCoder&lt;/title&gt;
10
+ &lt;item&gt;
11
+ &lt;title&gt;Lat Lon&lt;/title&gt;
12
+ &lt;link&gt;http://www.geocommunicator.gov&lt;/link&gt;
13
+ &lt;description&gt;Latitude(33.384549272498), Longitude(-112.228362739723)&lt;/description&gt;
14
+ &lt;pubDate&gt;1/17/2012 1:45:18 PM&lt;/pubDate&gt;
15
+ &lt;georss:point&gt;-112.228362739723 33.384549272498&lt;/georss:point&gt;
16
+ &lt;/item&gt;
17
+
18
+ &lt;item&gt;&lt;title&gt;Township Range Section&lt;/title&gt;
19
+ &lt;link&gt;http://www.geocommunicator.gov&lt;/link&gt;
20
+ &lt;description&gt;AZ,14,1,0,N,1,0,E,35,,0&lt;/description&gt;
21
+ &lt;pubDate&gt;1/17/2012 1:45:18 PM&lt;/pubDate&gt;
22
+ &lt;georss:polygon&gt;33.377309949200253,-112.22473576975602,33.377309762935738,-112.22508655240432,33.377309134293,-112.22616916833266,33.37730785372446,-112.22833437690633,33.377306363608341,-112.22906648958326,33.377305152888994,-112.23266758802146,33.377303662772874,-112.23339967741532,33.3773024054874,-112.23700079913641,33.380924970911053,-112.2369908107018,33.38454753633448,-112.23698082226719,33.387510306279239,-112.23697386063094,33.388168308962179,-112.23697292930837,33.39085871361948,-112.23697462897206,33.3917808161018,-112.23697244036401,33.391802213237952,-112.23269233791888,33.3918235638082,-112.22841218890744,33.391844751396775,-112.22413655681072,33.391865892419219,-112.21986092471394,33.388228751797271,-112.21980846796981,33.384591634458559,-112.21975596465961,33.380954284289089,-112.21970516101294,33.377316934119563,-112.21965433408343,33.377315932947795,-112.22005654902097,33.377313464942972,-112.22295871314896,33.3773114858825,-112.22400412274044,33.377309949200253,-112.22473576975602&lt;/georss:polygon&gt;
23
+ &lt;/item&gt;&lt;/channel&gt;&lt;/rss&gt;</Data>
24
+ </TownshipGeocoderResult>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <TownshipGeocoderResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.esri.com/">
3
+ <CompletionStatus>true</CompletionStatus>
4
+ <Message>Ok</Message>
5
+ <Data>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
6
+
7
+ &lt;rss version="2.0" xmlns:georss="http://www.georss.org/georss"&gt;
8
+ &lt;channel&gt;
9
+ &lt;title&gt;Township GeoCoder&lt;/title&gt;
10
+ &lt;item&gt;
11
+ &lt;title&gt;Lat Lon&lt;/title&gt;
12
+ &lt;link&gt;http://www.geocommunicator.gov&lt;/link&gt;
13
+ &lt;description&gt;Latitude(39.9648046692517), Longitude(-105.006276849858)&lt;/description&gt;
14
+ &lt;pubDate&gt;1/17/2012 2:56:49 PM&lt;/pubDate&gt;
15
+ &lt;georss:point&gt;-105.006276849858 39.9648046692517&lt;/georss:point&gt;
16
+ &lt;/item&gt;
17
+
18
+ &lt;item&gt;&lt;title&gt;Township Range Section&lt;/title&gt;
19
+ &lt;link&gt;http://www.geocommunicator.gov&lt;/link&gt;
20
+ &lt;description&gt;CO,6,1,0,S,68,0,W,16,,0&lt;/description&gt;
21
+ &lt;pubDate&gt;1/17/2012 2:56:49 PM&lt;/pubDate&gt;
22
+ &lt;georss:polygon&gt;39.957606675977047,-105.015652857276,39.961226610414428,-105.01565895743886,39.9648465681347,-105.01566508088479,39.968466525855092,-105.01567120433072,39.9720864602923,-105.01567728121052,39.9720635264739,-105.01097910806089,39.9720405926555,-105.00628093491133,39.972017635554039,-105.00158276176188,39.971994701735639,-104.99688458861243,39.968376862774051,-104.99688568291646,39.964759047095754,-104.99688682378661,39.961141208134165,-104.99688791809064,39.957523392455812,-104.99688905896079,39.957544207515355,-105.00158001436029,39.957565045857962,-105.00627096975978,39.95758583763444,-105.01096192515939,39.957606675977047,-105.015652857276&lt;/georss:polygon&gt;
23
+ &lt;/item&gt;&lt;/channel&gt;&lt;/rss&gt;</Data>
24
+ </TownshipGeocoderResult>
@@ -0,0 +1,122 @@
1
+ require 'spec_helper.rb'
2
+ require 'interior/geocoder.rb'
3
+
4
+ describe Interior::Geocoder do
5
+ let(:coder) { Interior::Geocoder }
6
+
7
+ describe '#get_lat_lon' do
8
+ subject { coder.get_lat_lon(st, me, to, to_dir, ra, ra_dir, se) }
9
+
10
+ context 'when in Arizona' do
11
+ let (:st) { 'AZ' }
12
+ let (:me) { 14 }
13
+ let (:to) { 1 }
14
+ let (:to_dir) { 'N' }
15
+ let (:ra) { 1 }
16
+ let (:ra_dir) { 'E' }
17
+ let (:se) { 35 }
18
+
19
+ it 'returns the correct latitude and longitude' do
20
+ subject.latitude.should == 33.384549272498
21
+ subject.longitude.should == -112.228362739723
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#build_trs_param' do
27
+ subject { coder.send(:build_trs_param, st, me, to, to_dir, ra, ra_dir, se) }
28
+
29
+ context 'when in Arizona' do
30
+ let (:st) { 'AZ' }
31
+ let (:me) { 14 }
32
+ let (:to) { 1 }
33
+ let (:to_dir) { 'N' }
34
+ let (:ra) { 1 }
35
+ let (:ra_dir) { 'E' }
36
+ let (:se) { 35 }
37
+
38
+ it 'returns the correct trs param' do
39
+ subject.should == "AZ,14,1,0,N,1,0,E,35,,0"
40
+ end
41
+ end
42
+
43
+ context 'when in Colorado' do
44
+ let (:st) { 'CO' }
45
+ let (:me) { 06 }
46
+ let (:to) { 1 }
47
+ let (:to_dir) { 'S' }
48
+ let (:ra) { 68 }
49
+ let (:ra_dir) { 'W' }
50
+ let (:se) { 16 }
51
+
52
+ it 'returns the correct trs param' do
53
+ subject.should == "CO,6,1,0,S,68,0,W,16,,0"
54
+ end
55
+ end
56
+
57
+ context 'when missing section' do
58
+ let (:st) { 'AZ' }
59
+ let (:me) { 14 }
60
+ let (:to) { 1 }
61
+ let (:to_dir) { 'N' }
62
+ let (:ra) { 1 }
63
+ let (:ra_dir) { 'E' }
64
+ let (:se) { nil }
65
+
66
+ it 'defaults to section 0' do
67
+ subject.should == "AZ,14,1,0,N,1,0,E,0,,0"
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#get_response_body' do
73
+ subject do
74
+ Net::HTTP.stub(:get_response => double('response', :body => body))
75
+ coder.send(:get_response_body, "AZ,14,1,0,N,1,0,E,0,,0")
76
+ end
77
+
78
+ context 'when the response contains a body' do
79
+ let(:body) { 'response_body' }
80
+
81
+ it 'returns the body' do
82
+ subject.should == 'response_body'
83
+ end
84
+ end
85
+
86
+ context 'when the response does not contain a body' do
87
+ let(:body) { nil }
88
+
89
+ it 'returns nil' do
90
+ subject.should == nil
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#parse_xml' do
96
+ subject { coder.send(:parse_xml, xml) }
97
+
98
+ context 'when in Arizona' do
99
+ let(:xml) { File.open('spec/fixtures/az.xml').read }
100
+
101
+ it 'returns the correct latitude and longitude' do
102
+ subject.should == { :lat => 33.384549272498, :lon => -112.228362739723 }
103
+ end
104
+ end
105
+
106
+ context 'when in Colorado' do
107
+ let(:xml) { File.open('spec/fixtures/co.xml').read }
108
+
109
+ it 'returns the correct latitude and longitude' do
110
+ subject.should == { :lat => 39.9648046692517, :lon => -105.006276849858 }
111
+ end
112
+ end
113
+
114
+ context 'when no xml is provided' do
115
+ let(:xml) { nil }
116
+
117
+ it 'returns nil' do
118
+ subject.should == nil
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper.rb'
2
+ require 'interior/response.rb'
3
+
4
+ describe Interior::Response do
5
+ let(:latitude) { 30 }
6
+ let(:longitude) { 60 }
7
+ let(:response) { Interior::Response.new(latitude, longitude) }
8
+
9
+ describe('#latitude') do
10
+ it 'can be initialized' do
11
+ response.latitude.should == latitude
12
+ end
13
+
14
+ it 'is readonly' do
15
+ lambda { response.latitude = 100 }.should raise_error
16
+ end
17
+ end
18
+
19
+ describe('#longitude') do
20
+ it 'can be initialized' do
21
+ response.longitude.should == longitude
22
+ end
23
+
24
+ it 'is readonly' do
25
+ lambda { response.longitude = 100 }.should raise_error
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.mock_with :rspec
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interior
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
+ platform: ruby
12
+ authors:
13
+ - Chris Hunt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: ruby-debug
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: nokogiri
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: Find the center latitude/longitude for any grid in the PLSS given township, range, and section.
63
+ email:
64
+ - chunt@climate.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - .gitignore
73
+ - .rvmrc
74
+ - Gemfile
75
+ - README.md
76
+ - Rakefile
77
+ - interior.gemspec
78
+ - lib/interior.rb
79
+ - lib/interior/geocoder.rb
80
+ - lib/interior/response.rb
81
+ - lib/interior/version.rb
82
+ - maps/meridians.jpg
83
+ - maps/meridians_small.jpg
84
+ - spec/fixtures/az.xml
85
+ - spec/fixtures/co.xml
86
+ - spec/lib/interior/geocoder_spec.rb
87
+ - spec/lib/interior/response_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: http://climate.com
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project: interior
118
+ rubygems_version: 1.8.10
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Convert PLSS to latitude and longitude
122
+ test_files:
123
+ - spec/fixtures/az.xml
124
+ - spec/fixtures/co.xml
125
+ - spec/lib/interior/geocoder_spec.rb
126
+ - spec/lib/interior/response_spec.rb
127
+ - spec/spec_helper.rb