Skip to content

Commit 4ce5a9e

Browse files
committed
Restructured code to incorporate shared base
1 parent 549f8df commit 4ce5a9e

File tree

1 file changed

+57
-49
lines changed
  • internal/controller/mapfilegenerator

1 file changed

+57
-49
lines changed

internal/controller/mapfilegenerator/mapper.go

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -133,62 +133,70 @@ func MapWMSToMapfileGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoperatorv
133133

134134
allLayers := wms.Spec.Service.GetAllLayers()
135135
for _, serviceLayer := range allLayers[1:] {
136-
layerExtent := extent
137-
if len(serviceLayer.BoundingBoxes) > 0 {
138-
layerExtent = serviceLayer.BoundingBoxes[0].ToExtent()
139-
}
136+
layer := getWMSLayer(serviceLayer, extent, wms)
137+
result.Layers = append(result.Layers, layer)
138+
}
139+
return result, nil
140+
}
140141

141-
layer := WMSLayer{
142-
BaseLayer: BaseLayer{
143-
Name: serviceLayer.Name,
144-
Title: smoothoperatorutils.PointerVal(serviceLayer.Title, ""),
145-
Abstract: smoothoperatorutils.PointerVal(serviceLayer.Abstract, ""),
146-
Keywords: strings.Join(serviceLayer.Keywords, ","),
147-
Extent: layerExtent,
148-
MetadataId: serviceLayer.DatasetMetadataURL.CSW.MetadataIdentifier,
149-
Columns: []Column{},
150-
GeometryType: nil,
151-
GeopackagePath: nil,
152-
TableName: nil,
153-
Postgis: nil,
154-
},
155-
GroupName: "",
156-
Styles: []Style{},
157-
Offsite: "",
158-
GetFeatureInfoIncludesClass: false,
159-
}
142+
func getWMSLayer(serviceLayer pdoknlv3.Layer, serviceExtent string, wms *pdoknlv3.WMS) WMSLayer {
143+
layerExtent := serviceExtent
144+
if len(serviceLayer.BoundingBoxes) > 0 {
145+
layerExtent = serviceLayer.BoundingBoxes[0].ToExtent()
146+
}
160147

161-
for _, style := range serviceLayer.Styles {
162-
stylePath := "/styling/" + smoothoperatorutils.PointerVal(style.Visualization, "")
163-
layer.Styles = append(layer.Styles, Style{
164-
Path: stylePath,
165-
Title: smoothoperatorutils.PointerVal(style.Title, ""),
166-
})
167-
}
148+
result := WMSLayer{
149+
BaseLayer: BaseLayer{
150+
Name: serviceLayer.Name,
151+
Title: smoothoperatorutils.PointerVal(serviceLayer.Title, ""),
152+
Abstract: smoothoperatorutils.PointerVal(serviceLayer.Abstract, ""),
153+
Keywords: strings.Join(serviceLayer.Keywords, ","),
154+
Extent: layerExtent,
155+
MetadataId: serviceLayer.DatasetMetadataURL.CSW.MetadataIdentifier,
156+
Columns: getColumns(*serviceLayer.Data),
157+
GeometryType: nil,
158+
GeopackagePath: nil,
159+
TableName: serviceLayer.Data.GetTableName(),
160+
Postgis: nil,
161+
},
162+
GroupName: "",
163+
Styles: []Style{},
164+
Offsite: "",
165+
GetFeatureInfoIncludesClass: false,
166+
}
168167

169-
if serviceLayer.Data != nil && serviceLayer.Data.Gpkg != nil {
170-
gpkg := serviceLayer.Data.Gpkg
168+
for _, style := range serviceLayer.Styles {
169+
stylePath := "/styling/" + smoothoperatorutils.PointerVal(style.Visualization, "")
170+
result.Styles = append(result.Styles, Style{
171+
Path: stylePath,
172+
Title: smoothoperatorutils.PointerVal(style.Title, ""),
173+
})
174+
}
171175

172-
layer.Columns = append(layer.Columns, Column{
173-
Name: "fuuid",
174-
Alias: nil,
175-
})
176+
if serviceLayer.Data != nil {
177+
if serviceLayer.Data.Gpkg != nil {
178+
gpkg := serviceLayer.Data.Gpkg
176179

177-
for _, column := range serviceLayer.Data.Gpkg.Columns {
178-
layer.Columns = append(layer.Columns, Column{
179-
Name: column.Name,
180-
Alias: column.Alias,
181-
})
180+
result.GeometryType = &gpkg.GeometryType
181+
geopackageConstructedPath := ""
182+
if smoothoperatorutils.PointerVal(wms.Options().PrefetchData, true) {
183+
splitBlobKey := strings.Split(gpkg.BlobKey, "/")
184+
geopackageConstructedPath = "/srv/data/gpkg/" + splitBlobKey[len(splitBlobKey)-1]
185+
} else {
186+
geopackageConstructedPath = "/vsiaz/geopackages/" + gpkg.BlobKey
182187
}
183188

184-
layer.GeometryType = &gpkg.GeometryType
185-
splitBlobKey := strings.Split(gpkg.BlobKey, "/")
186-
geopackageConstructedPath := "/srv/data/gpkg/" + splitBlobKey[len(splitBlobKey)-1]
187-
layer.GeopackagePath = &geopackageConstructedPath
188-
layer.TableName = &gpkg.TableName
189-
}
189+
result.GeopackagePath = &geopackageConstructedPath
190+
} else if serviceLayer.Data.TIF != nil {
191+
tif := serviceLayer.Data.TIF
192+
result.GeometryType = smoothoperatorutils.Pointer("Raster")
193+
_ = tif
190194

191-
result.Layers = append(result.Layers, layer)
195+
} else if serviceLayer.Data.Postgis != nil {
196+
postgis := serviceLayer.Data.Postgis
197+
_ = postgis
198+
}
192199
}
193-
return result, nil
200+
201+
return result
194202
}

0 commit comments

Comments
 (0)