Skip to content

Commit

Permalink
Paumas implement dont clip flag (#593)
Browse files Browse the repository at this point in the history
* implement dont_clip configuration option. closes #562.
  • Loading branch information
ARolek committed Apr 9, 2019
1 parent 564665b commit 7f1d938
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ name = "zoning" # used in the URL to reference this
# It can also be used to group multiple ProviderLayers under the same namespace.
provider_layer = "test_postgis.rivers" # must match a data provider layer
dont_simplify = true # optionally, turn off simplification for this layer. Default is false.
dont_clip = true # optionally, turn off clipping for this layer. Default is false.
min_zoom = 10 # minimum zoom level to include this layer
max_zoom = 18 # maximum zoom level to include this layer
```
Expand Down
3 changes: 3 additions & 0 deletions atlas/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type Layer struct {
// DontSimplify indicates wheather feature simplification should be applied.
// We use a negative in the name so the default is to simplify
DontSimplify bool
// DontClip indicates wheather feature clipping should be applied.
// We use a negative in the name so the default is to clip
DontClip bool
}

// MVTName will return the value that will be encoded in the Name field when the layer is encoded as MVT
Expand Down
1 change: 1 addition & 0 deletions atlas/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (m Map) Encode(ctx context.Context, tile *slippy.Tile) ([]byte, error) {
mvtLayer := mvt.Layer{
Name: l.MVTName(),
DontSimplify: l.DontSimplify,
DontClip: l.DontClip,
}

// on completion let the wait group know
Expand Down
1 change: 1 addition & 0 deletions cmd/internal/register/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func Maps(a *atlas.Atlas, maps []config.Map, providers map[string]provider.Tiler
DefaultTags: defaultTags,
GeomType: layerGeomType,
DontSimplify: bool(l.DontSimplify),
DontClip: bool(l.DontClip),
})
}

Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type MapLayer struct {
// DontSimplify indicates wheather feature simplification should be applied.
// We use a negative in the name so the default is to simplify
DontSimplify env.Bool `toml:"dont_simplify"`
// DontClip indicates wheather feature clipping should be applied.
// We use a negative in the name so the default is to clipping
DontClip env.Bool `toml:"dont_clip"`
}

// GetName helper to get the name we care about.
Expand Down
4 changes: 3 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func TestParse(t *testing.T) {
provider_layer = "provider1.water"
min_zoom = 10
max_zoom = 20
dont_simplify = true`,
dont_simplify = true
dont_clip = true`,
expected: config.Config{
TileBuffer: env.IntPtr(env.Int(12)),
LocationName: "",
Expand Down Expand Up @@ -180,6 +181,7 @@ func TestParse(t *testing.T) {
MinZoom: env.UintPtr(10),
MaxZoom: env.UintPtr(20),
DontSimplify: true,
DontClip: true,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions maths/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func scaleMultiPolygon(p tegola.MultiPolygon, factor float64) (bmp basic.MultiPo
return bmp
}

// CleanGeometry will apply various geoprocessing algorithems to the provided geometry.
// the extent will be used as a clipping region. if no clipping is desired, pass in a nil extent.
func CleanGeometry(ctx context.Context, g tegola.Geometry, extent *geom.Extent) (geo tegola.Geometry, err error) {
if g == nil {
return nil, nil
Expand Down
15 changes: 10 additions & 5 deletions mvt/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/go-spatial/tegola/maths"
"github.com/go-spatial/tegola/maths/points"
"github.com/go-spatial/tegola/maths/validate"
"github.com/go-spatial/tegola/mvt/vector_tile"
vectorTile "github.com/go-spatial/tegola/mvt/vector_tile"
)

// errors
Expand Down Expand Up @@ -87,15 +87,15 @@ func NewFeatures(geo tegola.Geometry, tags map[string]interface{}) (f []Feature)
}

// VTileFeature will return a vectorTile.Feature that would represent the Feature
func (f *Feature) VTileFeature(ctx context.Context, keys []string, vals []interface{}, tile *tegola.Tile, simplify bool) (tf *vectorTile.Tile_Feature, err error) {
func (f *Feature) VTileFeature(ctx context.Context, keys []string, vals []interface{}, tile *tegola.Tile, simplify bool, clip bool) (tf *vectorTile.Tile_Feature, err error) {
tf = new(vectorTile.Tile_Feature)
tf.Id = f.ID

if tf.Tags, err = keyvalTagsMap(keys, vals, f); err != nil {
return tf, err
}

geo, gtype, err := encodeGeometry(ctx, f.Geometry, tile, simplify)
geo, gtype, err := encodeGeometry(ctx, f.Geometry, tile, simplify, clip)
if err != nil {
return tf, err
}
Expand Down Expand Up @@ -570,7 +570,7 @@ func (c *cursor) ClosePath() uint32 {

// encodeGeometry will take a tegola.Geometry type and encode it according to the
// mapbox vector_tile spec.
func encodeGeometry(ctx context.Context, geometry tegola.Geometry, tile *tegola.Tile, simplify bool) (g []uint32, vtyp vectorTile.Tile_GeomType, err error) {
func encodeGeometry(ctx context.Context, geometry tegola.Geometry, tile *tegola.Tile, simplify bool, clip bool) (g []uint32, vtyp vectorTile.Tile_GeomType, err error) {

if geometry == nil {
return nil, vectorTile.Tile_UNKNOWN, ErrNilGeometryType
Expand All @@ -592,7 +592,12 @@ func encodeGeometry(ctx context.Context, geometry tegola.Geometry, tile *tegola.
if err != nil {
return nil, vectorTile.Tile_UNKNOWN, err
}
ext := geom.NewExtent([2]float64{pbb[0], pbb[1]}, [2]float64{pbb[2], pbb[3]})

// check if we need to clip and if we do build the extent
var ext *geom.Extent
if clip {
ext = geom.NewExtent([2]float64{pbb[0], pbb[1]}, [2]float64{pbb[2], pbb[3]})
}

geometry, err = validate.CleanGeometry(ctx, sg, ext)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion mvt/feature_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestEncodeGeometry(t *testing.T) {

fn := func(tc tcase) func(t *testing.T) {
return func(t *testing.T) {
g, gtype, err := encodeGeometry(context.Background(), tc.geo, tile, true)
g, gtype, err := encodeGeometry(context.Background(), tc.geo, tile, true, true)
if tc.eerr != err {
t.Errorf("error, expected %v got %v", tc.eerr, err)
}
Expand Down
4 changes: 3 additions & 1 deletion mvt/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Layer struct {
DontSimplify bool
// MaxSimplificationZoom is the zoom level at which point simplification is turned off. if value is zero Max is set to 14. If you do not want to simplify at any level set DontSimplify to true.
MaxSimplificationZoom uint
// DontClip truns off clipping for this layer.
DontClip bool
}

func valMapToVTileValue(valMap []interface{}) (vt []*vectorTile.Tile_Value) {
Expand Down Expand Up @@ -84,7 +86,7 @@ func (l *Layer) VTileLayer(ctx context.Context, tile *tegola.Tile) (*vectorTile.

simplify = simplify && tile.Z < l.MaxSimplificationZoom

vtf, err := f.VTileFeature(ctx, kmap, vmap, tile, simplify)
vtf, err := f.VTileFeature(ctx, kmap, vmap, tile, simplify, !l.DontClip)
if err != nil {
switch err {
case context.Canceled:
Expand Down

0 comments on commit 7f1d938

Please sign in to comment.