-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
182 lines (158 loc) · 6.06 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import groovy.io.FileType
def json = new groovy.json.JsonSlurper()
def config = json.parse(file(project.hasProperty('configFile') ? project.getProperty('configFile') : 'config.json'))
def dataDir = project.file('data')
task('generate-tileindex') {
description "Generate tile index Shapefiles for all available layers"
group 'Mapserver'
doLast {
dataDir.eachFileRecurse(FileType.DIRECTORIES) { dir ->
exec {
println "Generating tile index in ${dir.absolutePath}"
workingDir dir.parent
commandLine 'bash', '-c', "gdaltindex ${dir.name}.shp ${dir.name}/*.tif"
}
}
}
}
task('generate-mapfile') {
description "Generate a MAP file based on the configuration and the data"
group 'Mapserver'
doLast {
def debugLevel = project.hasProperty('debugLevel') ? project.getProperty('debugLevel') : 5
def globalCrs = config.globalEpsg
def mapFile = project.file(project.hasProperty('targetMapFile') ? project.getProperty('targetMapFile') : 'etc/mapserver.map')
mapFile.text = """
MAP
CONFIG "MS_ERRORFILE" "/tmp/ms_error.txt"
DEBUG $debugLevel
# all temp files get prefixed with this string
NAME mapserv
# background color of image if transparency (is not requested)
IMAGECOLOR 255 255 255
# default output image dimensions
SIZE 100000 100000
# always returns a map
STATUS ON
# set top level projection
PROJECTION
"init=epsg:$globalCrs"
END
EXTENT $config.globalExtent
"""
config.outputFormats.each { name, settings ->
mapFile.text += """
OUTPUTFORMAT
NAME "$name"
DRIVER "$settings.driver"
MIMETYPE "$settings.mimetype"
IMAGEMODE "$settings.imagemode"
EXTENSION "$settings.extension"
END
"""
}
def svcMeta = config.serviceMetadata
def keywordList = svcMeta.keywords?.join(',')
def languages = svcMeta.languages?.join(',')
def org = svcMeta.contactOrganization
mapFile.text += """
WEB
METADATA
"wcs_enable_request" "*"
"ows_enable_request" "*"
"""
def embeddedMetadata = svcMeta.embeddedMetadata
def linkedMetadata = svcMeta.linkedMetadata
if (!!embeddedMetadata == !!linkedMetadata) {
throw new GradleScriptException('Error in config.json: specify exactly one of "embeddedMetadata" and "linkedMetadata"', null)
}
if (embeddedMetadata) {
mapFile.text += """
"wcs_inspire_capabilities" "embed"
"ows_inspire_temporal_reference" "$embeddedMetadata.lastRevisionDate"
"ows_inspire_mpoc_name" "$org.contactPerson"
"ows_inspire_mpoc_email" "$org.contactPersonEmail"
"ows_inspire_metadatadate" "$embeddedMetadata.metadataDate"
"ows_inspire_resourcelocator" "$embeddedMetadata.resourceLocator"
"ows_inspire_keyword" "infoCoverageAccessService"
"ows_inspire_dsid_ns" "$embeddedMetadata.datasetIdentifierNamespace"
"""
}
else {
mapFile.text += """
"wcs_inspire_capabilities" "url"
"ows_inspire_metadataurl_href" "$linkedMetadata.href"
"ows_inspire_metadataurl_format" "application/vnd.ogc.csw.capabilities.response_xml"
"""
}
mapFile.text += """
"ows_inspire_dsid_code" "$svcMeta.datasetIdentifierCode"
"ows_title" "${svcMeta.title?:''}"
"ows_abstract" "${svcMeta.wcs_abstract?:''}"
"ows_languages" "$languages"
"ows_keywordlist" "${keywordList?:''}"
"ows_contactorganization" "$org.name"
"ows_service_onlineresource" "${org.onlineResource?:''}"
"ows_contactperson" "${org.contactPerson?:''}"
"ows_contactelectronicmailaddress" "${org.contactPersonEmail?:''}"
"ows_contactvoicetelephone" "${org.contactPersonPhone?:''}"
"ows_contactfacsimiletelephone" "${org.contactPersonFax?:''}"
"ows_contactposition" "${org.contactPosition?:''}"
"ows_address" "${org.address?:''}"
"ows_city" "${org.city?:''}"
"ows_stateorprovince" "${org.stateOrProvince?:''}"
"ows_postcode" "${org.postalCode?:''}"
"ows_country" "${org.country?:''}"
"ows_fees" "${svcMeta.fees?:''}"
"wcs_accessconstraints" "${svcMeta.accessConstraints?:''}"
"ows_hoursofservice" "${org.hoursOfService?:''}"
"ows_contactinstructions" "${org.contactInstructions?:''}"
"ows_role" "${org.role?:''}"
END
END
"""
dataDir.eachFileRecurse(FileType.DIRECTORIES) { dir ->
def layerConfigFile = file("/$dir/layerconfig.json")
if (!layerConfigFile.exists()) {
throw new GradleScriptException("Missing layerconfig.json for layer ${dir.name}.", null)
}
def layerConfig = json.parse(layerConfigFile)
def tileIndex = file("/$dir/../${dir.name}.shp")
if (!tileIndex.exists()) {
throw new GradleScriptException("Did not find tile index for ${dir.name}. Did you run the generate-tileindex task?" as String, null)
}
def supportedSrs = layerConfig.supportedSrs.join(' ')
def outputFormats = layerConfig.outputFormats.join(' ')
mapFile.text += """
LAYER
NAME "$dir.name"
STATUS ON
TYPE RASTER
DUMP TRUE
TILEINDEX "/data/${dir.name}.shp"
TILEITEM "LOCATION"
PROJECTION
"init=epsg:$layerConfig.layerEpsg"
END
METADATA
"wcs:CoverageId" "$dir.name"
"wcs_enable_request" "GetCapabilities GetCoverage"
"wcs_label" "$layerConfig.label"
"ows_srs" "$supportedSrs"
"ows_extent" "$layerConfig.extent"
"wcs_resolution" "$layerConfig.resolution"
"wcs_bandcount" "$layerConfig.bandCount"
"wcs_formats" "$outputFormats"
"wcs_native_format" "$layerConfig.nativeFormat"
END
END
"""
}
mapFile.text += """
END
"""
}
}
wrapper {
gradleVersion = '6.0.1'
}