Skip to content

Commit 4ec4eb1

Browse files
authored
Merge pull request #47 from ossimlabs/MAIN-45
Adding a few fixes to cut down on memory usage when rendering footprints
2 parents d015e90 + 055a38e commit 4ec4eb1

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
buildVersion=1.2.7
1+
buildVersion=1.2.8
22

33
ossimMavenProxy=https://nexus.ossim.io/nexus/content/repositories/all-repos
44

plugins/omar-geoscript-plugin/grails-app/services/omar/geoscript/FootprintService.groovy

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,31 @@ import javax.imageio.ImageIO
1717

1818
import org.springframework.util.FastByteArrayOutputStream
1919

20+
import groovy.transform.Memoized
2021
@Transactional(readOnly=true)
2122
class FootprintService
2223
{
2324
def grailsApplication
2425
def geoscriptService
2526

26-
def getFootprints(GetFootprintsRequest params)
27-
{
28-
byte[] buffer = []
29-
def (prefix, layerName) = params.layers.split( ':' )
27+
static final int INITIAL_SIZE = 8196
28+
static final TransparentGif transparentGif = new TransparentGif()
3029

30+
@Memoized
31+
private def createStyle(String styleName)
32+
{
3133
// Retrieve the styles for this configuration
3234
def styles = grailsApplication.config.wms.styles
3335
// Store all the style map's keys as a list
3436
def styleKeys = styles.keySet() as List
3537

36-
def layerInfo = LayerInfo.where {
37-
name == layerName && workspaceInfo.namespaceInfo.prefix == prefix
38-
}.get()
39-
40-
Workspace.withWorkspace( geoscriptService.getWorkspace( layerInfo.workspaceInfo.workspaceParams ) ) { workspace ->
41-
4238
// Attempt to retrieve the requested style from our styles map
43-
def outlineLookupTable = styles[params.styles]
39+
def outlineLookupTable = styles[styleName]
4440

4541
// If the requested style doesn't exist in this map, then use the first style
4642
// we do have. A size of zero, indicates there are no elements to this style.
4743
if (outlineLookupTable.size() == 0) {
48-
println "WARNING: Style '${params.styles}' does not exist on this instance. " +
44+
println "WARNING: Style '${styleName}' does not exist on this instance. " +
4945
"Defaulting to first available style '${styleKeys.first()}'."
5046
outlineLookupTable = styles[styleKeys.first()]
5147
}
@@ -61,7 +57,23 @@ class FootprintService
6157

6258
style << ( stroke( color: '#000000' ) + fill( opacity: 0.0 ) ).where( "not (${allFilters})" )
6359

64-
def footprints = new QueryLayer( workspace[layerName], style as Composite )
60+
style as Composite
61+
}
62+
63+
def getFootprints(GetFootprintsRequest params)
64+
{
65+
byte[] buffer = []
66+
def (prefix, layerName) = params.layers.split( ':' )
67+
68+
def layerInfo = LayerInfo.where {
69+
name == layerName && workspaceInfo.namespaceInfo.prefix == prefix
70+
}.get()
71+
72+
Workspace.withWorkspace( geoscriptService.getWorkspace( layerInfo.workspaceInfo.workspaceParams ) ) { workspace ->
73+
74+
def style = createStyle(params.styles)
75+
76+
def footprints = new QueryLayer( workspace[layerName], style )
6577
def viewBbox = new Bounds( *( params.bbox.split( ',' )*.toDouble() ), params.srs )
6678
def geomField = workspace[layerName].schema.geom
6779
def queryBbox
@@ -114,16 +126,14 @@ class FootprintService
114126
)
115127

116128
if ( map?.type?.equalsIgnoreCase('gif') ) {
117-
map.@renderers['gif'] = new TransparentGif()
129+
map.@renderers['gif'] = transparentGif
118130
}
119131

120132
def image = map.renderToImage()
121133

122134
map.close()
123135

124-
def ostream = new FastByteArrayOutputStream(
125-
(image.sampleModel.sampleSize.sum() / 8 * image.width * image.height).intValue()
126-
)
136+
def ostream = new FastByteArrayOutputStream(INITIAL_SIZE)
127137

128138
ImageIO.write(image, map.type, ostream)
129139
buffer = ostream.toByteArrayUnsafe()

0 commit comments

Comments
 (0)