Class: Geoblacklight::Geometry
- Inherits:
-
Object
- Object
- Geoblacklight::Geometry
- Defined in:
- lib/geoblacklight/geometry.rb
Overview
Transforms and parses geometry expressed in WKT or CSW WKT ENVELOPE syntax
Instance Attribute Summary collapse
-
#geom ⇒ Object
readonly
Returns the value of attribute geom.
Instance Method Summary collapse
-
#bounding_box ⇒ String
Generate a wsen bounding box from the geometry.
-
#geojson ⇒ String
Convert geometry to GeoJSON.
-
#initialize(geom) ⇒ Geometry
constructor
A new instance of Geometry.
Constructor Details
#initialize(geom) ⇒ Geometry
Returns a new instance of Geometry.
12 13 14 |
# File 'lib/geoblacklight/geometry.rb', line 12 def initialize(geom) @geom = geom end |
Instance Attribute Details
#geom ⇒ Object (readonly)
Returns the value of attribute geom.
9 10 11 |
# File 'lib/geoblacklight/geometry.rb', line 9 def geom @geom end |
Instance Method Details
#bounding_box ⇒ String
Generate a wsen bounding box from the geometry
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/geoblacklight/geometry.rb', line 28 def bounding_box obj = factory.parse_wkt(geometry_as_wkt) # Get the minimum bounding box for the geometry as a Polygon bbox = obj.envelope # Return as wsen string minx = bbox.coordinates[0][0][0] miny = bbox.coordinates[0][0][1] maxx = bbox.coordinates[0][1][0] maxy = bbox.coordinates[0][2][1] "#{minx}, #{miny}, #{maxx}, #{maxy}" rescue RGeo::Error::ParseError Geoblacklight.logger.warn "Error parsing geometry: #{geom}" default_extent end |
#geojson ⇒ String
Convert geometry to GeoJSON
18 19 20 21 22 23 24 |
# File 'lib/geoblacklight/geometry.rb', line 18 def geojson obj = factory.parse_wkt(geometry_as_wkt) RGeo::GeoJSON.encode(obj).to_json rescue Geoblacklight.logger.warn "Geometry is not valid: #{geom}" default_extent end |