Permalink
Browse files

mapserver: support gdal raster datasources with processing parameters

  • Loading branch information...
olt committed Aug 22, 2017
1 parent 62fa58d commit b7152ce18dd3d0faa26f02573367d37e2d480f84
Showing with 47 additions and 11 deletions.
  1. +16 −2 builder/mapserver/mapfile.go
  2. +6 −5 mml/datasource.go
  3. +1 −0 mml/layer.go
  4. +24 −4 mml/mml.go
@@ -203,6 +203,8 @@ func (m *Map) AddLayer(layer mml.Layer, rules []mss.Rule) {
t = "POLYGON"
} else if layer.Type == mml.Point {
t = "POINT"
} else if layer.Type == mml.Raster {
t = "RASTER"
} else {
log.Println("unknown geometry type for layer", layer.ID)
return
@@ -313,7 +315,7 @@ func (m *Map) newClass(r mss.Rule, layerType string) (b *Block, styled bool) {
b.Add("Expression", filter)
}
prefixes := mss.SortedPrefixes(r.Properties, []string{"line-", "polygon-", "polygon-pattern-", "text-", "shield-", "marker-", "point-", "building-"})
prefixes := mss.SortedPrefixes(r.Properties, []string{"line-", "polygon-", "polygon-pattern-", "text-", "shield-", "marker-", "point-", "building-", "raster-"})
for _, p := range prefixes {
prefixStyled := false
@@ -342,6 +344,8 @@ func (m *Map) newClass(r mss.Rule, layerType string) (b *Block, styled bool) {
prefixStyled = m.addPointSymbolizer(b, r)
case "building-":
prefixStyled = m.addBuildingSymbolizer(b, r)
case "raster-":
prefixStyled = m.addRasterSymbolizer(b, r)
default:
log.Println("invalid prefix", p)
}
@@ -744,6 +748,10 @@ func (m *Map) addMarkerSymbolizer(b *Block, r mss.Rule, isLine bool) (styled boo
return false
}
func (m *Map) addRasterSymbolizer(b *Block, r mss.Rule) (styled bool) {
return true
}
var sanitizeFontName = regexp.MustCompile("[^-a-zA-Z0-9]")
var sanitizeSymbolName = regexp.MustCompile("[^-a-zA-Z0-9]")
@@ -986,7 +994,13 @@ func (m *Map) addDatasource(block *Block, ds mml.Datasource, rules []mss.Rule) {
}
block.Add("connectiontype", "ogr")
block.Add("", NewBlock("projection", Item{"", quote("init=epsg:" + ds.SRID)}))
case mml.GDAL:
fname := m.locator.Data(ds.Filename)
block.Add("data", quote(fname))
block.Add("", NewBlock("projection", Item{"", quote("init=epsg:" + ds.SRID)}))
for _, processing := range ds.Processing {
block.Add("processing", quote(processing))
}
// return []Parameter{
// // {Name: "file", Value: "/Users/olt/dev/osm_data/sqlites/" + ds.Filename},
// {Name: "file", Value: "/tmp/" + ds.Filename},
View
@@ -38,11 +38,12 @@ type OGR struct {
}
type GDAL struct {
Id string
Filename string
SRID string
Extent string
Band string
Id string
Filename string
SRID string
Extent string
Band string
Processing []string
}
type GeoJson struct {
View
@@ -7,6 +7,7 @@ const (
LineString GeometryType = "LineString"
Polygon GeometryType = "Polygon"
Point GeometryType = "Point"
Raster GeometryType = "Raster"
)
type Layer struct {
View
@@ -72,6 +72,8 @@ func parseGeometryType(t string) GeometryType {
return LineString
case "point":
return Point
case "raster":
return Raster
default:
return Unknown
}
@@ -122,11 +124,13 @@ func newDatasource(params map[string]interface{}) (Datasource, error) {
Extent: d["extent"],
}, nil
} else if d["type"] == "gdal" {
processing := asStrings(params["processing"])
return GDAL{
Filename: d["file"],
SRID: d["srid"],
Extent: d["extent"],
Band: d["band"],
Filename: d["file"],
SRID: d["srid"],
Extent: d["extent"],
Band: d["band"],
Processing: processing,
}, nil
} else if d["type"] == "geojson" {
return GeoJson{
@@ -139,6 +143,22 @@ func newDatasource(params map[string]interface{}) (Datasource, error) {
}
}
func asStrings(v interface{}) []string {
slice, ok := v.([]interface{})
if !ok {
return nil
}
var result []string
for i := range slice {
s, ok := slice[i].(string)
if !ok {
return nil
}
result = append(result, s)
}
return result
}
func Parse(r io.Reader) (*MML, error) {
aux := auxMML{}
input, err := ioutil.ReadAll(r)

0 comments on commit b7152ce

Please sign in to comment.