Skip to content

Commit

Permalink
Merge pull request #34 from trajectoryjp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
HarutakaMatsumoto authored Sep 9, 2024
2 parents 11506da + 14706ca commit 9ab0554
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 7 deletions.
14 changes: 7 additions & 7 deletions transform/convert_quadkey_and_Vertical_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func ConvertExtendedSpatialIDToSpatialIDs(extendedSpatialID *object.ExtendedSpat
// extendedSpatialIDs :["20/85263/65423/23/-2", "20/85263/65423/23/-1"]
func ConvertTileXYZsToExtendedSpatialIDs(request []*object.TileXYZ, zBaseExponent int64, zBaseOffset int64, outputVZoom int64) ([]object.ExtendedSpatialID, error) {

extendedSpatialIDsMap := make(map[int64]object.ExtendedSpatialID)
extendedSpatialIDsMap := make(map[object.ExtendedSpatialID]bool)

for _, r := range request {
if !extendedSpatialIDCheckZoom(r.HZoom(), outputVZoom) {
Expand All @@ -627,20 +627,20 @@ func ConvertTileXYZsToExtendedSpatialIDs(request []*object.TileXYZ, zBaseExponen
}

for z := zMin; z <= zMax; z++ {
// 重複排除
if _, exists := extendedSpatialIDsMap[z]; exists {
continue
}
extendedSpatialID := new(object.ExtendedSpatialID)
extendedSpatialID.SetX(r.X())
extendedSpatialID.SetY(r.Y())
extendedSpatialID.SetZ(z)
extendedSpatialID.SetZoom(r.HZoom(), outputVZoom)
extendedSpatialIDsMap[z] = *extendedSpatialID
// 重複排除
if _, exists := extendedSpatialIDsMap[*extendedSpatialID]; exists {
continue
}
extendedSpatialIDsMap[*extendedSpatialID] = true
}
}
extendedSpatialIDs := make([]object.ExtendedSpatialID, 0, len(extendedSpatialIDsMap))
for _, extendedSpatialID := range extendedSpatialIDsMap {
for extendedSpatialID := range extendedSpatialIDsMap {
extendedSpatialIDs = append(extendedSpatialIDs, extendedSpatialID)
}

Expand Down
155 changes: 155 additions & 0 deletions transform/convert_quadkey_and_Vertical_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,54 @@ func TestConvertTileXYZsToSpatialIDs(t *testing.T) {
23,
},
},
{
[]string{
"23/0/85263/65423",
"23/1/85263/65423",
"23/2/85263/65423",
"23/0/85264/65424",
"23/1/85264/65424",
"23/2/85264/65424",
},
argSet{
[]*object.TileXYZ{
newTileXYZ(
t,
23,
85263,
65423,
23,
0,
),
newTileXYZ(
t,
23,
85263,
65423,
23,
1,
),
newTileXYZ(
t,
23,
85264,
65424,
23,
0,
),
newTileXYZ(
t,
23,
85264,
65424,
23,
1,
)},
25,
-1,
23,
},
},
}
for _, testCase := range testCases {
result, err := ConvertTileXYZsToSpatialIDs(testCase.request.tile, testCase.request.zBaseExponent, testCase.request.zBaseOffset, testCase.request.outputVZoom)
Expand Down Expand Up @@ -736,6 +784,47 @@ func TestConvertTileXYZsToExtendedSpatialIDs(t *testing.T) {
23,
},
},
{
[]string{"20/85263/65423/23/0", "20/85263/65423/23/1", "20/85263/65423/23/2", "20/85264/65424/23/0", "20/85264/65424/23/1", "20/85264/65424/23/2"},
argSet{
[]*object.TileXYZ{
newTileXYZ(
t,
20,
85263,
65423,
23,
0,
),
newTileXYZ(
t,
20,
85263,
65423,
23,
1,
),
newTileXYZ(
t,
20,
85264,
65424,
23,
0,
),
newTileXYZ(
t,
20,
85264,
65424,
23,
1,
)},
25,
-1,
23,
},
},
}
for _, testCase := range testCases {
expectedData := []object.ExtendedSpatialID{}
Expand Down Expand Up @@ -830,6 +919,72 @@ func TestErrorConvertTileXYZsToExtendedSpatialIDs(t *testing.T) {
}
}

func ExampleConvertTileXYZsToExtendedSpatialIDs() {
inputData := []struct {
hZoom int64
x int64
y int64
vZoom int64
z int64
}{
{
22,
85263,
65423,
23,
0,
},
{
22,
85263,
65423,
23,
1,
},
{
22,
85264,
65424,
23,
0,
},
{
22,
85264,
65424,
23,
1,
},
}
var inputXYZ []*object.TileXYZ
for _, in := range inputData {
tile, err := object.NewTileXYZ(in.hZoom, in.x, in.y, in.vZoom, in.z)
if err != nil {
panic(err)
}
inputXYZ = append(inputXYZ, tile)
}
outputData, err := ConvertTileXYZsToExtendedSpatialIDs(
inputXYZ,
25,
-1,
23,
)
if err != nil {
panic(err)
}
for _, out := range outputData {
fmt.Println(out.ID())
}
// Unordered output:
// 22/85263/65423/23/0
// 22/85264/65424/23/0
// 22/85263/65423/23/1
// 22/85264/65424/23/1
// 22/85263/65423/23/2
// 22/85264/65424/23/2
}

func TestConvertExtendedSpatialIDsToSpatialIDs(t *testing.T) {
testCases := []struct {
expected []string
Expand Down

0 comments on commit 9ab0554

Please sign in to comment.