-
Notifications
You must be signed in to change notification settings - Fork 0
/
TarpitAnGeo
110 lines (87 loc) · 3.6 KB
/
TarpitAnGeo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.io.InputStream
val Liste1 = mutableListOf<String>()
val Liste2 = mutableListOf<String>()
val Liste3 = mutableListOf<String>()
val Liste4 = mutableListOf<String>()
val ListeConfig = mutableListOf<String>()
var wertDECip: String = ""
val path = System.getProperty("user.dir")
var longlat = ""
var fileName = "ip-locations.txt"
var fileName2 = "data.txt"
var fileName3 = "maps.kml"
fun main(args: Array<String>) {
val inputStream99: InputStream = File(path + File.separator + "geo.txt").inputStream()
inputStream99.bufferedReader().forEachLine { ListeConfig.add(it) }
longlat = ListeConfig.elementAt(0)
val inputStream2: InputStream = File(path +File.separator + fileName).inputStream()
inputStream2.bufferedReader().forEachLine { Liste1.add(it) }
val inputStream: InputStream = File(path + File.separator + fileName2).inputStream()
inputStream.bufferedReader().forEachLine { Liste2.add(it) }
println(" Preparing Data.")
prepareDECip()
println(" Writing KML File.")
println(" ")
createKML()
println(" ")
println(" Process completed.")
println(" ")
}
fun prepareDECip() {
for (line in Liste2) {
val pos1 = line.indexOf(",",0)
val pos2 = line.indexOf(",",((pos1)+1))
val pos3 = line.indexOf(",",((pos2)+1))
wertDECip = line.substring(pos2+1, pos3)
Liste3.add(wertDECip)
}
Liste4.addAll(Liste3.distinct())
}
fun createKML() {
var decip: Double
val kopftext: String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><Style id=\"transBluePoly\"><LineStyle><width>1.5</width><color>501400E6</color></LineStyle></Style>"
var haupttext: String = ""
val endtext: String = "</Document></kml>"
var counter: Long = 0
try {
val fw = FileWriter(path + File.separator + fileName3, true)
fw.write(kopftext)
for(line in Liste4){
counter = counter +1
decip = line.toDouble()
for (line in Liste1) {
val pos1 = line.indexOf(",",0)
val pos2 = line.indexOf(",",((pos1)+1))
val pos3 = line.indexOf(",",((pos2)+1))
val pos4 = line.indexOf(",",((pos3)+1))
val pos5 = line.indexOf(",",((pos4)+1))
val pos6 = line.indexOf(",",((pos5)+1))
val pos7 = line.indexOf(",",((pos6)+1))
val wert1: String = line.substring(0,pos1)
val wert2: String = line.substring(pos1+1, pos2)
val wert6: String = line.substring(pos5+1, pos6)
val wert7: String = line.substring(pos6+1, pos7)
val wert8: String = line.substring(pos7+1)
val Cwert1: Double = wert1.toDouble()
val Cwert2: Double = wert2.toDouble()
if (decip >= Cwert1 && decip <= Cwert2) {
haupttext = "<Placemark>" +
"<name>" + wert6 + "</name>" + "<extrude>1</extrude>" +
"<tessellate>1</tessellate><styleUrl>#transBluePoly</styleUrl><LineString>" +
"<coordinates>" + wert8 + "," + wert7 + System.getProperty("line.separator") + longlat + "</coordinates></LineString></Placemark>"
fw.write(haupttext)
break
}
}
var percentage = (counter.toDouble() / Liste4.count().toDouble()) * 100
var prozent: Int = percentage.toInt()
print( " " + prozent.toString() + "% \r")
}
fw.write(endtext)
fw.close()
} catch (e: IOException) {
}
}