adiwg-mdtranslator 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +31 -0
- data/Rakefile +13 -0
- data/adiwg-mdtranslator.gemspec +31 -0
- data/bin/mdtranslator +164 -0
- data/lib/adiwg/mdtranslator/internal/internal_metadata_obj.rb +499 -0
- data/lib/adiwg/mdtranslator/internal/module_dateTimeFun.rb +98 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/adiwgJson_reader.rb +80 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/adiwgJson_validator.rb +115 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_address.rb +71 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_associatedResource.rb +57 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_boundingBox.rb +51 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_browseGraphic.rb +52 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_citation.rb +104 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_contacts.rb +121 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_coordinates.rb +52 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_dataQuality.rb +40 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_dateTime.rb +27 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_descriptiveKeyword.rb +49 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_distributionInfo.rb +150 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_extent.rb +62 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_geoCoordSystem.rb +46 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_geoProperties.rb +89 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_geographicElement.rb +168 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_legalConstraint.rb +45 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_lineString.rb +25 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_lineage.rb +50 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_metadata.rb +76 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_metadataExtension.rb +40 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_metadataInfo.rb +119 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_onlineResource.rb +62 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_phone.rb +59 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_point.rb +25 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_polygon.rb +55 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_processStep.rb +64 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resolution.rb +42 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceFormat.rb +35 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceIdentifier.rb +49 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceInfo.rb +298 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceMaintenance.rb +50 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_resourceSpecificUsage.rb +50 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_responsibleParty.rb +37 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_securityConstraint.rb +52 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_source.rb +48 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_spatialReference.rb +48 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_taxonClass.rb +43 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_taxonomy.rb +83 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_temporalElement.rb +71 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_timeInstant.rb +45 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_timePeriod.rb +53 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_verticalElement.rb +53 -0
- data/lib/adiwg/mdtranslator/readers/adiwgJson/modules_0.8.0/module_voucher.rb +38 -0
- data/lib/adiwg/mdtranslator/validator.rb +43 -0
- data/lib/adiwg/mdtranslator/version.rb +7 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_address.rb +91 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_aggregateInformation.rb +68 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_boundingPolygon.rb +75 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_browseGraphic.rb +51 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_citation.rb +157 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_contact.rb +85 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_dataIdentification.rb +338 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_dataQuality.rb +55 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_date.rb +60 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_digitalTransferOptions.rb +51 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_distribution.rb +36 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_distributor.rb +80 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_extent.rb +94 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_format.rb +40 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_genericMetaData.rb +65 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_geographicBoundingBox.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_geographicDescription.rb +29 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_geographicElement.rb +36 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_identifier.rb +51 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_keyword.rb +63 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_legalConstraints.rb +63 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_lineString.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_lineage.rb +63 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_maintenanceInformation.rb +64 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_medium.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadata.rb +277 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_metadataExtension.rb +156 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_multiGeometry.rb +140 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_onlineResource.rb +78 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_point.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_polygon.rb +94 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_processStep.rb +81 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_referenceIdentifier.rb +42 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_referenceSystem.rb +29 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_resolution.rb +46 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_responsibleParty.rb +90 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_securityConstraints.rb +68 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_source.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_standardOrderProcess.rb +74 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_taxonClassification.rb +65 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_taxonSystem.rb +100 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_telephone.rb +77 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_temporalExtent.rb +58 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_timeInstant.rb +47 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_timePeriod.rb +54 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_usage.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_useConstraints.rb +30 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_verticalExtent.rb +59 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/classes/class_vouchers.rb +48 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_associationType.rb +35 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_characterSet.rb +58 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_classification.rb +35 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_datatype.rb +45 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_dateType.rb +29 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_initiativeType.rb +35 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_keywordType.rb +33 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_maintenanceFrequency.rb +42 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_mediumFormat.rb +32 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_mediumName.rb +44 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_obligation.rb +32 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_onlineFunction.rb +31 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_presentationForm.rb +44 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_progress.rb +33 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_restriction.rb +38 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_role.rb +37 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_scope.rb +46 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_spatialRepresentationType.rb +36 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/codelists/code_topicCategory.rb +50 -0
- data/lib/adiwg/mdtranslator/writers/iso19115_2/iso19115_2_writer.rb +131 -0
- data/lib/adiwg/mdtranslator.rb +97 -0
- data/lib/adiwg-mdtranslator.rb +1 -0
- data/mdtranslator.rb +178 -0
- data/test/adiwgJson_full_test_example.json +1717 -0
- data/test/adiwgJson_template.json +977 -0
- data/test/dev.rb +32 -0
- data/test/tc_translation.rb +31 -0
- metadata +317 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# ISO <<CodeLists>> gmd:CI_RoleCode
|
2
|
+
|
3
|
+
# from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2013-08-09 original script
|
6
|
+
|
7
|
+
class CI_RoleCode
|
8
|
+
def initialize(xml)
|
9
|
+
@xml = xml
|
10
|
+
end
|
11
|
+
|
12
|
+
def writeXML(codeName)
|
13
|
+
|
14
|
+
case(codeName)
|
15
|
+
when 'resourceProvider' then codeID = '001'
|
16
|
+
when 'custodian' then codeID = '002'
|
17
|
+
when 'owner' then codeID = '003'
|
18
|
+
when 'user' then codeID = '004'
|
19
|
+
when 'distributor' then codeID = '005'
|
20
|
+
when 'originator' then codeID = '006'
|
21
|
+
when 'pointOfContact' then codeID = '007'
|
22
|
+
when 'principalInvestigator' then codeID = '008'
|
23
|
+
when 'processor' then codeID = '009'
|
24
|
+
when 'publisher' then codeID = '010'
|
25
|
+
when 'author' then codeID = '011'
|
26
|
+
else
|
27
|
+
codeName = 'INVALID ROLE CODE'
|
28
|
+
codeID = '999'
|
29
|
+
end
|
30
|
+
|
31
|
+
# write xml
|
32
|
+
@xml.tag!('gmd:CI_RoleCode',{:codeList=>'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode',
|
33
|
+
:codeListValue=>"#{codeName}",
|
34
|
+
:codeSpace=>"#{codeID}"})
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# ISO <<CodeLists>> gmd:MD_ScopeCode
|
2
|
+
|
3
|
+
# from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2013-08-09 original script
|
6
|
+
|
7
|
+
class MD_ScopeCode
|
8
|
+
def initialize(xml)
|
9
|
+
@xml = xml
|
10
|
+
end
|
11
|
+
|
12
|
+
def writeXML(codeName)
|
13
|
+
case(codeName)
|
14
|
+
when 'attribute' then codeID = '001'
|
15
|
+
when 'attributeType' then codeID = '002'
|
16
|
+
when 'collectionHardware' then codeID = '003'
|
17
|
+
when 'collectionSession' then codeID = '004'
|
18
|
+
when 'dataset' then codeID = '005'
|
19
|
+
when 'series' then codeID = '006'
|
20
|
+
when 'nonGeographicDataset' then codeID = '007'
|
21
|
+
when 'dimensionGroup' then codeID = '008'
|
22
|
+
when 'feature' then codeID = '009'
|
23
|
+
when 'featureType' then codeID = '010'
|
24
|
+
when 'propertyType' then codeID = '011'
|
25
|
+
when 'fieldSession' then codeID = '012'
|
26
|
+
when 'software' then codeID = '013'
|
27
|
+
when 'service' then codeID = '014'
|
28
|
+
when 'model' then codeID = '015'
|
29
|
+
when 'tile' then codeID = '016'
|
30
|
+
else
|
31
|
+
codeName = 'INVALID SCOPE CODE'
|
32
|
+
codeID = '999'
|
33
|
+
end
|
34
|
+
|
35
|
+
# write xml
|
36
|
+
@xml.tag!('gmd:MD_ScopeCode',{:codeList=>'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode',
|
37
|
+
:codeListValue=>"#{codeName}",
|
38
|
+
:codeSpace=>"#{codeID}"})
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# ISO <<CodeLists>> gmd:MD_SpatialRepresentationTypeCode
|
2
|
+
|
3
|
+
# from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2013-10-21 original script
|
6
|
+
|
7
|
+
class MD_SpatialRepresentationTypeCode
|
8
|
+
def initialize(xml)
|
9
|
+
@xml = xml
|
10
|
+
end
|
11
|
+
|
12
|
+
def writeXML(codeName)
|
13
|
+
case(codeName)
|
14
|
+
when 'vector' then codeID = '001'
|
15
|
+
when 'grid' then codeID = '002'
|
16
|
+
when 'textTable' then codeID = '003'
|
17
|
+
when 'tin' then codeID = '004'
|
18
|
+
when 'stereoModel' then codeID = '005'
|
19
|
+
when 'video' then codeID = '006'
|
20
|
+
else
|
21
|
+
codeName = 'INVALID SPATIAL REPRESENTATION TYPE'
|
22
|
+
codeID = '999'
|
23
|
+
end
|
24
|
+
|
25
|
+
# write xml
|
26
|
+
@xml.tag!('gmd:MD_SpatialRepresentationTypeCode',{:codeList=>'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_SpatialRepresentationTypeCode',
|
27
|
+
:codeListValue=>"#{codeName}",
|
28
|
+
:codeSpace=>"#{codeID}"})
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# ISO <<CodeLists>> gmd:MD_TopicCategoryCode
|
2
|
+
# Enumeration
|
3
|
+
|
4
|
+
# from http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml
|
5
|
+
# History:
|
6
|
+
# Stan Smith 2013-10-21 original script
|
7
|
+
|
8
|
+
class MD_TopicCategoryCode
|
9
|
+
def initialize(xml)
|
10
|
+
@xml = xml
|
11
|
+
end
|
12
|
+
|
13
|
+
def writeXML(codeName)
|
14
|
+
case(codeName)
|
15
|
+
when 'farming',
|
16
|
+
'biota',
|
17
|
+
'boundaries',
|
18
|
+
'climatologyMeteorologyAtmosphere',
|
19
|
+
'economy',
|
20
|
+
'elevation',
|
21
|
+
'environment',
|
22
|
+
'geoscientificInformation',
|
23
|
+
'health',
|
24
|
+
'imageryBaseMapsEarthCover',
|
25
|
+
'intelligenceMilitary',
|
26
|
+
'inlandWaters',
|
27
|
+
'location',
|
28
|
+
'oceans',
|
29
|
+
'planningCadastre',
|
30
|
+
'society',
|
31
|
+
'structure',
|
32
|
+
'transportation',
|
33
|
+
'utilitiesCommunication'
|
34
|
+
else
|
35
|
+
# topics not in the standard ISO list will not pass validation
|
36
|
+
# the domain is validated by the XSD
|
37
|
+
# this codelist cannot be extended
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
# write xml
|
42
|
+
@xml.tag!('gmd:MD_TopicCategoryCode',codeName)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# Writer - internal data structure to ISO 19115-2:2009
|
2
|
+
|
3
|
+
# History:
|
4
|
+
# Stan Smith 2013-08-10 original script
|
5
|
+
# Stan Smith 2014-06-04 add internal object pre-scan to create extents
|
6
|
+
# ... for geometry supplemental information
|
7
|
+
# Stan Smith 2014-07-08 modify require statements to function in RubyGem structure
|
8
|
+
|
9
|
+
require 'builder'
|
10
|
+
require 'date'
|
11
|
+
require 'uuidtools'
|
12
|
+
require 'class_metadata'
|
13
|
+
|
14
|
+
$idCount = '_000'
|
15
|
+
|
16
|
+
class Iso191152Writer
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
end
|
20
|
+
|
21
|
+
def writeXML(internalObj)
|
22
|
+
|
23
|
+
# pre-scan the internal object to create a new extents for each geometry
|
24
|
+
# ... that has supplemental information (temporal, vertical, identity)
|
25
|
+
# ... new extents will be added to internalObj as needed
|
26
|
+
prescanGeoElements(internalObj)
|
27
|
+
|
28
|
+
# create new XML document
|
29
|
+
xml = Builder::XmlMarkup.new(indent: 3)
|
30
|
+
metadataWriter = MI_Metadata.new(xml)
|
31
|
+
metadata = metadataWriter.writeXML(internalObj)
|
32
|
+
|
33
|
+
return metadata
|
34
|
+
end
|
35
|
+
|
36
|
+
def prescanGeoElements(internalObj)
|
37
|
+
# supplemental information for the geographic element is carried in the
|
38
|
+
# ... internal structure in the temporalElements:, verticalElements:,
|
39
|
+
# ... and elementIdentifiers: attributes of the extGeoElements:
|
40
|
+
# ... of the extent.
|
41
|
+
# since temporal, vertical, and identify information in ISO is a property
|
42
|
+
# ... of EX_Extent and not of the geographicElement,
|
43
|
+
# ... this code creates a new extent for each geographicElement
|
44
|
+
# ... that has supplemental information and
|
45
|
+
# ... moves the supplemental information from the geometry to the new extent.
|
46
|
+
# In this implementation, supplemental information is only allowed for
|
47
|
+
# ... geometry types of Point, LineString, and Polygon
|
48
|
+
aExtents = internalObj[:metadata][:resourceInfo][:extents]
|
49
|
+
unless aExtents.empty?
|
50
|
+
aExtents.each do |hExtent|
|
51
|
+
aGeoElements = hExtent[:extGeoElements]
|
52
|
+
unless aGeoElements.empty?
|
53
|
+
aGeoElements.each do |hGeoElement|
|
54
|
+
hGeometry = hGeoElement[:elementGeometry]
|
55
|
+
unless hGeometry.empty?
|
56
|
+
geoType = hGeometry[:geoType]
|
57
|
+
case geoType
|
58
|
+
when 'Point', 'LineString', 'Polygon'
|
59
|
+
newExtent = extentFromGeoElement(hGeoElement, geoType)
|
60
|
+
if !newExtent.nil?
|
61
|
+
aExtents << newExtent
|
62
|
+
end
|
63
|
+
|
64
|
+
when 'MultiGeometry'
|
65
|
+
aGeoMembers = hGeometry[:geometry]
|
66
|
+
unless aGeoMembers.empty?
|
67
|
+
aGeoMembers.each do |hGeoMemberElement|
|
68
|
+
hGeometry = hGeoMemberElement[:elementGeometry]
|
69
|
+
unless hGeometry.empty?
|
70
|
+
geoType = hGeometry[:geoType]
|
71
|
+
case geoType
|
72
|
+
when 'Point', 'LineString', 'Polygon'
|
73
|
+
newExtent = extentFromGeoElement(hGeoMemberElement, geoType)
|
74
|
+
if !newExtent.nil?
|
75
|
+
aExtents << newExtent
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def extentFromGeoElement(hGeoElement, geoType)
|
90
|
+
# build new extent to portray supplemental information
|
91
|
+
# from elementGeometry
|
92
|
+
if !hGeoElement[:temporalElements].empty? ||
|
93
|
+
!hGeoElement[:verticalElements].empty? ||
|
94
|
+
!hGeoElement[:elementIdentifiers].empty?
|
95
|
+
|
96
|
+
# get unique id for geometry
|
97
|
+
# if geometry id was missing, set it at this time so
|
98
|
+
# ... it will match the supplemental information extent description
|
99
|
+
geoID = hGeoElement[:elementId]
|
100
|
+
if geoID.nil?
|
101
|
+
$idCount = $idCount.succ
|
102
|
+
geoID = geoType + $idCount
|
103
|
+
hGeoElement[:elementId] = geoID
|
104
|
+
end
|
105
|
+
|
106
|
+
# build unique id for extent geometry
|
107
|
+
$idCount = $idCount.succ
|
108
|
+
extGeoID = geoType + $idCount
|
109
|
+
|
110
|
+
intMetadataClass = InternalMetadata.new
|
111
|
+
intExtent = intMetadataClass.newExtent
|
112
|
+
intGeoEle = intMetadataClass.newGeoElement
|
113
|
+
|
114
|
+
intGeoEle[:elementId] = extGeoID
|
115
|
+
intGeoEle[:elementGeometry] = hGeoElement[:elementGeometry]
|
116
|
+
|
117
|
+
intExtent[:extDesc] = 'Supplemental information for ' + geoID
|
118
|
+
intExtent[:extGeoElements] << intGeoEle
|
119
|
+
intExtent[:extIdElements] = hGeoElement[:elementIdentifiers]
|
120
|
+
intExtent[:extTempElements] = hGeoElement[:temporalElements]
|
121
|
+
intExtent[:extVertElements] = hGeoElement[:verticalElements]
|
122
|
+
|
123
|
+
return intExtent
|
124
|
+
|
125
|
+
else
|
126
|
+
return nil
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# MdTranslator - ADIwg MdTranslator RubyGem entry point
|
2
|
+
# ... pass input file to appropriate reader and writer;
|
3
|
+
# ... assign module path names for require statements
|
4
|
+
|
5
|
+
# History:
|
6
|
+
# Stan Smith 2014-07-02 original script
|
7
|
+
# Stan Smith 2014-07-21 added ADIWG namespace
|
8
|
+
# Stan Smith 2014-07-21 added validation of json structure
|
9
|
+
# Stan Smith 2014-07-23 moved all validations to readers/adiwg/adiwg_validator.rb
|
10
|
+
# ... each reader will have it's own validator
|
11
|
+
# Stan Smith 2014-09-26 added processing of minor release numbers
|
12
|
+
|
13
|
+
# add main directories to load_path
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'mdtranslator'))
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'mdtranslator/internal'))
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'mdtranslator/readers'))
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'mdtranslator/writers'))
|
18
|
+
|
19
|
+
require 'version'
|
20
|
+
require 'internal_metadata_obj'
|
21
|
+
|
22
|
+
module ADIWG
|
23
|
+
|
24
|
+
module Mdtranslator
|
25
|
+
|
26
|
+
def self.translate(file, reader, writer, validate, showAllTags)
|
27
|
+
|
28
|
+
$showAllTags = showAllTags
|
29
|
+
$response = {
|
30
|
+
readerFormat: nil,
|
31
|
+
readerStructurePass: nil,
|
32
|
+
readerStructureMessages: [],
|
33
|
+
readerName: reader,
|
34
|
+
readerNameFound: nil,
|
35
|
+
readerVersionFound: nil,
|
36
|
+
readerVersionUsed: nil,
|
37
|
+
readerValidationLevel: validate,
|
38
|
+
readerValidationPass: nil,
|
39
|
+
readerValidationMessages: [],
|
40
|
+
writerName: writer,
|
41
|
+
writerFormat: nil,
|
42
|
+
writerPass: nil,
|
43
|
+
writerMessages: [],
|
44
|
+
writerOutput: nil
|
45
|
+
}
|
46
|
+
|
47
|
+
# the mdtranslator gem loads and returns the above hash
|
48
|
+
|
49
|
+
case reader
|
50
|
+
when 'adiwgJson'
|
51
|
+
require 'adiwgJson/adiwgJson_validator'
|
52
|
+
|
53
|
+
# validate adiwgJson file
|
54
|
+
AdiwgJsonValidation.validate(file)
|
55
|
+
if $response[:readerStructurePass] && $response[:readerValidationPass]
|
56
|
+
# initiate the reader
|
57
|
+
require 'adiwgJson/adiwgJson_reader'
|
58
|
+
readerClass = AdiwgJsonReader.new
|
59
|
+
internalObj = readerClass.unpack(file)
|
60
|
+
else
|
61
|
+
return $response
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
case writer
|
66
|
+
when 'iso19115_2'
|
67
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'mdtranslator/writers/iso19115_2/codelists'))
|
68
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'mdtranslator/writers/iso19115_2/classes'))
|
69
|
+
require 'iso19115_2/iso19115_2_writer'
|
70
|
+
|
71
|
+
# set the format of the output file based on the writer specified
|
72
|
+
$response[:writerFormat] = 'xml'
|
73
|
+
|
74
|
+
writerClass = Iso191152Writer.new
|
75
|
+
|
76
|
+
# initiate the writer
|
77
|
+
$response[:writerOutput] = writerClass.writeXML(internalObj)
|
78
|
+
if $response[:writerMessages].length > 0
|
79
|
+
$response[:writerPass] = false
|
80
|
+
else
|
81
|
+
$response[:writerPass] = true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
return $response
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.reader_module(moduleName, version)
|
90
|
+
dir = File.join($response[:readerName], 'modules_' + version)
|
91
|
+
file = File.join(dir, moduleName)
|
92
|
+
return file
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'adiwg/mdtranslator'
|
data/mdtranslator.rb
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# ADIwg mdTranslator - Thor CLI for mdtranslator
|
3
|
+
|
4
|
+
# History:
|
5
|
+
# Stan Smith 2014-07-15 original script
|
6
|
+
# Stan Smith 2014-09-02 changed name to mdtranslator
|
7
|
+
# Stan Smith 2014-09-21 coded cli to 0.8.0 api
|
8
|
+
|
9
|
+
# uncomment next 2 lines during development to run from code (not gem) ....
|
10
|
+
lib = File.expand_path('lib')
|
11
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
12
|
+
|
13
|
+
require 'thor'
|
14
|
+
require 'adiwg-mdtranslator'
|
15
|
+
|
16
|
+
class Mdtranslator < Thor
|
17
|
+
|
18
|
+
# exit_on_failure added to exit with code 1 if thor cannot complete task
|
19
|
+
# such as if required parameters are missing
|
20
|
+
def self.exit_on_failure?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
# basic cli description
|
25
|
+
desc 'translate [FILE]', %q{Pass JSON string or filename plus parameters to mdtranslator translate}
|
26
|
+
long_desc <<-LONGDESC
|
27
|
+
'mdtranslator translate' provides command line access to the ADIWG metadata translator
|
28
|
+
with options to select the input file reader, select writer output format, show empty tags
|
29
|
+
in XML outputs, and choose level of validation for JSON inputs.
|
30
|
+
LONGDESC
|
31
|
+
# define cli options
|
32
|
+
method_option :reader, :aliases => '-r', :desc => 'Name of reader to read your input', :default => 'adiwgJson'
|
33
|
+
method_option :writer, :aliases => '-w', :desc => 'Name of writer to create your metadata, or leave blank to validate input only'
|
34
|
+
method_option :validate, :aliases => '-v', :desc => 'Specify level of validation to be performed', :enum => %w{none normal strict}, :default => 'normal'
|
35
|
+
method_option :showAllTags, :aliases => '-s', :desc => 'Include tags for unused attributes', :type => :boolean, :default => false
|
36
|
+
method_option :messages, :aliases => '-m', :desc => 'On error return messages as formatted text or json object', :enum => %w{json text}, :default => 'text'
|
37
|
+
method_option :returnObject, :aliases => '-o', :desc => 'Return full JSON object generated by translator', :type => :boolean, :default => false
|
38
|
+
|
39
|
+
# accept command and options
|
40
|
+
def translate(file)
|
41
|
+
|
42
|
+
# test to see if file parameter is a local file
|
43
|
+
# if not ... it is assumed to be a json string
|
44
|
+
if File.exist?(file)
|
45
|
+
# read file
|
46
|
+
my_file = File.open(file, 'r')
|
47
|
+
fileObj = my_file.read
|
48
|
+
my_file.close
|
49
|
+
else
|
50
|
+
fileObj = file
|
51
|
+
end
|
52
|
+
|
53
|
+
# for testing parameters
|
54
|
+
# puts 'reader: ' + options[:reader]
|
55
|
+
# puts 'writer: ' + options[:writer]
|
56
|
+
# puts 'validation level: ' + options[:validate]
|
57
|
+
# puts 'showAllTags: ' + options[:showAllTags].to_s
|
58
|
+
# puts 'message format: ' + options[:messages]
|
59
|
+
# puts 'return object format: ' + options[:returnObject]
|
60
|
+
# require 'pp'
|
61
|
+
# pp fileObj
|
62
|
+
|
63
|
+
# call mdtranslator
|
64
|
+
mdReturn = ADIWG::Mdtranslator.translate(fileObj, options[:reader], options[:writer],
|
65
|
+
options[:validate], options[:showAllTags])
|
66
|
+
|
67
|
+
# determine return content and type of return ...
|
68
|
+
if mdReturn[:readerStructurePass] && mdReturn[:readerValidationPass]
|
69
|
+
|
70
|
+
# no problem was found with the input file
|
71
|
+
if options[:writer].nil?
|
72
|
+
# if no writer was specified the input was being validated only,
|
73
|
+
# ...no writer output will have been generated,
|
74
|
+
# ...and the return will be a string unless json was requested
|
75
|
+
if options[:messages] == 'json'
|
76
|
+
$stdout.write mdReturn.to_json
|
77
|
+
return
|
78
|
+
else
|
79
|
+
$stdout.write 'Success'
|
80
|
+
return
|
81
|
+
end
|
82
|
+
else
|
83
|
+
# a writer was specified,
|
84
|
+
# output is expected from the translator's writer
|
85
|
+
if mdReturn[:writerPass]
|
86
|
+
# writer output was generated
|
87
|
+
# ...return the writer output in its native format unless json was requested
|
88
|
+
if options[:returnObject]
|
89
|
+
$stdout.write mdReturn.to_json
|
90
|
+
return
|
91
|
+
else
|
92
|
+
$stdout.write mdReturn[:writerOutput].to_s
|
93
|
+
return
|
94
|
+
end
|
95
|
+
else
|
96
|
+
# the writer failed or generated warnings to be reported
|
97
|
+
# ...return the messages as a string unless json was requested
|
98
|
+
if options[:messages] == 'json'
|
99
|
+
$stdout.write mdReturn.to_json
|
100
|
+
return
|
101
|
+
else
|
102
|
+
# build a string with messages issues from parser and validator
|
103
|
+
s = ''
|
104
|
+
s += "Failed\n"
|
105
|
+
s += "Writer failed to generate output or issued significant warnings\n"
|
106
|
+
s += "See following messages for further information\n"
|
107
|
+
|
108
|
+
# post structure messages
|
109
|
+
i = 0
|
110
|
+
mdReturn[:writerMessages].each do |message|
|
111
|
+
i += 1
|
112
|
+
s += "\nMessage: #{i}\n"
|
113
|
+
s += message + "\n"
|
114
|
+
end
|
115
|
+
|
116
|
+
$stdout.write s
|
117
|
+
return
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
else
|
124
|
+
|
125
|
+
# problems were found with the input file
|
126
|
+
|
127
|
+
# if no writer was specified the input was being validated only,
|
128
|
+
# ...no writer output will have been generated,
|
129
|
+
# ...and return is always expected to be a string
|
130
|
+
if options[:messages] == 'json'
|
131
|
+
$stdout.write mdReturn.to_json
|
132
|
+
return
|
133
|
+
else
|
134
|
+
# build a string with messages issues from parser and validator
|
135
|
+
s = ''
|
136
|
+
s += "Failed\n"
|
137
|
+
s += "Input failed to pass either file structure validation or content does not match schema\n"
|
138
|
+
s += "See following messages for further information\n"
|
139
|
+
|
140
|
+
# post structure messages
|
141
|
+
if mdReturn[:readerStructurePass]
|
142
|
+
s += "Success - Input structure is valid\n"
|
143
|
+
else
|
144
|
+
s += "Fail - Structure of input file is invalid - see following message(s):\n"
|
145
|
+
i = 0
|
146
|
+
mdReturn[:readerStructureMessages].each do |message|
|
147
|
+
i += 1
|
148
|
+
s += "\nMessage: #{i}\n"
|
149
|
+
s += message.to_s + "\n"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# post validator messages
|
154
|
+
unless mdReturn[:readerValidationPass].nil?
|
155
|
+
if mdReturn[:readerValidationPass]
|
156
|
+
s += "Success - Input content passes schema definition\n"
|
157
|
+
else
|
158
|
+
s += "Fail - Input content did not pass schema validation - see following message(s):\n"
|
159
|
+
i = 0
|
160
|
+
mdReturn[:readerValidationMessages].each do |message|
|
161
|
+
i += 1
|
162
|
+
s += "\nMessage: #{i}\n"
|
163
|
+
s += message.to_s + "\n"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
$stdout.write s
|
169
|
+
return
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
Mdtranslator.start(ARGV)
|
177
|
+
|
178
|
+
end
|