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
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
15 16 17 18 |
# File 'lib/geo_combine/ogp.rb', line 15 def initialize() @metadata = JSON.parse() raise InvalidMetadata unless valid? end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/geo_combine/ogp.rb', line 9 def @metadata end |
Instance Method Details
#date ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/geo_combine/ogp.rb', line 79 def date begin DateTime.rfc3339(['ContentDate']) rescue nil end end |
#envelope ⇒ String
Builds a Solr Envelope using CQL syntax
125 126 127 128 129 130 131 132 |
# File 'lib/geo_combine/ogp.rb', line 125 def envelope raise ArgumentError unless west >= -180 && west <= 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
142 143 144 |
# File 'lib/geo_combine/ogp.rb', line 142 def fgdc GeoCombine::Fgdc.new(['FgdcText']) if ['FgdcText'] end |
#geoblacklight_terms ⇒ Hash
Builds a Geoblacklight Schema type hash from Esri Open Data portal metadata
49 50 51 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 |
# File 'lib/geo_combine/ogp.rb', line 49 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' }.delete_if { |_k, v| v.nil? } end |
#ogp_formats ⇒ Object
OGP doesn’t ship format types, so we just try and be clever here.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/geo_combine/ogp.rb', line 104 def ogp_formats case ['DataType'] when 'Paper Map', 'Raster' return 'GeoTIFF' when 'Polygon', 'Point', 'Line' return 'Shapefile' else raise ArgumentError, ['DataType'] end end |
#ogp_geom ⇒ Object
Convert “Paper Map” to Raster, assumes all OGP “Paper Maps” have WMS
93 94 95 96 97 98 99 100 |
# File 'lib/geo_combine/ogp.rb', line 93 def ogp_geom case ['DataType'] when 'Paper Map' 'Raster' else ['DataType'] end end |
#placenames ⇒ Object
138 139 140 |
# File 'lib/geo_combine/ogp.rb', line 138 def placenames fgdc..xpath('//placekey').map(&:text) if fgdc end |
#references ⇒ String
Converts references to json
118 119 120 |
# File 'lib/geo_combine/ogp.rb', line 118 def references references_hash.to_json end |
#subjects ⇒ Object
134 135 136 |
# File 'lib/geo_combine/ogp.rb', line 134 def subjects fgdc..xpath('//themekey').map(&:text) if fgdc end |
#to_geoblacklight ⇒ GeoCombine::Geoblacklight
Creates and returns a Geoblacklight schema object from this metadata
41 42 43 |
# File 'lib/geo_combine/ogp.rb', line 41 def to_geoblacklight GeoCombine::Geoblacklight.new(geoblacklight_terms.to_json) end |
#valid? ⇒ Boolean
Runs validity checks on OGP metadata to ensure fields are present
34 35 36 |
# File 'lib/geo_combine/ogp.rb', line 34 def valid? OGP_REQUIRED_FIELDS.all? { |k| [k].present? } end |
#year ⇒ Object
87 88 89 |
# File 'lib/geo_combine/ogp.rb', line 87 def year date.year unless date.nil? end |