Class: FrOData::Properties::Geography::Base
- Inherits:
-
FrOData::Property
- Object
- FrOData::Property
- FrOData::Properties::Geography::Base
- Defined in:
- lib/frodata/properties/geography/base.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_SRID =
The default SRID (same as used by GPS)
4326
Instance Attribute Summary collapse
-
#srid ⇒ Object
The SRID (Spatial Reference ID) of this property.
Attributes inherited from FrOData::Property
Class Method Summary collapse
-
.from_xml(property_xml, options = {}) ⇒ FrOData::Properties::Geography
Creates a new property instance from an XML element.
Instance Method Summary collapse
-
#crs ⇒ Hash
The full CRS representation as used by GeoJSON.
-
#crs_name ⇒ String
The name of the CRS (Coordinate Reference System) used.
-
#initialize(name, value, options = {}) ⇒ Base
constructor
Initializes a geography property.
-
#json_value ⇒ Hash
Value to be used in JSON.
-
#srs_name ⇒ String
The name of the SRS (Spatial Reference System) used.
-
#to_xml(xml_builder) ⇒ Object
Returns the XML representation of the property to the supplied XML builder.
-
#url_value ⇒ String
Value to be used in URLs.
-
#value=(value) ⇒ Object
Sets the value of the property.
Methods inherited from FrOData::Property
#==, #allows_nil?, #concurrency_mode, #strict?, #type, #xml_value
Constructor Details
#initialize(name, value, options = {}) ⇒ Base
Initializes a geography property.
Special options available for geographic types:
srid
: the SRID (spatial reference ID) of the
coordinate system being used.
Defaults to 4326 (same as GPS).
22 23 24 25 26 |
# File 'lib/frodata/properties/geography/base.rb', line 22 def initialize(name, value, = {}) super(name, value, ) self.value = value self.srid = srid || [:srid] || DEFAULT_SRID end |
Instance Attribute Details
#srid ⇒ Object
The SRID (Spatial Reference ID) of this property.
6 7 8 |
# File 'lib/frodata/properties/geography/base.rb', line 6 def srid @srid end |
Class Method Details
.from_xml(property_xml, options = {}) ⇒ FrOData::Properties::Geography
Creates a new property instance from an XML element
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/frodata/properties/geography/base.rb', line 107 def self.from_xml(property_xml, = {}) if property_xml.attributes['null'].andand.value == 'true' content = nil else content = parse_xml(property_xml) .merge!(srid: srid_from_xml(property_xml)) end new(property_xml.name, content, ) end |
Instance Method Details
#crs ⇒ Hash
The full CRS representation as used by GeoJSON
82 83 84 85 86 87 |
# File 'lib/frodata/properties/geography/base.rb', line 82 def crs { type: 'name', properties: { name: crs_name } } end |
#crs_name ⇒ String
The name of the CRS (Coordinate Reference System) used. Used in GeoJSON representation
72 73 74 75 76 77 78 |
# File 'lib/frodata/properties/geography/base.rb', line 72 def crs_name if srid == DEFAULT_SRID "EPSG:#{srid}" else raise NotImplementedError, "Unsupported SRID #{srid}" end end |
#json_value ⇒ Hash
Value to be used in JSON.
50 51 52 53 54 55 56 |
# File 'lib/frodata/properties/geography/base.rb', line 50 def json_value { type: type_name, coordinates: value, crs: crs } end |
#srs_name ⇒ String
The name of the SRS (Spatial Reference System) used. Basically, the SRID in URI/URL form.
61 62 63 64 65 66 67 |
# File 'lib/frodata/properties/geography/base.rb', line 61 def srs_name if srid == DEFAULT_SRID "http://www.opengis.net/def/crs/EPSG/0/#{srid}" else raise NotImplementedError, "Unsupported SRID #{srid}" end end |
#to_xml(xml_builder) ⇒ Object
Returns the XML representation of the property to the supplied XML builder.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/frodata/properties/geography/base.rb', line 92 def to_xml(xml_builder) attributes = { 'metadata:type' => type } type_attrs = { 'gml:srsName' => srs_name } xml_builder['data'].send(name.to_sym, attributes) do xml_builder['gml'].send(type_name, type_attrs) do value_to_xml(xml_value, xml_builder) end end end |
#url_value ⇒ String
Value to be used in URLs.
44 45 46 |
# File 'lib/frodata/properties/geography/base.rb', line 44 def url_value "geography'SRID=#{srid};#{type_name}(#{coords_to_s})'" end |
#value=(value) ⇒ Object
Sets the value of the property.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/frodata/properties/geography/base.rb', line 30 def value=(value) if value.nil? && allows_nil? @value = nil elsif value.is_a?(Hash) @value = value['coordinates'] elsif value.is_a?(Array) @value = value else @value = parse_wkt(value.to_s) end end |