Skip to content

Commit d21a93a

Browse files
committed
spatial bbox fix
formatting add single array methods
1 parent d33c91a commit d21a93a

File tree

3 files changed

+174
-23
lines changed

3 files changed

+174
-23
lines changed

src/main/java/mil/nga/oapi/features/json/Spatial.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ public class Spatial extends FeaturesObject {
1919
private static final long serialVersionUID = 1L;
2020

2121
/**
22-
* West, south, east, north edges of the bounding box. The coordinates are
23-
* in the coordinate reference system specified in `crs`. By default this is
24-
* WGS 84 longitude/latitude.
22+
* One or more bounding boxes that describe the spatial extent of the
23+
* dataset. In the Core only a single bounding box is supported. Extensions
24+
* may support additional areas. If multiple areas are provided, the union
25+
* of the bounding boxes describes the spatial extent.
2526
*/
26-
private List<Double> bbox = new ArrayList<>();
27+
private List<List<Double>> bbox = new ArrayList<>();
2728

2829
/**
2930
* Coordinate reference system of the coordinates in the spatial extent
@@ -46,7 +47,7 @@ public Spatial() {
4647
*
4748
* @return bounding box
4849
*/
49-
public List<Double> getBbox() {
50+
public List<List<Double>> getBbox() {
5051
return bbox;
5152
}
5253

@@ -56,10 +57,20 @@ public List<Double> getBbox() {
5657
* @param bbox
5758
* bounding box
5859
*/
59-
public void setBbox(List<Double> bbox) {
60+
public void setBbox(List<List<Double>> bbox) {
6061
this.bbox = bbox;
6162
}
6263

64+
/**
65+
* Add a bounding box
66+
*
67+
* @param bbox
68+
* single bounding box
69+
*/
70+
public void addBbox(List<Double> bbox) {
71+
this.bbox.add(bbox);
72+
}
73+
6374
/**
6475
* Get the coordinate reference system
6576
*

src/main/java/mil/nga/oapi/features/json/Temporal.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
public class Temporal {
1515

1616
/**
17-
* One or more time intervals that describe the temporal extent of the dataset.
18-
* The value `null` is supported and indicates an unbounded interval end.
19-
* In the Core only a single time interval is supported. Extensions may support
20-
* multiple intervals. If multiple intervals are provided, the union of the
21-
* intervals describes the temporal extent.
17+
* One or more time intervals that describe the temporal extent of the
18+
* dataset. The value `null` is supported and indicates an unbounded
19+
* interval end. In the Core only a single time interval is supported.
20+
* Extensions may support multiple intervals. If multiple intervals are
21+
* provided, the union of the intervals describes the temporal extent.
2222
*/
23-
private List<List<String>> interval = new ArrayList<>(new ArrayList<>());
23+
private List<List<String>> interval = new ArrayList<>();
2424

2525
/**
2626
* Coordinate reference system of the coordinates in the temporal extent
@@ -57,6 +57,16 @@ public void setInterval(List<List<String>> interval) {
5757
this.interval = interval;
5858
}
5959

60+
/**
61+
* Add an interval
62+
*
63+
* @param interval
64+
* single interval
65+
*/
66+
public void addInterval(List<String> interval) {
67+
this.interval.add(interval);
68+
}
69+
6070
/**
6171
* Get the Temporal reference system
6272
*

src/test/java/mil/nga/oapi/features/json/FeaturesTest.java

Lines changed: 141 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void testCollections() {
5454
+ " \"collections\" : [ {\n"
5555
+ " \"name\" : \"flurstueck\",\n"
5656
+ " \"title\" : \"Flurstück\",\n" + " \"extent\" : {\n"
57-
+ " \"spatial\" : { \"bbox\" : [ 5.61272621360749, 50.2373512077239, 9.58963433710139, 52.5286304537795 ] },\n"
57+
+ " \"spatial\" : { \"bbox\" : [[ 5.61272621360749, 50.2373512077239, 9.58963433710139, 52.5286304537795 ]] },\n"
5858
+ " \"temporal\" : { \"interval\" : [[ \"2018-05-18T14:45:44Z\", \"2019-06-17T21:41:19Z\" ]] }\n"
5959
+ " },\n" + " \"links\" : [ {\n"
6060
+ " \"rel\" : \"item\",\n"
@@ -90,7 +90,7 @@ public void testCollections() {
9090
+ " \"name\" : \"gebaeudebauwerk\",\n"
9191
+ " \"title\" : \"Gebäude, Bauwerk\",\n"
9292
+ " \"extent\" : {\n"
93-
+ " \"spatial\" : { \"bbox\" : [ 5.61272621360749, 50.2373512077239, 9.58963433710139, 52.5286304537795 ] },\n"
93+
+ " \"spatial\" : { \"bbox\" : [[ 5.61272621360749, 50.2373512077239, 9.58963433710139, 52.5286304537795 ]] },\n"
9494
+ " \"temporal\" : { \"interval\" : [[ \"2018-05-18T14:45:44Z\", \"2019-06-17T21:41:19Z\" ]] }\n"
9595
+ " },\n" + " \"links\" : [ {\n"
9696
+ " \"rel\" : \"item\",\n"
@@ -122,7 +122,7 @@ public void testCollections() {
122122
+ " }, {\n" + " \"name\" : \"verwaltungseinheit\",\n"
123123
+ " \"title\" : \"Verwaltungseinheit\",\n"
124124
+ " \"extent\" : {\n"
125-
+ " \"spatial\" : { \"bbox\" : [ 5.61272621360749, 50.2373512077239, 9.58963433710139, 52.5286304537795 ] },\n"
125+
+ " \"spatial\" : { \"bbox\" : [[ 5.61272621360749, 50.2373512077239, 9.58963433710139, 52.5286304537795 ]] },\n"
126126
+ " \"temporal\" : { \"interval\" : [[ \"2018-05-18T14:45:44Z\", \"2019-06-17T21:41:19Z\" ]] }\n"
127127
+ " },\n" + " \"links\" : [ {\n"
128128
+ " \"rel\" : \"item\",\n"
@@ -161,6 +161,130 @@ public void testCollections() {
161161

162162
}
163163

164+
/**
165+
* Test collections
166+
*/
167+
@Test
168+
public void testCollections2() {
169+
170+
String content = "{\"links\": ["
171+
+ "{ \"href\": \"http://data.example.org/collections.json\","
172+
+ "\"rel\": \"self\", \"type\": \"application/json\", \"title\": \"this document\" },"
173+
+ "{ \"href\": \"http://data.example.org/collections.html\","
174+
+ "\"rel\": \"alternate\", \"type\": \"text/html\", \"title\": \"this document as HTML\" },"
175+
+ "{ \"href\": \"http://schemas.example.org/1.0/buildings.xsd\","
176+
+ "\"rel\": \"describedby\", \"type\": \"application/xml\", \"title\": \"GML application schema for Acme Corporation building data\" },"
177+
+ "{ \"href\": \"http://download.example.org/buildings.gpkg\","
178+
+ "\"rel\": \"enclosure\", \"type\": \"application/geopackage+sqlite3\", \"title\": \"Bulk download (GeoPackage)\", \"length\": 472546 }"
179+
+ "]," + "\"collections\": [" + "{" + "\"id\": \"buildings\","
180+
+ "\"title\": \"Buildings\","
181+
+ "\"description\": \"Buildings in the city of Bonn.\","
182+
+ "\"extent\": {" + "\"spatial\": {"
183+
+ "\"bbox\": [ [ 7.01, 50.63, 7.22, 50.78 ] ]" + "},"
184+
+ "\"temporal\": {"
185+
+ "\"interval\": [ [ \"2010-02-15T12:34:56Z\", null ] ]" + "}"
186+
+ "}," + "\"itemType\": \"feature\"," + "\"links\": ["
187+
+ "{ \"href\": \"http://data.example.org/collections/buildings\","
188+
+ "\"rel\": \"self\", \"title\": \"This collection\" },"
189+
+ "{ \"href\": \"http://data.example.org/collections/buildings/items\","
190+
+ "\"rel\": \"items\", \"type\": \"application/geo+json\","
191+
+ "\"title\": \"Buildings\" },"
192+
+ "{ \"href\": \"https://creativecommons.org/publicdomain/zero/1.0/\","
193+
+ "\"rel\": \"license\", \"type\": \"text/html\","
194+
+ "\"title\": \"CC0-1.0\" },"
195+
+ "{ \"href\": \"https://creativecommons.org/publicdomain/zero/1.0/rdf\","
196+
+ "\"rel\": \"license\", \"type\": \"application/rdf+xml\","
197+
+ "\"title\": \"CC0-1.0\" }" + "]" + "}" + "]" + "}";
198+
Collections collections = FeaturesConverter.toCollections(content);
199+
TestCase.assertNotNull(collections);
200+
List<Link> links = collections.getLinks();
201+
TestCase.assertNotNull(links);
202+
TestCase.assertEquals(4, links.size());
203+
TestCase.assertEquals("http://data.example.org/collections.json",
204+
links.get(0).getHref());
205+
TestCase.assertEquals("self", links.get(0).getRel());
206+
TestCase.assertEquals("application/json", links.get(0).getType());
207+
TestCase.assertEquals("this document", links.get(0).getTitle());
208+
TestCase.assertEquals("http://data.example.org/collections.html",
209+
links.get(1).getHref());
210+
TestCase.assertEquals("alternate", links.get(1).getRel());
211+
TestCase.assertEquals("text/html", links.get(1).getType());
212+
TestCase.assertEquals("this document as HTML", links.get(1).getTitle());
213+
TestCase.assertEquals("http://schemas.example.org/1.0/buildings.xsd",
214+
links.get(2).getHref());
215+
TestCase.assertEquals("describedby", links.get(2).getRel());
216+
TestCase.assertEquals("application/xml", links.get(2).getType());
217+
TestCase.assertEquals(
218+
"GML application schema for Acme Corporation building data",
219+
links.get(2).getTitle());
220+
TestCase.assertEquals("http://download.example.org/buildings.gpkg",
221+
links.get(3).getHref());
222+
TestCase.assertEquals("enclosure", links.get(3).getRel());
223+
TestCase.assertEquals("application/geopackage+sqlite3",
224+
links.get(3).getType());
225+
TestCase.assertEquals("Bulk download (GeoPackage)",
226+
links.get(3).getTitle());
227+
TestCase.assertEquals(472546, links.get(3).getLength().intValue());
228+
TestCase.assertEquals(1, collections.getCollections().size());
229+
Collection collection = collections.getCollections().get(0);
230+
TestCase.assertEquals("buildings", collection.getId());
231+
TestCase.assertEquals("Buildings", collection.getTitle());
232+
TestCase.assertEquals("Buildings in the city of Bonn.",
233+
collection.getDescription());
234+
Extent extent = collection.getExtent();
235+
TestCase.assertNotNull(extent);
236+
TestCase.assertEquals(1, extent.getSpatial().getBbox().size());
237+
TestCase.assertEquals(4, extent.getSpatial().getBbox().get(0).size());
238+
TestCase.assertEquals(7.01,
239+
extent.getSpatial().getBbox().get(0).get(0));
240+
TestCase.assertEquals(50.63,
241+
extent.getSpatial().getBbox().get(0).get(1));
242+
TestCase.assertEquals(7.22,
243+
extent.getSpatial().getBbox().get(0).get(2));
244+
TestCase.assertEquals(50.78,
245+
extent.getSpatial().getBbox().get(0).get(3));
246+
TestCase.assertEquals(1, extent.getTemporal().getInterval().size());
247+
TestCase.assertEquals(2,
248+
extent.getTemporal().getInterval().get(0).size());
249+
TestCase.assertEquals("2010-02-15T12:34:56Z",
250+
extent.getTemporal().getInterval().get(0).get(0));
251+
TestCase.assertNull(extent.getTemporal().getInterval().get(0).get(1));
252+
TestCase.assertEquals("feature", collection.getItemType());
253+
List<Link> collectionLinks = collection.getLinks();
254+
TestCase.assertNotNull(collectionLinks);
255+
TestCase.assertEquals(4, collectionLinks.size());
256+
TestCase.assertEquals("http://data.example.org/collections/buildings",
257+
collectionLinks.get(0).getHref());
258+
TestCase.assertEquals("self", collectionLinks.get(0).getRel());
259+
TestCase.assertEquals("This collection",
260+
collectionLinks.get(0).getTitle());
261+
TestCase.assertEquals(
262+
"http://data.example.org/collections/buildings/items",
263+
collectionLinks.get(1).getHref());
264+
TestCase.assertEquals("items", collectionLinks.get(1).getRel());
265+
TestCase.assertEquals("application/geo+json",
266+
collectionLinks.get(1).getType());
267+
TestCase.assertEquals("Buildings", collectionLinks.get(1).getTitle());
268+
TestCase.assertEquals(
269+
"https://creativecommons.org/publicdomain/zero/1.0/",
270+
collectionLinks.get(2).getHref());
271+
TestCase.assertEquals("license", collectionLinks.get(2).getRel());
272+
TestCase.assertEquals("text/html", collectionLinks.get(2).getType());
273+
TestCase.assertEquals("CC0-1.0", collectionLinks.get(2).getTitle());
274+
TestCase.assertEquals(
275+
"https://creativecommons.org/publicdomain/zero/1.0/rdf",
276+
collectionLinks.get(3).getHref());
277+
TestCase.assertEquals("license", collectionLinks.get(3).getRel());
278+
TestCase.assertEquals("application/rdf+xml",
279+
collectionLinks.get(3).getType());
280+
TestCase.assertEquals("CC0-1.0", collectionLinks.get(3).getTitle());
281+
282+
content = FeaturesConverter.toStringValue(collections);
283+
TestCase.assertNotNull(content);
284+
TestCase.assertNotNull(FeaturesConverter.toCollections(content));
285+
286+
}
287+
164288
/**
165289
* Test a collection
166290
*/
@@ -171,7 +295,7 @@ public void testCollection() {
171295
+ " \"title\": \"Buildings\",\n"
172296
+ " \"description\": \"Buildings in the city of Bonn.\",\n"
173297
+ " \"extent\": {\n"
174-
+ " \"spatial\": { \"bbox\" : [ 7.01, 50.63, 7.22, 50.78 ] },\n"
298+
+ " \"spatial\": { \"bbox\" : [[ 7.01, 50.63, 7.22, 50.78 ]] },\n"
175299
+ " \"temporal\": { \"interval\" : [[ \"2010-02-15T12:34:56Z\", \"2018-03-18T12:11:00Z\" ]] }\n"
176300
+ " },\n" + " \"links\": [\n"
177301
+ " { \"href\": \"http://data.example.org/collections/buildings/items\",\n"
@@ -189,19 +313,25 @@ public void testCollection() {
189313
collection.getDescription());
190314
Extent extent = collection.getExtent();
191315
TestCase.assertNotNull(extent);
192-
TestCase.assertEquals(4, extent.getSpatial().getBbox().size());
193-
TestCase.assertEquals(7.01, extent.getSpatial().getBbox().get(0));
194-
TestCase.assertEquals(50.63, extent.getSpatial().getBbox().get(1));
195-
TestCase.assertEquals(7.22, extent.getSpatial().getBbox().get(2));
196-
TestCase.assertEquals(50.78, extent.getSpatial().getBbox().get(3));
316+
TestCase.assertEquals(1, extent.getSpatial().getBbox().size());
317+
TestCase.assertEquals(4, extent.getSpatial().getBbox().get(0).size());
318+
TestCase.assertEquals(7.01,
319+
extent.getSpatial().getBbox().get(0).get(0));
320+
TestCase.assertEquals(50.63,
321+
extent.getSpatial().getBbox().get(0).get(1));
322+
TestCase.assertEquals(7.22,
323+
extent.getSpatial().getBbox().get(0).get(2));
324+
TestCase.assertEquals(50.78,
325+
extent.getSpatial().getBbox().get(0).get(3));
197326
TestCase.assertEquals(1, extent.getTemporal().getInterval().size());
198-
TestCase.assertEquals(2, extent.getTemporal().getInterval().get(0).size());
327+
TestCase.assertEquals(2,
328+
extent.getTemporal().getInterval().get(0).size());
199329
TestCase.assertEquals("2010-02-15T12:34:56Z",
200330
extent.getTemporal().getInterval().get(0).get(0));
201331
TestCase.assertEquals("2018-03-18T12:11:00Z",
202332
extent.getTemporal().getInterval().get(0).get(1));
203333
List<Link> links = collection.getLinks();
204-
TestCase.assertNotNull(extent);
334+
TestCase.assertNotNull(links);
205335
TestCase.assertEquals(2, links.size());
206336
TestCase.assertEquals(
207337
"http://data.example.org/collections/buildings/items",

0 commit comments

Comments
 (0)