Skip to content

Commit

Permalink
Merge pull request #106 from datacite/support_multiple_geolocation_po…
Browse files Browse the repository at this point in the history
…lygons

Add support for multiple geolocation polygons
  • Loading branch information
richardhallett authored Mar 24, 2021
2 parents d5b6320 + 183ea9f commit db09275
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/bolognese/readers/datacite_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def read_datacite(string: nil, **options)
"southBoundLatitude" => gl.dig("geoLocationBox", "southBoundLatitude"),
"northBoundLatitude" => gl.dig("geoLocationBox", "northBoundLatitude")
}.compact.presence,
"geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon", "polygonPoint")).map { |glp| { "polygonPoint" => glp } }.compact.presence,
"geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon")).map do |glp|
Array.wrap(glp.dig("polygonPoint")).map { |glpp| { "polygonPoint" => glpp } }.compact.presence
end,
"geoLocationPlace" => parse_attributes(gl["geoLocationPlace"], first: true).to_s.strip.presence
}.compact
end
Expand Down
56 changes: 56 additions & 0 deletions spec/fixtures/datacite-geolocationpolygons-multiple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.4/metadata.xsd">
<identifier identifierType="DOI">10.5072/multiplegeopolygons</identifier>
<creators>
<creator>
<creatorName>John Smithy</creatorName>
</creator>
</creators>
<titles>
<title>Multiple Geopolygon testing</title>
</titles>
<resourceType resourceTypeGeneral="Software">XML</resourceType>
<publisher>DataCite</publisher>
<publicationYear>2021</publicationYear>
<geoLocations>
<geoLocation>
<geoLocationPolygon>
<polygonPoint>
<pointLongitude>41</pointLongitude>
<pointLatitude>71</pointLatitude>
</polygonPoint>
<polygonPoint>
<pointLongitude>45</pointLongitude>
<pointLatitude>75</pointLatitude>
</polygonPoint>
<polygonPoint>
<pointLongitude>55</pointLongitude>
<pointLatitude>85</pointLatitude>
</polygonPoint>
<polygonPoint>
<pointLongitude>41</pointLongitude>
<pointLatitude>71</pointLatitude>
</polygonPoint>
</geoLocationPolygon>
<geoLocationPolygon>
<polygonPoint>
<pointLongitude>65</pointLongitude>
<pointLatitude>80</pointLatitude>
</polygonPoint>
<polygonPoint>
<pointLongitude>55</pointLongitude>
<pointLatitude>75</pointLatitude>
</polygonPoint>
<polygonPoint>
<pointLongitude>45</pointLongitude>
<pointLatitude>73</pointLatitude>
</polygonPoint>
<polygonPoint>
<pointLongitude>65</pointLongitude>
<pointLatitude>80</pointLatitude>
</polygonPoint>
</geoLocationPolygon>
</geoLocation>
</geoLocations>
</resource>
22 changes: 22 additions & 0 deletions spec/readers/datacite_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1545,4 +1545,26 @@
expect(subject.formats.first).to eq("application/xml")
end

it "Parsing multiple geolocationpolygon elements" do
input = fixture_path + "datacite-geolocationpolygons-multiple.xml"
subject = Bolognese::Metadata.new(input: input)
expect(subject.valid?).to be true
expect(subject.id).to eq("https://doi.org/10.5072/multiplegeopolygons")
expect(subject.geo_locations).to eq([
{ "geoLocationPolygon"=> [
[ {"polygonPoint"=>{"pointLatitude"=>"71", "pointLongitude"=>"41"}},
{"polygonPoint"=>{"pointLatitude"=>"75", "pointLongitude"=>"45"}},
{"polygonPoint"=>{"pointLatitude"=>"85", "pointLongitude"=>"55"}},
{"polygonPoint"=>{"pointLatitude"=>"71", "pointLongitude"=>"41"}}],
[
{"polygonPoint"=>{"pointLatitude"=>"80", "pointLongitude"=>"65"}},
{"polygonPoint"=>{"pointLatitude"=>"75", "pointLongitude"=>"55"}},
{"polygonPoint"=>{"pointLatitude"=>"73", "pointLongitude"=>"45"}},
{"polygonPoint"=>{"pointLatitude"=>"80", "pointLongitude"=>"65"}}
]
] }
]
)
end

end

0 comments on commit db09275

Please sign in to comment.