Skip to content

Commit fbe373e

Browse files
authored
Merge pull request #26 from cedardevs/1080-antimeridian-bbox-parsing
Parsing bbox crossing antimeridian.
2 parents 0c8414d + 8af50cd commit fbe373e

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

schemas-parse/src/main/groovy/org/cedar/schemas/parse/ISOParser.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.apache.commons.text.StringEscapeUtils
66
import org.cedar.schemas.avro.geojson.LineString
77
import org.cedar.schemas.avro.geojson.Point
88
import org.cedar.schemas.avro.geojson.Polygon
9+
import org.cedar.schemas.avro.geojson.MultiPolygon
910
import org.cedar.schemas.avro.psi.*
1011

1112
class ISOParser {
@@ -324,6 +325,13 @@ class ISOParser {
324325
builder = LineString.newBuilder()
325326
coordinates = [[west, south], [east, north]]
326327
}
328+
else if (west > east) {
329+
builder = MultiPolygon.newBuilder()
330+
coordinates = [
331+
[[[-180, south], [east, south], [east, north], [-180, north], [-180, south]]],
332+
[[[west, south], [180, south], [180, north], [west, north], [west, south]]]
333+
]
334+
}
327335
else {
328336
// this returns with correlating null values as well
329337
builder = Polygon.newBuilder()

schemas-parse/src/test/groovy/org/cedar/schemas/parse/ISOParserSpec.groovy

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.cedar.schemas.parse
33
import org.cedar.schemas.avro.geojson.LineStringType
44
import org.cedar.schemas.avro.geojson.PointType
55
import org.cedar.schemas.avro.geojson.PolygonType
6+
import org.cedar.schemas.avro.geojson.MultiPolygonType
67
import org.cedar.schemas.avro.psi.*
78
import org.cedar.schemas.avro.util.AvroUtils
89
import org.xml.sax.SAXParseException
@@ -201,6 +202,39 @@ class ISOParserSpec extends Specification {
201202
result.isGlobal
202203
}
203204

205+
def "Spatial bounding is correctly parsed when it crosses the antimeridian"() {
206+
207+
given:
208+
def document = ClassLoader.systemClassLoader.getResourceAsStream("test-iso-discontinous-antimeridian-coords.xml").text
209+
def metadata = new XmlSlurper().parseText(document)
210+
211+
when:
212+
def result = ISOParser.parseSpatialInfo(metadata)
213+
214+
215+
then:
216+
217+
def expectedCoordinates = [
218+
[[
219+
[-180.0, -81.3282],
220+
[6.2995, -81.3282],
221+
[6.2995, 81.3282],
222+
[-180.0, 81.3282],
223+
[-180.0, -81.3282]
224+
]],
225+
[[
226+
[141.7005, -81.3282],
227+
[180.0, -81.3282],
228+
[180.0, 81.3282],
229+
[141.7005, 81.3282],
230+
[141.7005, -81.3282]
231+
]]
232+
]
233+
result.spatialBounding.coordinates == expectedCoordinates
234+
result.spatialBounding.type == MultiPolygonType.MultiPolygon
235+
!result.isGlobal
236+
}
237+
204238
def "Spatial bounding is correctly parsed when it contains zeros"() {
205239

206240
given:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<gmi:MI_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gmi="http://www.isotc211.org/2005/gmi" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.isotc211.org/2005/gmi">
4+
<gmd:identificationInfo>
5+
<gmd:MD_DataIdentification>
6+
<gmd:extent>
7+
<gmd:EX_Extent id="boundingExtent">
8+
<gmd:geographicElement>
9+
<gmd:EX_GeographicBoundingBox id="boundingGeographicBoundingBox">
10+
<gmd:westBoundLongitude>
11+
<gco:Decimal>141.7005</gco:Decimal>
12+
</gmd:westBoundLongitude>
13+
<gmd:eastBoundLongitude>
14+
<gco:Decimal>6.2995</gco:Decimal>
15+
</gmd:eastBoundLongitude>
16+
<gmd:southBoundLatitude>
17+
<gco:Decimal>-81.3282</gco:Decimal>
18+
</gmd:southBoundLatitude>
19+
<gmd:northBoundLatitude>
20+
<gco:Decimal>81.3282</gco:Decimal>
21+
</gmd:northBoundLatitude>
22+
</gmd:EX_GeographicBoundingBox>
23+
</gmd:geographicElement>
24+
</gmd:EX_Extent>
25+
</gmd:extent>
26+
<gmd:supplementalInformation gco:nilReason="missing"/>
27+
</gmd:MD_DataIdentification>
28+
</gmd:identificationInfo>
29+
</gmi:MI_Metadata>

0 commit comments

Comments
 (0)