lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_spatial.rb in adiwg-mdtranslator-2.0.0rc10 vs lib/adiwg/mdtranslator/writers/sbJson/sections/sbJson_spatial.rb in adiwg-mdtranslator-2.0.0rc11
- old
+ new
@@ -10,41 +10,59 @@
module Spatial
def self.build(aExtents)
- spatial = {}
aBoxObjects = []
aExtents.each do |hExtent|
hExtent[:geographicExtents].each do |hGeoExtent|
- hBbox = hGeoExtent[:computedBbox]
- sw = [ hBbox[:westLongitude], hBbox[:southLatitude] ]
- nw = [ hBbox[:westLongitude], hBbox[:northLatitude] ]
- ne = [ hBbox[:eastLongitude], hBbox[:northLatitude] ]
- se = [ hBbox[:eastLongitude], hBbox[:southLatitude] ]
- aPoly = [ sw, nw, ne, se ]
- geoJson = {
- type: 'Polygon',
- coordinates: [
- aPoly
- ]
- }
- aBoxObjects << geoJson
+ # use computedBbox if exists
+ # ... this is always exists if geographic extent has objects
+ # otherwise use user provided boundingBox
+ hBbox = {}
+ if hGeoExtent[:computedBbox].empty?
+ unless hGeoExtent[:boundingBox].empty?
+ hBbox = hGeoExtent[:boundingBox]
+ end
+ else
+ hBbox = hGeoExtent[:computedBbox]
+ end
+
+ # turn the box into a polygon
+ unless hBbox.empty?
+ sw = [ hBbox[:westLongitude], hBbox[:southLatitude] ]
+ nw = [ hBbox[:westLongitude], hBbox[:northLatitude] ]
+ ne = [ hBbox[:eastLongitude], hBbox[:northLatitude] ]
+ se = [ hBbox[:eastLongitude], hBbox[:southLatitude] ]
+ aPoly = [ sw, nw, ne, se ]
+ geoJson = {
+ type: 'Polygon',
+ coordinates: [
+ aPoly
+ ]
+ }
+ aBoxObjects << geoJson
+ end
+
end
end
+ spatial = {}
+
unless aBoxObjects.empty?
hBox = AdiwgCoordinates.computeBbox(aBoxObjects)
sbBox = {}
+
+ # transform to sbJson bbox format
sbBox[:maxY] = hBox[:northLatitude]
sbBox[:minY] = hBox[:southLatitude]
sbBox[:maxX] = hBox[:eastLongitude]
sbBox[:minX] = hBox[:westLongitude]
spatial[:boundingBox] = sbBox
end
- # representational point is not computed
+ # sbJson representational point is not provided
spatial
end