Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions bbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ func (e *Extent) Clone() *Extent {

// Intersect will return a new extent that is the intersect of the two extents.
//
// +-------------------------+
// | |
// | A +----------+------+
// | |//////////| |
// | |/// C ////| |
// | |//////////| |
// +--------------+----------+ |
// | B |
// +-----------------+
// +-------------------------+
// | |
// | A +----------+------+
// | |//////////| |
// | |/// C ////| |
// | |//////////| |
// +--------------+----------+ |
// | B |
// +-----------------+
// For example the for the above Box A intersects Box B at the area surround by C.
//
// If the Boxes don't intersect does will be false, otherwise ibb will be the intersect.
Expand Down
15 changes: 9 additions & 6 deletions encoding/mvt/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"github.com/go-spatial/geom"
)

// PrepareGeo converts the geometry's coordinates to tile coordinates. tile should be the
// PrepareGeo converts the geometry's coordinates to tile pixel coordinates. tile should be the
// extent of the tile, in the same projection as geo. pixelExtent is the dimension of the
// (square) tile in pixels usually 4096, see DefaultExtent.
// The geometry must not go outside the tile extent. If this is unknown,
// use the clip package before encoding.
// This function treats the tile extent elements as left, top, right, bottom. This is fine
// when working with a north-positive projection such as lat/long (epsg:4326)
// and web mercator (epsg:3857), but a south-positive projection (ie. epsg:2054) or west-postive
// projection would then flip the geomtery. To properly render these coordinate systems, simply
// swap the X's or Y's in the tile extent.
func PrepareGeo(geo geom.Geometry, tile *geom.Extent, pixelExtent float64) geom.Geometry {
switch g := geo.(type) {
case geom.Point:
Expand Down Expand Up @@ -60,10 +63,10 @@ func PrepareGeo(geo geom.Geometry, tile *geom.Extent, pixelExtent float64) geom.
}

func preparept(g geom.Point, tile *geom.Extent, pixelExtent float64) geom.Point {
px := (g.X() - tile.MinX()) / tile.XSpan() * pixelExtent
py := (g.Y() - tile.MinY()) / tile.YSpan() * pixelExtent
px := int64((g.X() - tile.MinX()) / tile.XSpan() * pixelExtent)
py := int64((tile.MaxY() - g.Y()) / tile.YSpan() * pixelExtent)

return geom.Point{px, py}
return geom.Point{float64(px), float64(py)}
}

func preparelinestr(g geom.LineString, tile *geom.Extent, pixelExtent float64) (ls geom.LineString) {
Expand Down
16 changes: 8 additions & 8 deletions encoding/mvt/prepare_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ func TestPrepareLinestring(t *testing.T) {

tests := map[string]tcase{
"duplicate pt simple line": {
in: geom.LineString{{9.0, 9.0}, {9.0, 9.0}},
out: geom.LineString{{9.0, 9.0}, {9.0, 9.0}},
in: geom.LineString{{9.0, 4090.0}, {9.0, 4090.0}},
out: geom.LineString{{9.0, 6.0}, {9.0, 6.0}},
tile: geom.Extent{0.0, 0.0, 4096.0, 4096.0},
},
"simple line": {
in: geom.LineString{{9.0, 9.0}, {11.0, 11.0}},
out: geom.LineString{{9.0, 9.0}, {11.0, 11.0}},
in: geom.LineString{{9.0, 4090.0}, {11.0, 4091.0}},
out: geom.LineString{{9.0, 6.0}, {11.0, 5.0}},
tile: geom.Extent{0.0, 0.0, 4096.0, 4096.0},
},
"edge line": {
in: geom.LineString{{0.0, 0.0}, {4096.0, 20.0}},
out: geom.LineString{{0.0, 0.0}, {4096.0, 20.0}},
out: geom.LineString{{0.0, 4096.0}, {4096.0, 4076.0}},
tile: geom.Extent{0.0, 0.0, 4096.0, 4096.0},
},
"simple line 3pt": {
in: geom.LineString{{9.0, 9.0}, {11.0, 9.0}, {11.0, 14.0}},
out: geom.LineString{{9.0, 9.0}, {11.0, 9.0}, {11.0, 14.0}},
in: geom.LineString{{9.0, 4090.0}, {11.0, 4090.0}, {11.0, 4076.0}},
out: geom.LineString{{9.0, 6.0}, {11.0, 6.0}, {11.0, 20.0}},
tile: geom.Extent{0.0, 0.0, 4096.0, 4096.0},
},
"scale" : {
in: geom.LineString{{100.0, 100.0}, {300.0, 300.0}},
out: geom.LineString{{1024.0, 1024.0}, {3072.0, 3072.0}},
out: geom.LineString{{1024.0, 3072.0}, {3072.0, 1024.0}},
tile: geom.Extent{0.0, 0.0, 400.0, 400.0},
},
}
Expand Down
32 changes: 16 additions & 16 deletions slippy/tile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func TestNewTile(t *testing.T) {
x: 1,
y: 1,
buffer: 64,
eExtent: geom.NewExtent(
[2]float64{-10018754.17, 10018754.17},
[2]float64{0, 0},
),
eBExtent: geom.NewExtent(
[2]float64{-1.017529720390625e+07, 1.017529720390625e+07},
[2]float64{156543.03390624933, -156543.03390624933},
),
eExtent: &geom.Extent{
-10018754.17, 0,
0, 10018754.17,
},
eBExtent: &geom.Extent{
-1.017529720390625e+07, -156543.03390624933,
156543.03390624933, 1.017529720390625e+07,
},
eBounds: spherical.Hull(
[2]float64{-90, 66.51},
[2]float64{0, 0},
Expand All @@ -89,14 +89,14 @@ func TestNewTile(t *testing.T) {
x: 11436,
y: 26461,
buffer: 64,
eExtent: geom.NewExtent(
[2]float64{-13044437.497219238996, 3856706.6986199953},
[2]float64{-13043826.000993041, 3856095.202393799},
),
eBExtent: geom.NewExtent(
[2]float64{-1.3044447051847773e+07, 3.8567162532485295e+06},
[2]float64{-1.3043816446364507e+07, 3.856085647765265e+06},
),
eExtent: &geom.Extent{
-13044437.497219238996, 3856095.202393799,
-13043826.000993041, 3856706.6986199953,
},
eBExtent: &geom.Extent{
-1.3044447051847773e+07, 3.856085647765265e+06,
-1.3043816446364507e+07, 3.8567162532485295e+06,
},
eBounds: spherical.Hull(
[2]float64{-117.18, 32.70},
[2]float64{-117.17, 32.70},
Expand Down