Class: GeoCombine::OGP
- Inherits:
-
Object
- Object
- GeoCombine::OGP
- Includes:
- Formatting
- Defined in:
- lib/geo_combine/ogp.rb
Overview
Data model for OpenGeoPortal metadata
Defined Under Namespace
Classes: InvalidMetadata
Constant Summary collapse
- OGP_REQUIRED_FIELDS =
%w[ Access Institution LayerDisplayName LayerId MaxX MaxY MinX MinY Name ].freeze
- SLUG_STRIP_VALUES =
%w[ SDE_DATA. SDE. SDE2. GISPORTAL.GISOWNER01. GISDATA. MORIS. ].freeze
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #date ⇒ Object
-
#envelope ⇒ String
Builds a Solr Envelope using CQL syntax.
- #fgdc ⇒ Object
-
#geoblacklight_terms ⇒ Hash
Builds a Geoblacklight Schema type hash from Esri Open Data portal metadata.
-
#initialize(metadata) ⇒ OGP
constructor
Initializes an OGP object for parsing.
-
#ogp_formats ⇒ Object
OGP doesn't ship format types, so we just try and be clever here.
-
#ogp_geom ⇒ Object
Convert "Paper Map" to Raster, assumes all OGP "Paper Maps" have WMS.
- #placenames ⇒ Object
-
#references ⇒ String
Converts references to json.
- #subjects ⇒ Object
-
#to_geoblacklight ⇒ GeoCombine::Geoblacklight
Creates and returns a Geoblacklight schema object from this metadata.
-
#valid? ⇒ Boolean
Runs validity checks on OGP metadata to ensure fields are present.
- #year ⇒ Object
Methods included from Formatting
#remove_lines, #sanitize, #sanitize_and_remove_lines, #sluggify
Constructor Details
#initialize(metadata) ⇒ OGP
Initializes an OGP object for parsing
18 19 20 21 |
# File 'lib/geo_combine/ogp.rb', line 18 def initialize() @metadata = JSON.parse() raise InvalidMetadata unless valid? end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/geo_combine/ogp.rb', line 12 def @metadata end |
Instance Method Details
#date ⇒ Object
82 83 84 85 86 |
# File 'lib/geo_combine/ogp.rb', line 82 def date DateTime.rfc3339(['ContentDate']) rescue StandardError nil end |
#envelope ⇒ String
Builds a Solr Envelope using CQL syntax
126 127 128 129 130 131 132 133 134 |
# File 'lib/geo_combine/ogp.rb', line 126 def envelope raise ArgumentError unless west.between?(-180, 180) && east >= -180 && east <= 180 && north >= -90 && north <= 90 && south >= -90 && south <= 90 && west <= east && south <= north "ENVELOPE(#{west}, #{east}, #{north}, #{south})" end |
#fgdc ⇒ Object
144 145 146 |
# File 'lib/geo_combine/ogp.rb', line 144 def fgdc GeoCombine::Fgdc.new(['FgdcText']) if ['FgdcText'] end |
#geoblacklight_terms ⇒ Hash
Builds a Geoblacklight Schema type hash from Esri Open Data portal metadata
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/geo_combine/ogp.rb', line 52 def geoblacklight_terms { # Required fields dc_identifier_s: identifier, layer_slug_s: slug, dc_title_s: ['LayerDisplayName'], solr_geom: envelope, dct_provenance_s: institution, dc_rights_s: ['Access'], geoblacklight_version: '1.0', # Recommended fields dc_description_s: ['Abstract'], layer_geom_type_s: ogp_geom, dct_references_s: references, layer_id_s: "#{['WorkspaceName']}:#{['Name']}", # Optional dct_temporal_sm: [['ContentDate']], dc_format_s: ogp_formats, # dct_issued_dt # dc_language_s dct_spatial_sm: placenames, solr_year_i: year, dc_publisher_s: ['Publisher'], dc_subject_sm: subjects, dc_type_s: 'Dataset' }.compact end |
#ogp_formats ⇒ Object
OGP doesn't ship format types, so we just try and be clever here.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/geo_combine/ogp.rb', line 105 def ogp_formats case ['DataType'] when 'Paper Map', 'Raster' 'GeoTIFF' when 'Polygon', 'Point', 'Line' 'Shapefile' else raise ArgumentError, ['DataType'] end end |
#ogp_geom ⇒ Object
Convert "Paper Map" to Raster, assumes all OGP "Paper Maps" have WMS
94 95 96 97 98 99 100 101 |
# File 'lib/geo_combine/ogp.rb', line 94 def ogp_geom case ['DataType'] when 'Paper Map' 'Raster' else ['DataType'] end end |
#placenames ⇒ Object
140 141 142 |
# File 'lib/geo_combine/ogp.rb', line 140 def placenames fgdc..xpath('//placekey').map(&:text) if fgdc end |
#references ⇒ String
Converts references to json
119 120 121 |
# File 'lib/geo_combine/ogp.rb', line 119 def references references_hash.to_json end |
#subjects ⇒ Object
136 137 138 |
# File 'lib/geo_combine/ogp.rb', line 136 def subjects fgdc..xpath('//themekey').map(&:text) if fgdc end |
#to_geoblacklight ⇒ GeoCombine::Geoblacklight
Creates and returns a Geoblacklight schema object from this metadata
44 45 46 |
# File 'lib/geo_combine/ogp.rb', line 44 def to_geoblacklight GeoCombine::Geoblacklight.new(geoblacklight_terms.to_json) end |
#valid? ⇒ Boolean
Runs validity checks on OGP metadata to ensure fields are present
37 38 39 |
# File 'lib/geo_combine/ogp.rb', line 37 def valid? OGP_REQUIRED_FIELDS.all? { |k| [k].present? } end |
#year ⇒ Object
88 89 90 |
# File 'lib/geo_combine/ogp.rb', line 88 def year date&.year end |