-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
68 lines (54 loc) · 1.87 KB
/
convert.py
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
import pandas as pd
import numpy as np
from pyproj import Proj, transform
class Coords():
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def getCoords(self):
return self.x, self.y, self.z
def setCoords(self, x, y, z):
self.x = x
self.y = y
self.z = z
def transf(epsgIn, epsgOut, coor, dims):
# inProj = Proj(init='epsg:3857')
inProj = Proj(epsgIn)
outProj = Proj(epsgOut)
# outProj = Proj(init='epsg:4326')
x, y, z = coor.getCoords()
if dims == 3:
out = transform(inProj, outProj, round(x,6), round(y,6), round(z,6))
else:
out = transform(inProj, outProj, round(x,6), round(y,6))
return out
inputFile = "debugData.txt"
outputFile = "transformed_" + inputFile
epsgIn = 'epsg:31467' # DHDN GK zone 3
epsgOut = 'epsg:4326' # WGS84
outputDims = 2
data = pd.read_csv(inputFile)# , usecols=[1,2,3,4,5,6,7], names=['x', 'y', 'z','R','G','B','ID'])
npd = data.to_numpy()
w = open(outputFile, "w", 16000000)
tmpString = ""
l = len(npd[1])
for i in range(len(npd)):
# x and y are exchanged because DHDN uses Northing (y) and Easting (x)
C = Coords(npd[i][1], npd[i][0], npd[i][2])
c = transf(epsgIn, epsgOut, C, outputDims)
# tmpString = str(c[0]) + " " + str(c[1]) + "\n"
if l == 7:
tmpString = str(c[1]) + "," + str(c[0]) + "," + str(C.z) + "," + str(npd[i][3]) + \
"," + str(npd[i][4]) + "," + str(npd[i][5]) + \
"," + str(npd[i][6]) + "\n"
elif l == 6:
tmpString = str(c[1]) + "," + str(c[0]) + "," + str(C.z) + "," + \
str(npd[i][3]) + "," + str(npd[i][4]) + "," + str(npd[i][5]) + "\n"
elif l == 3:
tmpString = str(c[1]) + "," + str(c[0]) + "," + str(C.z) + "\n"
if i % 100 == 0:
print(str(i) + ": " + tmpString)
w.write(tmpString)
w.close()
print("end reached!")