Class: GeoCombine::OGP

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Formatting

#remove_lines, #sanitize, #sanitize_and_remove_lines, #sluggify

Constructor Details

#initialize(metadata) ⇒ OGP

Initializes an OGP object for parsing

Raises:



17
18
19
20
# File 'lib/geo_combine/ogp.rb', line 17

def initialize()
   = JSON.parse()
  raise  unless valid?
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/geo_combine/ogp.rb', line 11

def 
  
end

Instance Method Details

#dateObject



81
82
83
84
85
# File 'lib/geo_combine/ogp.rb', line 81

def date
  DateTime.rfc3339(['ContentDate'])
rescue StandardError
  nil
end

#envelopeString

Builds a Solr Envelope using CQL syntax

Raises:

  • (ArgumentError)


125
126
127
128
129
130
131
132
133
# 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

#fgdcObject



143
144
145
# File 'lib/geo_combine/ogp.rb', line 143

def fgdc
  GeoCombine::Fgdc.new(['FgdcText']) if ['FgdcText']
end

#geoblacklight_termsHash

Builds a Geoblacklight Schema type hash from Esri Open Data portal metadata



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
78
79
# File 'lib/geo_combine/ogp.rb', line 51

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: "#{metadata['WorkspaceName']}:#{metadata['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_formatsObject

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'
    'GeoTIFF'
  when 'Polygon', 'Point', 'Line'
    'Shapefile'
  else
    raise ArgumentError, ['DataType']
  end
end

#ogp_geomObject

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

#placenamesObject



139
140
141
# File 'lib/geo_combine/ogp.rb', line 139

def placenames
  fgdc..xpath('//placekey').map(&:text) if fgdc
end

#referencesString

Converts references to json



118
119
120
# File 'lib/geo_combine/ogp.rb', line 118

def references
  references_hash.to_json
end

#subjectsObject



135
136
137
# File 'lib/geo_combine/ogp.rb', line 135

def subjects
  fgdc..xpath('//themekey').map(&:text) if fgdc
end

#to_geoblacklightGeoCombine::Geoblacklight

Creates and returns a Geoblacklight schema object from this metadata



43
44
45
# File 'lib/geo_combine/ogp.rb', line 43

def to_geoblacklight
  GeoCombine::Geoblacklight.new(geoblacklight_terms.to_json)
end

#valid?Boolean

Runs validity checks on OGP metadata to ensure fields are present



36
37
38
# File 'lib/geo_combine/ogp.rb', line 36

def valid?
  OGP_REQUIRED_FIELDS.all? { |k| [k].present? }
end

#yearObject



87
88
89
# File 'lib/geo_combine/ogp.rb', line 87

def year
  date&.year
end