Class: MiamiDadeGeo::Municipality
- Inherits:
-
Object
- Object
- MiamiDadeGeo::Municipality
- Defined in:
- lib/miami_dade_geo/municipality.rb
Overview
Represents one of the municipalities in Miami-Dade County, and unincorporated Miami-Dade County as well.
Makes one or two SOAP requests on construction.
Doesn’t have a ‘new` method for construction, since there are a few different ways to construct it.
Instance Attribute Summary collapse
-
#munic_code ⇒ Integer
readonly
The numeric code of the municipality.
-
#name ⇒ String
readonly
The name of the municipality, or unincorporated MDC.
Class Method Summary collapse
-
.new_with_code(munic_code) ⇒ Object
Constructs a Municipality object for a given ‘munic_code`.
-
.new_with_latlong(latlong_hash) ⇒ Object
Constructs a Municipality object for a given latitude and longitude.
-
.new_with_name(name) ⇒ Object
Constructs a Municipality object for a given municipality name.
-
.new_with_xy(xy_hash) ⇒ Object
Constructs a Municipality object for a given x-y coordinate in the NAD 83 Florida state coordinate system.
Instance Attribute Details
#munic_code ⇒ Integer (readonly)
Returns the numeric code of the municipality.
21 22 23 |
# File 'lib/miami_dade_geo/municipality.rb', line 21 def munic_code @munic_code end |
#name ⇒ String (readonly)
Returns the name of the municipality, or unincorporated MDC.
17 18 19 |
# File 'lib/miami_dade_geo/municipality.rb', line 17 def name @name end |
Class Method Details
.new_with_code(munic_code) ⇒ Object
Constructs a MiamiDadeGeo::Municipality object for a given ‘munic_code`. The SOAP method called zero-pads single-digit municipality codes, so this constructor converts the code to an `Integer` and formats it.
Used by the Address#municipality method.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/miami_dade_geo/municipality.rb', line 48 def self.new_with_code(munic_code) canonicalized_munic_code = "%02d" % [munic_code.to_i] poly = GeoAttributeClient.instance. all_fields('municipality_poly', 'municid', canonicalized_munic_code) new poly end |
.new_with_latlong(latlong_hash) ⇒ Object
Constructs a MiamiDadeGeo::Municipality object for a given latitude and longitude. Makes two SOAP requests: one to convert from lat-long to x-y in NAD 83, and one to load the municipality for the NAD 83 coordinate.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/miami_dade_geo/municipality.rb', line 82 def self.new_with_latlong(latlong_hash) body = LatlongClient.instance.savon. call(:get_x_yfrom_lat_long_dec, message: { 'LNG' => latlong_hash[:long].to_f, 'LAT' => latlong_hash[:lat].to_f} ). body resp = body[:get_x_yfrom_lat_long_dec_response] result = resp[:get_x_yfrom_lat_long_dec_result] double = result[:double] new_with_xy(x: double[0], y: double[1]) end |
.new_with_name(name) ⇒ Object
Constructs a MiamiDadeGeo::Municipality object for a given municipality name. The SOAP method called is case-sensitive, and we believe all municipalities to be ALL-CAPS, so this constructor capitalizes the name before searching.
Useful to get the ‘munic_code` for a given municipality name.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/miami_dade_geo/municipality.rb', line 30 def self.new_with_name(name) canonicalized_name = name.upcase poly = GeoAttributeClient.instance. all_fields('municipality_poly', 'name', canonicalized_name) new poly end |
.new_with_xy(xy_hash) ⇒ Object
Constructs a MiamiDadeGeo::Municipality object for a given x-y coordinate in the NAD 83 Florida state coordinate system. Calls one SOAP method.
66 67 68 69 70 71 72 |
# File 'lib/miami_dade_geo/municipality.rb', line 66 def self.new_with_xy(xy_hash) new GetClosestFeatureClient.instance. get_closest_feature('municipality_poly', xy_hash[:x], xy_hash[:y], 0) end |