Skip to content

Commit 13611c5

Browse files
committed
restructured project
1 parent 26095f1 commit 13611c5

19 files changed

+43
-79
lines changed
File renamed without changes.

src/helpers/closestNode.go renamed to src/backend/helpers/closestNode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package helpers
22

33
import (
4-
"OSM/src/datastructures"
4+
"OSM/src/backend/datastructures"
55
"log"
66
"math"
77
"time"

src/helpers/createPath.go renamed to src/backend/helpers/createPath.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package helpers
22

3-
import "OSM/src/datastructures"
3+
import (
4+
"OSM/src/backend/datastructures"
5+
)
46

57
func CreatePathFromPrev(start, end int32, prev []int32, graph datastructures.Graph) [][]float64 {
68
var path [][]float64
File renamed without changes.

src/helpers/fmiFormat.go renamed to src/backend/helpers/fmiFormat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package helpers
22

33
import (
4-
"OSM/src/datastructures"
4+
"OSM/src/backend/datastructures"
55
"bufio"
66
"fmt"
77
"log"

src/helpers/geoJson.go renamed to src/backend/helpers/geoJson.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package helpers
22

33
import (
4-
"OSM/src/datastructures"
4+
"OSM/src/backend/datastructures"
55
"fmt"
66
geojson "github.com/paulmach/go.geojson"
77
"log"
88
"os"
99
)
1010

11-
func NodesToLineString(nodes [][]float64, popupContent int32) []byte {
11+
func NodesToLineStringGeoJson(nodes [][]float64, popupContent int32) []byte {
1212
lineNodes := make([][]float64, len(nodes))
1313
for i, elem := range nodes {
1414
lineNodes[i] = []float64{elem[1], elem[0]}
@@ -22,7 +22,7 @@ func NodesToLineString(nodes [][]float64, popupContent int32) []byte {
2222
return rawJson
2323
}
2424

25-
func NodeToPoint(node []float64, index int32) []byte {
25+
func NodeToPointGeoJson(node []float64, index int32) []byte {
2626
fc := geojson.NewFeatureCollection()
2727
feature := geojson.NewPointFeature([]float64{node[1], node[0]})
2828
popupContent := fmt.Sprintf("Lat: %f\nLong: %f\nIndex: %d", node[0], node[1], index)
@@ -33,7 +33,7 @@ func NodeToPoint(node []float64, index int32) []byte {
3333
return rawJson
3434
}
3535

36-
func NodesToPoints(nodes [][]float64) []byte {
36+
func NodesToPointsGeoJson(nodes [][]float64) []byte {
3737
fc := geojson.NewFeatureCollection()
3838
for _, node := range nodes {
3939
feature := geojson.NewPointFeature([]float64{node[1], node[0]})

src/coastlines/coastlines.go renamed to src/backend/pre/coastlines.go

+1-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package coastlines
1+
package pre
22

33
import (
44
"io"
@@ -7,7 +7,6 @@ import (
77
"runtime"
88
"time"
99

10-
geojson "github.com/paulmach/go.geojson"
1110
"github.com/qedus/osmpbf"
1211
)
1312

@@ -31,7 +30,6 @@ func readPBF(path string) (map[int64][]float64, map[int64][]int64) {
3130
}
3231
nodes := make(map[int64][]float64)
3332
ways := make(map[int64][]int64)
34-
//var happenings int64 = 0
3533
for {
3634
if v, err := d.Decode(); err == io.EOF {
3735
break
@@ -66,21 +64,6 @@ func readPBF(path string) (map[int64][]float64, map[int64][]int64) {
6664
return nodes, ways
6765
}
6866

69-
func CreateGeojson(nodes map[int64][]float64, ways map[int64][]int64) []byte {
70-
fc := geojson.NewFeatureCollection()
71-
for _, val := range ways {
72-
var lineNodes [][]float64
73-
for _, nodeId := range val {
74-
lineNodes = append(lineNodes, []float64{nodes[nodeId][1], nodes[nodeId][0]})
75-
}
76-
feature := geojson.NewLineStringFeature(lineNodes)
77-
feature.SetProperty("", 0)
78-
fc.AddFeature(feature)
79-
}
80-
rawJson, _ := fc.MarshalJSON()
81-
return rawJson
82-
}
83-
8467
// merges ways where the end node of the way is the starting node of another way
8568
func mergeWays(ways map[int64][]int64) {
8669
toDelete := make(map[int64]bool)
@@ -113,14 +96,6 @@ func mergeWays(ways map[int64][]int64) {
11396
func GenerateCoastlines(path string) [][][]float64 {
11497
log.Printf("Starting to read pbf file.\n")
11598
nodes, ways := readPBF(path)
116-
//fmt.Printf("Ways before merging: %d\n", len(ways))
117-
//mergeWays(ways)
118-
//fmt.Printf("Ways after merging: %d\n", len(ways))
119-
//mergeWays(ways)
120-
//fmt.Printf("Ways after merging twice: %d\n", len(ways))
121-
//mergeWays(ways)
122-
//fmt.Printf("Ways after merging thrice %d\n", len(ways))
123-
12499
oldLength := len(ways)
125100

126101
startTimeMerge := time.Now()

src/spherePoints/spherePoints.go renamed to src/backend/pre/graphFactory.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
package spherePoints
1+
package pre
22

33
import (
4-
"OSM/src/datastructures"
5-
"OSM/src/helpers"
4+
"OSM/src/backend/datastructures"
5+
"OSM/src/backend/helpers"
66
"log"
77
"math"
88
"sort"
99
"time"
10-
11-
geojson "github.com/paulmach/go.geojson"
1210
)
1311

1412
const LowerBound = -80 // from -90 (South Pole) until around -80 Latitute, Antartica land so no points needed to be created

src/piptest/piptest.go renamed to src/backend/pre/piptest.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package piptest
1+
package pre
22

33
import (
44
"fmt"
@@ -238,7 +238,7 @@ func progressBar(counter int, max_len int) string { //Progress bar to show the p
238238
return bar
239239
}
240240

241-
// method to call when we want to do this
241+
// TopLevel method to call when we want to do this
242242
func TopLevel(wayNodes [][][]float64, spherePointsArr [][]float64) []bool {
243243
start11 := time.Now()
244244
boundBoxes := createBoundingBoxes(wayNodes)

src/piptest/piptest_test.go renamed to src/backend/pre/piptest_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package piptest
1+
package pre
22

33
import (
4-
"OSM/src/coastlines"
54
"testing"
65
)
76

@@ -18,7 +17,7 @@ func TestTopLevel(t *testing.T) {
1817
}
1918
var correctClassification = []bool{false, true, true, false, false, true, false, false}
2019

21-
wayNodes := coastlines.GenerateCoastlines("E:/Classes Infotech/4th Semster/Fachpraktika/Code/data/planet-coastlines.pbf")
20+
wayNodes := GenerateCoastlines("E:/Classes Infotech/4th Semster/Fachpraktika/Code/data/planet-coastlines.pbf")
2221
results := TopLevel(wayNodes, coordinates)
2322

2423
for i, elem := range results {

src/shortestPath/dijkstra.go renamed to src/backend/shortestPath/dijkstra.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
package shortestPath
22

33
import (
4-
"OSM/src/datastructures"
4+
datastructures2 "OSM/src/backend/datastructures"
55
"container/heap"
66
"log"
77
"math"
88
"time"
99
)
1010

11-
func Dijkstra(start int32, end int32, graph datastructures.Graph) (int32, []int32) {
11+
func Dijkstra(start int32, end int32, graph datastructures2.Graph) (int32, []int32) {
1212
startTime := time.Now()
1313
dist := make([]int32, len(graph.Nodes))
1414
for i := 0; i < len(dist); i++ {
1515
dist[i] = math.MaxInt32
1616
}
1717
prev := make([]int32, len(graph.Nodes))
18-
pq := make(datastructures.PriorityQueue, 0)
18+
pq := make(datastructures2.PriorityQueue, 0)
1919

20-
heap.Push(&pq, &datastructures.Item{
20+
heap.Push(&pq, &datastructures2.Item{
2121
Id: start,
2222
Dist: 0,
2323
Prev: start,
2424
})
2525
for pq.Len() > 0 {
26-
node := heap.Pop(&pq).(*datastructures.Item)
26+
node := heap.Pop(&pq).(*datastructures2.Item)
2727
if node.Dist >= dist[node.Id] {
2828
continue
2929
}
@@ -40,7 +40,7 @@ func Dijkstra(start int32, end int32, graph datastructures.Graph) (int32, []int3
4040
if alt >= dist[graph.Edges[e]] {
4141
continue
4242
}
43-
heap.Push(&pq, &datastructures.Item{
43+
heap.Push(&pq, &datastructures2.Item{
4444
Id: graph.Edges[e],
4545
Dist: alt,
4646
Prev: node.Id,

src/shortestPath/dijkstra_test.go renamed to src/backend/shortestPath/dijkstra_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package shortestPath
22

33
import (
4-
"OSM/src/helpers"
4+
"OSM/src/backend/helpers"
55
"log"
66
"math/rand"
77
"testing"

src/main.go

+11-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
package main
22

33
import (
4-
"OSM/src/coastlines"
5-
"OSM/src/piptest"
6-
"OSM/src/spherePoints"
4+
"OSM/src/backend/helpers"
5+
pre2 "OSM/src/backend/pre"
6+
"os"
77
)
88

9-
func main() {
10-
//path := "E:/Classes Infotech/4th Semster/Fachpraktika/Code/data/planet-coastlines.pbf" //change to own path
11-
//nodes, ways := coastlines.GenerateCoastlines(path)
12-
//
13-
//var no_of_nodes int64 = 10000
14-
//
15-
//tested_p_array := piptest.TopLevel(nodes, ways, no_of_nodes)
16-
//fmt.Printf("Size of mapped points: %d", len(tested_p_array))
17-
//
18-
//json_file := spherePoints.PointsToGeoJson(tested_p_array)
19-
//if err := os.WriteFile("../out/out_pip_test.json", json_file, 06666); err != nil {
20-
//
21-
// log.Fatal(err)
22-
//}
9+
const N = 1e6
2310

24-
//web.GenerateCoastlines("D:/OneDrive - stud.uni-stuttgart.de/Uni/10. Semester/FP-OSM/pbf files/oceanfmi.sec")
11+
func main() {
12+
path := os.Getenv("PBF")
2513

26-
wayNodes := coastlines.GenerateCoastlines("E:/Classes Infotech/4th Semster/Fachpraktika/Code/data/planet-coastlines.pbf")
27-
points := spherePoints.GenerateSpherePoints(1e4)
28-
piptest.TopLevel(wayNodes, points)
14+
wayNodes := pre2.GenerateCoastlines(path)
15+
points := pre2.GenerateSpherePoints(N)
16+
classification := pre2.TopLevel(wayNodes, points)
17+
graph := pre2.GenerateGraphFromPoints(N, points, classification)
18+
helpers.CreateFileFromGraph(graph, "./out/graph.fmi")
2919

3020
}

web/server.go renamed to src/web/server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package web
22

33
import (
4-
"OSM/src/datastructures"
5-
"OSM/src/helpers"
6-
"OSM/src/shortestPath"
4+
"OSM/src/backend/datastructures"
5+
helpers2 "OSM/src/backend/helpers"
6+
"OSM/src/backend/shortestPath"
77
"log"
88
"math"
99
"net/http"
1010
"strconv"
1111
)
1212

1313
func Main(pathToFmiFile string) {
14-
graph := helpers.CreateGraphFromFile(pathToFmiFile)
14+
graph := helpers2.CreateGraphFromFile(pathToFmiFile)
1515

1616
fileServer := http.FileServer(http.Dir("web/static"))
1717
http.Handle("/", fileServer)
@@ -38,8 +38,8 @@ func pointHandler(graph datastructures.Graph) http.HandlerFunc {
3838
query := r.URL.Query()
3939
lat, _ := strconv.ParseFloat(query["lat"][0], 64)
4040
lng, _ := strconv.ParseFloat(query["lng"][0], 64)
41-
idx, node := helpers.GetClosestNodeInGraph([]float64{lat, lng}, graph)
42-
rawJson := helpers.NodeToPoint(node, idx)
41+
idx, node := helpers2.GetClosestNodeInGraph([]float64{lat, lng}, graph)
42+
rawJson := helpers2.NodeToPointGeoJson(node, idx)
4343
w.WriteHeader(http.StatusOK)
4444
w.Write(rawJson)
4545
}
@@ -69,8 +69,8 @@ func routeHandler(graph datastructures.Graph) http.HandlerFunc {
6969
return
7070
}
7171

72-
lineNodes := helpers.CreatePathFromPrev(startIdx32, endIdx32, prev, graph)
73-
rawJson := helpers.NodesToLineString(lineNodes, distance)
72+
lineNodes := helpers2.CreatePathFromPrev(startIdx32, endIdx32, prev, graph)
73+
rawJson := helpers2.NodesToLineStringGeoJson(lineNodes, distance)
7474

7575
w.WriteHeader(http.StatusOK)
7676
w.Write(rawJson)
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)