Skip to content

Commit

Permalink
Merge pull request #131 from stansmith907/dev
Browse files Browse the repository at this point in the history
Add FGDC CSDGM 1998 reader
  • Loading branch information
jlblcc authored Sep 12, 2017
2 parents 32555bd + fe9b802 commit 962658a
Show file tree
Hide file tree
Showing 48 changed files with 2,593 additions and 210 deletions.
46 changes: 23 additions & 23 deletions lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,29 +436,6 @@ def newGraphic
}
end

def newSpatialReferenceSystem
{
systemType: nil,
systemIdentifier: {}
}
end

def newSpatialResolution
{
scaleFactor: nil,
measure: {},
levelOfDetail: nil
}
end

def newMeasure
{
type: nil,
value: nil,
unitOfMeasure: nil
}
end

def newExtent
{
description: nil,
Expand Down Expand Up @@ -793,6 +770,29 @@ def newEntityForeignKey
}
end

def newSpatialReferenceSystem
{
systemType: nil,
systemIdentifier: {}
}
end

def newSpatialResolution
{
scaleFactor: nil,
measure: {},
levelOfDetail: nil
}
end

def newMeasure
{
type: nil,
value: nil,
unitOfMeasure: nil
}
end

def newSpatialRepresentation
{
gridRepresentation: {},
Expand Down
1 change: 1 addition & 0 deletions lib/adiwg/mdtranslator/readers/fgdc/fgdc_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Stan Smith 2017-08-10 original script

require 'nokogiri'
require_relative 'version'
require_relative 'modules/module_fgdc'

module ADIWG
Expand Down
110 changes: 110 additions & 0 deletions lib/adiwg/mdtranslator/readers/fgdc/modules/module_attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Reader - fgdc to internal data structure
# unpack fgdc entity attribute

# History:
# Stan Smith 2017-09-06 original script

require 'uuidtools'
require 'nokogiri'
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
require_relative 'module_enumerated'
require_relative 'module_range'

module ADIWG
module Mdtranslator
module Readers
module Fgdc

module Attribute

def self.unpack(xAttribute, hDictionary, hResponseObj)

# instance classes needed in script
intMetadataClass = InternalMetadata.new
hAttribute = intMetadataClass.newEntityAttribute

# entity attribute 5.1.2.1 (attrlabl) - attribute name
# -> dataDictionary.entities.attributes.attributeCode
code = xAttribute.xpath('./attrlabl').text
unless code.empty?
hAttribute[:attributeName] = code
hAttribute[:attributeCode] = code
end

# entity attribute 5.1.2.2 (attrdef) - attribute definition
# -> dataDictionary.entities.attributes.attributeDefinition
definition = xAttribute.xpath('./attrdef').text
unless definition.empty?
hAttribute[:attributeDefinition] = definition
end

# entity attribute 5.1.2.3 (attrdefs) - attribute definition source
# -> not mapped

# entity attribute 5.1.2.4 (attrdomv) - attribute domain value
axDomain = xAttribute.xpath('./attrdomv')
unless axDomain.empty?
hDomain = intMetadataClass.newDictionaryDomain
hDomain[:domainId] = UUIDTools::UUID.random_create.to_s
hDomain[:domainCode] = code
hDomain[:domainDescription] = 'FGDC enumerated domain'

axDomain.each do |xDomain|

# entity attribute 5.1.2.4.1 (edom) - enumerated domain
xEnumeration = xDomain.xpath('./edom')
unless xEnumeration.empty?
hItem = Enumerated.unpack(xEnumeration, hResponseObj)
hDomain[:domainItems] << hItem
end

# entity attribute 5.1.2.4.2 (rdom) - range domain
xRange = xDomain.xpath('./rdom')
unless xRange.empty?
Range.unpack(xRange, hAttribute, hResponseObj)
end

# entity attribute 5.1.2.4.3 (codesetd) - codeset domain

# entity attribute 5.1.2.4.3.1 (codesetn) - codeset name
# -> not mapped

# entity attribute 5.1.2.4.3.2 (codesets) - codeset source
# -> not mapped

# entity attribute 5.1.2.4.4 (udom) - unrepresentable domain
# -> not mapped

end

unless hDomain[:domainItems].empty?
hAttribute[:domainId] = hDomain[:domainId]
hDictionary[:domains] << hDomain
end

end

# entity attribute 5.1.2.5 (begdatea) - beginning date of attribute values
# -> not mapped

# entity attribute 5.1.2.6 (enddatea) - ending date of attribute values
# -> not mapped

# entity attribute 5.1.2.7 (attrvai) - attribute value accuracy information

# entity attribute 5.1.2.7.1 (attrva) - attribute value accuracy
# -> not mapped

# entity attribute 5.1.2.7.2 (attrvae) - attribute value accuracy explanation
# -> not mapped

hAttribute

end

end

end
end
end
end
69 changes: 69 additions & 0 deletions lib/adiwg/mdtranslator/readers/fgdc/modules/module_digitalForm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Reader - fgdc to internal data structure
# unpack fgdc distribution digital form

# History:
# Stan Smith 2017-09-08 original script

require 'nokogiri'
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
require_relative 'module_date'
require_relative 'module_transferInfo'
require_relative 'module_onlineOption'
require_relative 'module_offlineOption'

module ADIWG
module Mdtranslator
module Readers
module Fgdc

module DigitalForm

def self.unpack(xDigiForm, hResponseObj)

# instance classes needed in script
intMetadataClass = InternalMetadata.new
hTransfer = intMetadataClass.newTransferOption

# distribution 6.4.2.1 (digtinfo) - digital transfer information
xTranInfo = xDigiForm.xpath('./digtinfo')
unless xTranInfo.empty?
TransferInfo.unpack(xTranInfo, hTransfer, hResponseObj)
end

# distribution 6.4.2.2 (digtopt) - digital transfer option
xDigiOption = xDigiForm.xpath('./digtopt')
unless xDigiOption.empty?

# distribution 6.4.2.2.1 (onlinopt) - online option []
axOnlines = xDigiOption.xpath('./onlinopt')
unless axOnlines.empty?
axOnlines.each do |xOnline|
aOnlines = OnlineOption.unpack(xOnline, hResponseObj)
aOnlines.each do |hOnline|
hTransfer[:onlineOptions] << hOnline
end
end
end

# distribution 6.4.2.2.2 (offoptn) - offline option []
axOfflines = xDigiOption.xpath('./offoptn')
unless axOfflines.empty?
axOfflines.each do |xOffline|
aOffline = OfflineOption.unpack(xOffline, hResponseObj)
aOffline.each do |hOffline|
hTransfer[:offlineOptions] << hOffline
end
end
end

end

return hTransfer

end
end

end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

require 'nokogiri'
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
require_relative 'module_contact'
require_relative 'module_orderProcess'
require_relative 'module_timePeriod'

module ADIWG
module Mdtranslator
Expand All @@ -14,9 +17,87 @@ module Fgdc

module Distribution

def self.unpack(xDistribution, hResponseObj)
def self.unpack(xDistribution, hResourceInfo, hResponseObj)

# instance classes needed in script
intMetadataClass = InternalMetadata.new
hDistribution = intMetadataClass.newDistribution
hDistributor = intMetadataClass.newDistributor

# distribution 6.1 (distrib) - distributor {contact}
# -> distribution.distributor.contact.responsibility(distributor)
xContact = xDistribution.xpath('./distrib')
unless xContact.empty?
hResponsibility = Contact.unpack(xContact, hResponseObj)
unless hResponsibility.nil?
hResponsibility[:roleName] = 'distributor'
hDistributor[:contact] = hResponsibility
end
end

# distribution 6.2 (resdesc) - resource description
# -> distribution.description
description = xDistribution.xpath('./resdesc').text
unless description.empty?
hDistribution[:description] = description
end

# distribution 6.3 (distliab) - distribution liability
# -> resourceInfo.constraints.legal.otherConstraint
constraint = xDistribution.xpath('./distliab').text
unless constraint.empty?
hConstraint = intMetadataClass.newConstraint
hConstraint[:type] = 'legal'
hLegal = intMetadataClass.newLegalConstraint
hLegal[:otherCons] << constraint
hConstraint[:legalConstraint] = hLegal
hResourceInfo[:constraints] << hConstraint
end

# distribution 6.4 (stdorder) - standard order process []
axOrders = xDistribution.xpath('./stdorder')
unless axOrders.empty?
axOrders.each do |xOrder|
OrderProcess.unpack(xOrder, hDistributor, hResponseObj)
end
end

# distribution 6.5 (custom) - custom order process
# -> distribution.distributor.orderProcess.orderingInstructions
custom = xDistribution.xpath('./custom').text
unless custom.empty?
hOrder = intMetadataClass.newOrderProcess
hOrder[:orderingInstructions] = custom
hDistributor[:orderProcess] << hOrder
end

# distribution 6.6 (techpreq) - technical prerequisites
# -> distribution.description {+=}
techPre = xDistribution.xpath('./techpreq').text
unless techPre.empty?
hDistribution[:description] += '\n\n Technical Prerequisites: ' + techPre
end

# distribution 6.7 (availabl) - available time period {time period}
# -> distribution.distributor.orderProcess.plannedAvailability
xTimePeriod = xDistribution.xpath('./availabl')
unless xTimePeriod.empty?
hTimePeriod = TimePeriod.unpack(xTimePeriod, hResponseObj)
unless hTimePeriod.nil?
if hTimePeriod[:startDateTime].empty?
hDateTime = hTimePeriod[:endDateTime]
else
hDateTime = hTimePeriod[:startDateTime]
end
hDistributor[:orderProcess].each do |hOrder|
hOrder[:plannedAvailability] = hDateTime
end
end
end

hDistribution[:distributor] << hDistributor

return hDistribution

end

Expand Down
Loading

0 comments on commit 962658a

Please sign in to comment.