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



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

def initialize(geom)
  @geom = geom
end

Instance Attribute Details

#geomObject (readonly)

Returns the value of attribute geom.



8
9
10
# File 'lib/geoblacklight/geometry.rb', line 8

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”



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/geoblacklight/geometry.rb', line 27

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)


17
18
19
20
21
22
23
# File 'lib/geoblacklight/geometry.rb', line 17

def geojson
  obj = factory.parse_wkt(geometry_as_wkt)
  RGeo::GeoJSON.encode(obj).to_json
rescue StandardError
  Geoblacklight.logger.warn "Geometry is not valid: #{geom}"
  default_extent
end