Class: Geoblacklight::Geometry

Inherits:
Object
  • Object
show all
Defined in:
lib/geoblacklight/geometry.rb

Overview

Transforms and parses geometry expressed in WKT or CSW WKT ENVELOPE syntax

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(geom) ⇒ Geometry

Returns a new instance of Geometry.

Parameters:

  • geom (String)

    WKT or WKT ENVELOPE syntax formatted string



12
13
14
# File 'lib/geoblacklight/geometry.rb', line 12

def initialize(geom)
  @geom = geom
end

Instance Attribute Details

#geomObject (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_boxString

Generate a wsen bounding box from the geometry

Returns:

  • (String)

    bounding box as comma delimited wsen “w, s, e, n”



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

#geojsonString

Convert geometry to GeoJSON

Returns:

  • (String)


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