diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..d2a6c12
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "python.pythonPath": "/usr/bin/python"
+}
\ No newline at end of file
diff --git a/InitGui.py b/InitGui.py
index 94d42c4..a9beddd 100644
--- a/InitGui.py
+++ b/InitGui.py
@@ -35,25 +35,6 @@
windowCreated = 0
-# http://www.bkg.bund.de/nn_159902/EN/FederalOffice/Products/Geo-Data/Geo__Data__node.html__nnn=true
-#import sys
-#for p in sys.path:
-# print(p)
-
-'''
-try:
- import importlib
- def reload(a):
- importlib.reload(a)
-except:
- pass
->>>>>>> Stashed changes
-
-def reload(a):
- import importlib
- importlib.reload(a)
-'''
-
try:
import cv2
except:
@@ -70,9 +51,7 @@ def reload(a):
import FreeCAD,FreeCADGui
-import sys
-reload(sys)
#---------------------------------------------------------------------------
# define the Commands of the Test Application module
@@ -460,7 +439,7 @@ def IsActive(self):
def Activated(self):
- import re
+ import re, sys
ta=True
if ta:
FreeCAD.ActiveDocument.openTransaction(self.name)
diff --git a/geodat/elevationgrid.py b/geodat/elevationgrid.py
index c8f978a..beba729 100644
--- a/geodat/elevationgrid.py
+++ b/geodat/elevationgrid.py
@@ -333,7 +333,7 @@ def createElevationGrid(mode,rbfmode=True,source=None,gridCount=20,zfactor=20,bo
}
say("Source",source,"mode",mode)
- if source<>None:
+ if source is not None:
if hasattr(source,"Shape"):
# part object
diff --git a/geodat/import_aster.py b/geodat/import_aster.py
index 9f9bd3f..63e2caf 100644
--- a/geodat/import_aster.py
+++ b/geodat/import_aster.py
@@ -47,12 +47,14 @@ def import_ast(b=50.26,l=11.39):
example .../.FreeCAD/geodat/AST/ASTGTM2_N51E010_dem.tif
'''
+ import numpy as np
+
bs=np.floor(b)
ls=np.floor(l)
# the ast dataset
ff="N%02dE%03d" % (int(bs),int(ls))
- fn=FreeCAD.ConfigGet("UserAppData") +'/geodat/AST/ASTGTM2_' + ff +'_dem.tif'
+ fn=FreeCAD.ConfigGet("UserAppData") +'geodat/AST/ASTGTM2_' + ff +'_dem.tif'
print(fn)
'''
diff --git a/geodat/import_csv.py b/geodat/import_csv.py
index 2a4e8e6..18bbb74 100644
--- a/geodat/import_csv.py
+++ b/geodat/import_csv.py
@@ -1,106 +1,77 @@
# -*- coding: utf-8 -*-
-#-------------------------------------------------
-#-- geodat import csv
-#--
-#-- microelly 2016 v 0.1
-#--
-#-- GNU Lesser General Public License (LGPL)
-#-------------------------------------------------
-
-
+# -------------------------------------------------
+# -- geodat import csv
+# --
+# -- microelly 2016 v 0.1
+# --
+# -- GNU Lesser General Public License (LGPL)
+# -------------------------------------------------
+
+import FreeCAD
+import FreeCADGui
+import Part
+import Draft
+from geodat.transversmercator import TransverseMercator
from geodat.say import *
+import csv
+import re
import sys
-if sys.version_info[0] !=2:
- from importlib import reload
-
-import FreeCAD,FreeCADGui, Part
-App=FreeCAD
-Gui=FreeCADGui
-
-import geodat.transversmercator
-from geodat.transversmercator import TransverseMercator
-
-import csv,re
-
-'''
-example data csv
-
-50.3729107;11.1913920;"l";"b"
-50.3731789;11.1919306;"l";"b"
-50.3732226;11.1920048;"l";"b"
-50.3732894;11.1920829;"l";"b"
-50.3734014;11.1900516;"l";"b"
-50.3736555;11.1906749;"l";"b"
-50.3734900;11.1904810;"l";"b"
-50.3734923;11.1905679;"l";"b"
-
-
-# python data ...
-
- origin=(50.3729107,11.1913920)
-
- data=[
- [50.3729107, 11.1913920, "l", "b"],
- [50.3731789, 11.1919306, "l", "b"],
- [50.3732226, 11.1920048, "l", "b"],
- [50.3732894, 11.1920829, "l", "b"],
- [50.3734014, 11.1900516, "l", "b"],
- [50.3736555, 11.1906749, "l", "b"],
- [50.3734900, 11.1904810, "l", "b"],
- [50.3734923, 11.1905679, "l", "b"],
- ]
-
-'''
-
-
-def import_csv(fn,orig,datatext=None):
- # lat lon
- yy=orig.split(',')
- origin=(float(yy[0]),float(yy[1]))
-
- data=[]
- if len(datatext) != 0:
- lines=datatext.split('\n')
- for l in lines:
- pp=re.split("( )+",l)
- if len(pp)==1:
- continue
- if len(pp)<3:
- raise Exception("Syntax error in 'direct Data input'")
- data.append([str(pp[0]),str(pp[2])])
- print(data)
- else:
- with open(fn, 'r') as csvfile:
- reader = csv.reader(csvfile, delimiter=';')
- print (reader)
- for row in reader:
- data.append(row)
-
- tm=TransverseMercator()
- tm.lat=origin[0]
- tm.lon=origin[1]
- center=tm.fromGeographic(tm.lat,tm.lon)
-
- points=[]
- for p in data:
- lat,lon = p[0],p[1]
- ll=tm.fromGeographic(float(lat),float(lon))
- points.append( FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],0.0))
-
- import Draft
- points.append(points[0])
- Draft.makeWire(points)
-
- po=App.ActiveDocument.ActiveObject
- po.ViewObject.LineColor=(1.0,0.0,0.0)
- po.MakeFace = False
-
- App.activeDocument().recompute()
- Gui.SendMsgToActiveView("ViewFit")
-
-
-s6='''
+if sys.version_info[0] != 2:
+ from importlib import reload
+
+App = FreeCAD
+Gui = FreeCADGui
+
+
+def import_csv(fn, orig, datatext=None):
+ # lat lon
+ yy = orig.split(',')
+ origin = (float(yy[0]), float(yy[1]))
+
+ data = []
+ if len(datatext) != 0:
+ lines = datatext.split('\n')
+ for l in lines:
+ pp = re.split("( )+", l)
+ if len(pp) == 1:
+ continue
+ if len(pp) < 3:
+ raise Exception("Syntax error in 'direct Data input'")
+
+ data.append([str(pp[0]), str(pp[2])])
+
+ else:
+ with open(fn, 'r') as csvfile:
+ reader = csv.reader(csvfile, delimiter=';')
+ print(reader)
+ for row in reader:
+ data.append(row)
+
+ tm = TransverseMercator()
+ tm.lat = origin[0]
+ tm.lon = origin[1]
+ center = tm.fromGeographic(tm.lat, tm.lon)
+
+ points = []
+ for p in data:
+ lat, lon = p[0], p[1]
+ ll = tm.fromGeographic(float(lat), float(lon))
+ points.append(FreeCAD.Vector(ll[0]-center[0], ll[1]-center[1], 0.0))
+
+
+ points.append(points[0])
+ Draft.makeWire(points)
+
+ po = App.ActiveDocument.ActiveObject
+ po.ViewObject.LineColor = (1.0, 0.0, 0.0)
+ po.MakeFace = False
+
+ App.activeDocument().recompute()
+ Gui.SendMsgToActiveView("ViewFit")
+
+
+s6 = '''
MainWindow:
VerticalLayout:
id:'main'
@@ -113,7 +84,7 @@ def import_csv(fn,orig,datatext=None):
setText:"Data input filename"
QtGui.QLineEdit:
- setText:"/home/thomas/.FreeCAD/Mod/geodat/testdata/csv_example.csv"
+ setText:"Select *.csv file"
id: 'bl'
QtGui.QPushButton:
@@ -142,48 +113,44 @@ def import_csv(fn,orig,datatext=None):
'''
-import FreeCAD,FreeCADGui
class MyApp(object):
- def run(self):
- filename=self.root.ids['bl'].text()
- try:
- import_csv(
- filename,
- self.root.ids['orig'].text(),
- self.root.ids['data'].toPlainText(),
- )
- except:
- sayexc()
-
- def getfn(self):
- fileName = QtGui.QFileDialog.getOpenFileName(None,u"Open File",u"/tmp/");
- s=self.root.ids['bl']
- s.setText(fileName[0])
+ def run(self):
+ filename = self.root.ids['bl'].text()
+ try:
+ import_csv(
+ filename,
+ self.root.ids['orig'].text(),
+ self.root.ids['data'].toPlainText(),
+ )
+ except:
+ sayexc()
+ def getfn(self):
+ fileName = QtGui.QFileDialog.getOpenFileName(None, u"Open File", u"/tmp/")
+ s = self.root.ids['bl']
+ s.setText(fileName[0])
def importCSV():
- app=MyApp()
-
- import geodat.miki as miki
- #reload(miki)
+ app = MyApp()
+ import geodat.miki as miki
+ # reload(miki)
- miki=miki.Miki()
- miki.app=app
- app.root=miki
+ miki = miki.Miki()
+ miki.app = app
+ app.root = miki
- miki.parse2(s6)
- miki.run(s6)
- return miki
+ miki.parse2(s6)
+ miki.run(s6)
+ return miki
# mydialog()
-
def runtest():
- m=mydialog()
- m.objects[0].hide()
+ m = mydialog()
+ m.objects[0].hide()
diff --git a/geodat/import_emir.py b/geodat/import_emir.py
index 91b2607..5bdb1df 100644
--- a/geodat/import_emir.py
+++ b/geodat/import_emir.py
@@ -14,7 +14,7 @@
from geodat.say import *
-import FreeCAD,FreeCADGui, Part
+import FreeCAD, FreeCADGui, Part
App=FreeCAD
Gui=FreeCADGui
@@ -42,20 +42,20 @@
def parsedata(lines):
print(lines)
- a=lines[0].split()
dat={}
- a=lines[0].split()
+ a=lines[0].decode().split()
dat[a[0]]=int(a[1])
- a=lines[1].split()
+
+ a=lines[1].decode().split()
dat[a[0]]=int(a[1])
- a=lines[2].split()
+ a=lines[2].decode().split()
dat[a[0]]=float(a[1])
- a=lines[3].split()
+ a=lines[3].decode().split()
dat[a[0]]=float(a[1])
- a=lines[4].split()
+ a=lines[4].decode().split()
dat[a[0]]=float(a[1])
a=[]
diff --git a/geodat/import_gpx.py b/geodat/import_gpx.py
index d584f4f..11da627 100644
--- a/geodat/import_gpx.py
+++ b/geodat/import_gpx.py
@@ -1,43 +1,56 @@
# -*- coding: utf-8 -*-
-#-------------------------------------------------
-#-- gpx importer
-#--
-#-- microelly 2016 v 0.0
-#--
-#-- GNU Lesser General Public License (LGPL)
-#-------------------------------------------------
+# -------------------------------------------------
+# -- gpx importer
+# --
+# -- microelly 2016 v 0.0
+# --
+# -- GNU Lesser General Public License (LGPL)
+# -------------------------------------------------
'''gpx path importer'''
-##\cond
-
+# \cond
+import pivy
+from pivy import coin
+import sys
+import FreeCAD
+import FreeCADGui
+import Part
+import Draft
+from geodat.transversmercator import TransverseMercator
+from geodat.xmltodict import parse
from geodat.say import *
+import time
+import json
+import os
+
+import geodat.inventortools
# test-data from https://en.wikipedia.org/wiki/GPS_Exchange_Format
-trackstring='''
+trackstring = '''
-
- Garmin International
-
-
+
+ Garmin International
+
+
- Example GPX Document
-
-
- 4.46
-
-
-
- 4.94
-
-
-
- 6.87
-
-
-
+ Example GPX Document
+
+
+ 4.46
+
+
+
+ 4.94
+
+
+
+ 6.87
+
+
+
'''
@@ -45,336 +58,179 @@
# https://de.wikipedia.org/wiki/GPS_Exchange_Format
'''
- xsd:decimal
-
- degreesType
- xsd:decimal
- xsd:string
- xsd:string
- xsd:string
- xsd:string
- linkType
- xsd:string
- xsd:string
- fixType
- xsd:nonNegativeInteger
- xsd:decimal
- xsd:decimal
- xsd:decimal
+ xsd:decimal
+
+ degreesType
+ xsd:decimal
+ xsd:string
+ xsd:string
+ xsd:string
+ xsd:string
+ linkType
+ xsd:string
+ xsd:string
+ fixType
+ xsd:nonNegativeInteger
+ xsd:decimal
+ xsd:decimal
+ xsd:decimal xsd:decimal dgpsStationType:integer
- extensionsType
+ extensionsType
'''
-import time, json, os
-
-import sys
-if sys.version_info[0] !=2:
+if sys.version_info[0] != 2:
from importlib import reload
-import pivy
-from pivy import coin
-import FreeCAD,FreeCADGui, Part
-App=FreeCAD
-Gui=FreeCADGui
+App = FreeCAD
+Gui = FreeCADGui
-import geodat.transversmercator
-from geodat.transversmercator import TransverseMercator
+debug = False
-import geodat.inventortools
-import geodat.xmltodict
-from geodat.xmltodict import parse
+global sd
-import time
-debug=0
+# \endcond
+import re
+def import_gpx(filename, orig, hi):
+ '''import a gpx trackfile'''
+
+ global sd
+ f = open(filename, "r")
+ c1 = f.read()
+ content = re.sub('^\<\?[^\>]+\?\>', '', c1)
+ print(content)
+ tm = TransverseMercator()
-global sd
+ # outdoor inn ...
+ tm.lat, tm.lon = 50.3736049, 11.191643
-##\endcond
+ if orig != 'auto':
+ yy = orig.split(',')
+ origin = (float(yy[0]), float(yy[1]))
+ tm.lat = origin[0]
+ tm.lon = origin[1]
-def import_gpx(filename,orig,hi):
- '''import a gpx trackfile'''
+ sd = parse(content)
- global sd
- # content=trackstring
-
-# fn='/home/microelly2/FCB/b202_gmx_tracks/im_haus.gpx'
-# filename='/home/microelly2/FCB/b202_gmx_tracks/neufang.gpx'
-
-
- f=open(filename,"r")
- c1=f.read()
- import re
- content = re.sub('^\<\?[^\>]+\?\>', '', c1)
- print(content)
+ if debug:
+ print(json.dumps(sd, indent=4))
+ points = []
+ points2 = []
+ points0 = []
+ px = []
+ py = []
+ pz = []
+ pt = []
- tm=TransverseMercator()
+ startx = None
+ starty = None
+ starth = None
+ FreeCAD.sd = sd
+ seg = sd['gpx']['trk']['trkseg']
- # outdoor inn ...
- tm.lat,tm.lon = 50.3736049,11.191643
-
- if orig!='auto':
- yy=orig.split(',')
- origin=(float(yy[0]),float(yy[1]))
- tm.lat=origin[0]
- tm.lon=origin[1]
-# center=tm.fromGeographic(tm.lat,tm.lon)
-
- sd=parse(content)
- if debug: print(json.dumps(sd, indent=4))
-
- points=[]
- points2=[]
- points0=[]
- px=[]
- py=[]
- pz=[]
- pt=[]
-
- startx=None
- starty=None
- starth=None
- FreeCAD.sd=sd
- seg=sd['gpx']['trk']['trkseg']
try:
seg['trkpt']
- ss=seg
- seg=[ss]
+ ss = seg
+ seg = [ss]
+
except:
pass
- lats=[]
- lons=[]
+
+ lats = []
+ lons = []
for s in seg:
- trkpts=s['trkpt']
+ trkpts = s['trkpt']
+
for n in trkpts:
lats.append(float(n['@lat']))
lons.append(float(n['@lon']))
- print (min(lats),max(lats))
- print (min(lons),max(lons))
- print ((max(lats)+min(lats))/2,(max(lons)+min(lons))/2)
- print ((max(lats)-min(lats))/2,(max(lons)-min(lons))/2)
+ print(min(lats), max(lats))
+ print(min(lons), max(lons))
+ print((max(lats)+min(lats))/2, (max(lons)+min(lons))/2)
+ print((max(lats)-min(lats))/2, (max(lons)-min(lons))/2)
if orig == 'auto':
- tm.lat, tm.lon = (max(lats)+min(lats))/2,(max(lons)+min(lons))/2
+ tm.lat, tm.lon = (max(lats)+min(lats))/2, (max(lons)+min(lons))/2
print("origin:")
- print(tm.lat,tm.lon)
- print ("----------")
-
-
+ print(tm.lat, tm.lon)
+ print("----------")
for s in seg:
- trkpts=s['trkpt']
-
-
- n=trkpts[0]
-
- center=tm.fromGeographic(tm.lat,tm.lon)
-
-# print(trkpts)
-# for p in trkpts:
-# print(p)
+ trkpts = s['trkpt']
+ n = trkpts[0]
+ center = tm.fromGeographic(tm.lat, tm.lon)
# map all points to xy-plane
for n in trkpts:
-# print(n['@lat'],n['@lon'])
lats.append(float(n['@lat']))
lons.append(float(n['@lon']))
- ll=tm.fromGeographic(float(n['@lat']),float(n['@lon']))
- h=n['ele']
-# print(h)
- tim=n['time']
- t2=re.sub('^.*T', '', tim)
- t3=re.sub('Z', '', t2)
- t4=t3.split(':')
- timx=int(t4[0])*3600+int(t4[1])*60+int(t4[2])
+ ll = tm.fromGeographic(float(n['@lat']), float(n['@lon']))
+ h = n['ele']
+ tim = n['time']
+ t2 = re.sub('^.*T', '', tim)
+ t3 = re.sub('Z', '', t2)
+ t4 = t3.split(':')
+ timx = int(t4[0])*3600+int(t4[1])*60+int(t4[2])
pt.append(timx)
+
if starth == None:
- starth=float(h)
- starth=0
-
- points.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],1000*(float(h)-starth)))
- points.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],0))
- points.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],1000*(float(h)-starth)))
- points2.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],1000*(float(h)-starth)+20000))
- points0.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],0))
+ starth = float(h)
+ starth = 0
+
+ points.append(FreeCAD.Vector(ll[0]-center[0], ll[1]-center[1], 1000*(float(h)-starth)))
+ points.append(FreeCAD.Vector(ll[0]-center[0], ll[1]-center[1], 0))
+ points.append(FreeCAD.Vector(ll[0]-center[0], ll[1]-center[1], 1000*(float(h)-starth)))
+ points2.append(FreeCAD.Vector(ll[0]-center[0], ll[1]-center[1], 1000*(float(h)-starth)+20000))
+ points0.append(FreeCAD.Vector(ll[0]-center[0], ll[1]-center[1], 0))
px.append(ll[0]-center[0])
py.append(ll[1]-center[1])
pz.append(1000*(float(h)-starth))
-# print(ll)
+ Draft.makeWire(points0)
- if 1:
- import Draft
- if 0: #close path
- points.append(points[0])
-
-
-
- Draft.makeWire(points0)
-
- Draft.makeWire(points)
-
- po=App.ActiveDocument.ActiveObject
- po.ViewObject.LineColor=(1.0,.0,0.0)
- po.MakeFace = False
+ Draft.makeWire(points)
- po.Placement.Base.z= float(hi) *1000
- po.Label="My Track"
+ po = App.ActiveDocument.ActiveObject
+ po.ViewObject.LineColor = (1.0, 0.0, 0.0)
+ po.MakeFace = False
- Draft.makeWire(points2)
+ po.Placement.Base.z = float(hi) * 1000
+ po.Label = "My Track"
- po2=App.ActiveDocument.ActiveObject
- po2.ViewObject.LineColor=(.0,.0,1.0)
- po2.ViewObject.PointSize=5
- po2.ViewObject.PointColor=(.0,1.0,1.0)
-
- po2.Placement.Base.z= float(hi)*1000
- po2.Label="Track + 20m"
+ Draft.makeWire(points2)
+ po2 = App.ActiveDocument.ActiveObject
+ po2.ViewObject.LineColor = (0.0, 0.0, 1.0)
+ po2.ViewObject.PointSize = 5
+ po2.ViewObject.PointColor = (0.0, 1.0, 1.0)
- App.activeDocument().recompute()
- Gui.SendMsgToActiveView("ViewFit")
- # break
+ po2.Placement.Base.z = float(hi)*1000
+ po2.Label = "Track + 20m"
- #------------------------------------------------
- # data for postprocessing
- return
-
- try:
- import numpyNode
- import mathplotlibNode
-
- t=mathplotlibNode.createMPL()
- t.Label="My Track raw Data"
-
- # hier werte bereitstellen
- t.countSources=4
- t.source1Values=px
- t.source2Values=py
- t.source3Values=pz
- t.source4Values=pt
-
- t.source1Data="px"
- t.source2Data="py"
- t.source3Data="pz"
- t.source4Data="pt"
-
- t.useOut1=True
- t.useOut2=True
- t.useOut3=True
- t.useOut4=True
-
- # werte umrechnen
- t2=numpyNode.createNP()
- t2.Label="My Track data processed"
- t2.sourceObject=t
- t2.expression1="in1/np.max(np.abs(in1))"
- t2.label1 = "x relative"
-
- t2.expression2="in2/np.max(np.abs(in2))"
- t2.label2 = "y relative"
-
- t2.expression3="in3/np.max(np.abs(in3))"
- t2.label3 = "z relative"
-
- t2.expression4="-1+2*(in4-np.min(in4))/(np.max(in4)-np.min(in4))"
- t2.label4 = "time relative"
-
- # werte grafisch darstellen
- t3=mathplotlibNode.createMPL()
- t3.Label="My Track Data visualization"
- t3.record=False
- t3.useNumpy=True
- t3.sourceNumpy=t2
-
- t3.useOut1=True
- t3.useOut2=True
- t3.useOut3=True
- t3.useOut4=True
-
- t4=numpyNode.createNP()
- t4.Label="My Track Data xy"
- t4.sourceObject=t
-
- t4.expression2="in2"
- t4.label2 = "path xy"
-
- t4.expressionTime="in1"
-
- t5=mathplotlibNode.createMPL()
- t5.Label="My Track Data xy Map"
- t5.record=False
- t5.useNumpy=True
- t5.sourceNumpy=t4
-
- t5.useOut2=True
- FreeCAD.ActiveDocument.recompute()
- except:
- sayexc()
+ App.activeDocument().recompute()
+ Gui.SendMsgToActiveView("ViewFit")
- return (str(tm.lat)+','+str(tm.lon))
- return px,py
-'''
-if 0:
- px,py=import_gpx()
- count=len(px)
- pp=range(count)
- px2=[]
- py2=[]
-
- import numpy as np
- xpp=np.array(px)
- np.average(xpp)
- std=np.std(xpp)
-
- for p in pp:
- if abs(px[p]) <2*std:
- px2.append(px[p])
- else:
- if px[p]>0:
- px2.append(2*std)
- else:
- px2.append(-2*std)
-
- for p in pp:
- if abs(py[p]) <10000:
- py2.append(py[p])
- else:
- py2.append(10000.0)
-
-
- import matplotlib.pyplot as plt
-
- #plt.plot(pp,px,pp,py)
- #plt.show()
-
- plt.hist(px2)
- # plt.hist(py2)
- #plt.show()
-
-
-# px,py=import_gpx()
-'''
+ return str(tm.lat)+','+str(tm.lon)
-s6='''
+s6 = '''
MainWindow:
VerticalLayout:
id:'main'
QtGui.QLabel:
- setText:"*** I M P O R T GPX T R A C K ***"
+ setText:"*** I M P O R T GPX T R A C K ***"
QtGui.QLabel:
QtGui.QLabel:
@@ -416,68 +272,73 @@ def import_gpx(filename,orig,hi):
'''
-## Gui backend
-
+# Gui backend
class MyApp(object):
- '''the execution layer of import_gpx'''
+ """
+ The execution layer of import_gpx
+ """
def run(self):
- '''calls import_gpx'''
- filename=self.root.ids['bl'].text()
+ """
+ Calls import_gpx
+ """
+
+ filename = self.root.ids['bl'].text()
if filename.startswith('UserAppData'):
- filename=filename.replace('UserAppData',FreeCAD.ConfigGet("UserAppData"))
+ filename = filename.replace('UserAppData', FreeCAD.ConfigGet("UserAppData"))
try:
- rc=import_gpx(
- filename,
- self.root.ids['orig'].text(),
- self.root.ids['h'].text(),
+ rc = import_gpx(
+ filename,
+ self.root.ids['orig'].text(),
+ self.root.ids['h'].text(),
)
self.root.ids['orig'].setText(rc),
+
except:
- sayexc()
+ sayexc()
def getfn(self):
- ''' get the filename of the track'''
- fileName = QtGui.QFileDialog.getOpenFileName(None,u"Open File",u"/tmp/");
+ """
+ Get the filename of the track
+ """
+
+ fileName = QtGui.QFileDialog.getOpenFileName(None, u"Open File", u"/tmp/")
print(fileName)
- s=self.root.ids['bl']
+ s = self.root.ids['bl']
s.setText(fileName[0])
-## the dialog to import the file
+# the dialog to import the file
def mydialog():
- ''' the dialog to import the file'''
- app=MyApp()
+ """
+ The dialog to import the file
+ """
+
+ app = MyApp()
import geodat
import geodat.miki as miki
reload(miki)
- miki=miki.Miki()
- miki.app=app
- app.root=miki
+ miki = miki.Miki()
+ miki.app = app
+ app.root = miki
miki.parse2(s6)
miki.run(s6)
return miki
-## tst open and hide dialog
+# tst open and hide dialog
def runtest():
- m=mydialog()
+ m = mydialog()
m.objects[0].hide()
-
def importGPXTrack():
- m=mydialog()
+ m = mydialog()
+
if __name__ == '__main__':
runtest()
-
-
-
-
-
-
diff --git a/geodat/import_heights.py b/geodat/import_heights.py
index 00bbeb2..f342c9e 100644
--- a/geodat/import_heights.py
+++ b/geodat/import_heights.py
@@ -8,8 +8,8 @@
#-- GNU Lesser General Public License (LGPL)
#-------------------------------------------------
-import FreeCAD,FreeCADGui
import FreeCAD, FreeCADGui, Draft
+from geodat.say import *
import sys
if sys.version_info[0] !=2:
@@ -24,9 +24,9 @@
import geodat.transversmercator
from geodat.transversmercator import TransverseMercator
-import inventortools
+from . import inventortools
+
-from geodat.say import *
#\cond
tm=TransverseMercator()
@@ -43,13 +43,15 @@
'''
def getheight(b,l):
- source="https://maps.googleapis.com/maps/api/elevation/json?locations="+str(b)+','+str(l)
+ #source="https://maps.googleapis.com/maps/api/elevation/json?locations="+str(b)+','+str(l)
+ source="https://api.open-elevation.com/api/v1/lookup?locations="+str(b)+','+str(l)
say(source)
try:
import urllib2
response = urllib2.urlopen(source)
except:
+ import urllib
response = urllib.request.urlopen(source)
ans=response.read()
@@ -66,7 +68,7 @@ def getheight(b,l):
return round(r['elevation']*1000,2)
-## download the heights from google
+## download the heights from open-elevation
def run(b0=50.35,l0=11.17,b=50.35,le=11.17,size=40):
@@ -83,43 +85,26 @@ def run(b0=50.35,l0=11.17,b=50.35,le=11.17,size=40):
for i in range(-size,size):
bb=b+i*0.001
ss=str(bb)+','+str(le)
- if i < size -1:
- ss += '|'
source += ss
- try:
- import urllib2
- response = urllib2.urlopen(source)
- except:
- response = urllib.request.urlopen(source)
-
- #+# to do: error handling - wait and try again
- ans=response.read()
-# say(ans)
-# say("--------")
- s=json.loads(ans)
- say(s)
-
-
- if s['status']=='REQUEST_DENIED':
- say("Fehler-aBBruch")
- return
- else:
- print(ans)
- s=json.loads(ans)
- res=s['results']
-
- points=[]
- for r in res:
- c=tm.fromGeographic(r['location']['lat'],r['location']['lng'])
- v=FreeCAD.Vector(
- round((c[0]-center[0]),2),
- round((c[1]-center[1]),2),
- round(r['elevation']*1000,2)-baseheight
- )
- points.append(v)
+ import json
+ from urllib import request
+ response = request.urlopen(source)
+ s=json.loads(response.read())
+
+ res = s['results']
+ points=[]
+ for r in res:
+ c=tm.fromGeographic(r['location']['lat'],r['location']['lng'])
+ v=FreeCAD.Vector(
+ round((c[0]-center[0]),2),
+ round((c[1]-center[1]),2),
+ round(r['elevation']*1000,2)-baseheight
+ )
+ points.append(v)
+
Draft.makeWire(points,closed=False,face=False,support=None)
FreeCAD.activeDocument().recompute()
FreeCADGui.updateGui()
diff --git a/geodat/import_latlony.py b/geodat/import_latlony.py
index 10d738e..73d16bc 100644
--- a/geodat/import_latlony.py
+++ b/geodat/import_latlony.py
@@ -87,7 +87,7 @@
from geodat.xmltodict import parse
import time
-debug=0
+debug = False
import numpy as np
@@ -129,7 +129,7 @@ def import_latlon(filename,orig,hi):
FreeCAD.c=c1
vals=np.array([float(c) for c in c1.split()])
- vals=vals.reshape(len(vals)/3,3)
+ #vals=vals.reshape(len(vals)/3,3)
'''
points=[]
points2=[]
@@ -396,7 +396,7 @@ def import_latlon(filename,orig,hi):
setText:"Track input filename"
QtGui.QLineEdit:
- setText:"{}Mod/geodat/testdata/latlonh.txt"
+ setText:"UserAppData/Mod/geodat/testdata/latlonh.txt"
id: 'bl'
QtGui.QPushButton:
diff --git a/geodat/import_osm.py b/geodat/import_osm.py
index ed2fb9f..c5e3186 100644
--- a/geodat/import_osm.py
+++ b/geodat/import_osm.py
@@ -1,274 +1,218 @@
# -*- coding: utf-8 -*-
-#-------------------------------------------------
-#-- osm map importer
-#--
-#-- microelly 2016 v 0.4
-#--
-#-- GNU Lesser General Public License (LGPL)
-#-------------------------------------------------
-'''import data from openstreetmap'''
-
-
-#http://api.openstreetmap.org/api/0.6/map?bbox=11.74182,50.16413,11.74586,50.16561
-#http://api.openstreetmap.org/api/0.6/way/384013089
-#http://api.openstreetmap.org/api/0.6/node/3873106739
-
-#\cond
+# -------------------------------------------------
+# -- osm map importer
+# --
+# -- microelly 2016 v 0.4
+# --
+# -- GNU Lesser General Public License (LGPL)
+# -------------------------------------------------
+"""
+Import data from OpenStreetMap
+"""
+
+
+# http://api.openstreetmap.org/api/0.6/map?bbox=11.74182,50.16413,11.74586,50.16561
+# http://api.openstreetmap.org/api/0.6/way/384013089
+# http://api.openstreetmap.org/api/0.6/node/3873106739
+
+# \cond
+# \endcond
+import WebGui
+import re
+import FreeCAD
+import FreeCADGui
+import WebGui
+import Part
+from pivy import coin
+from geodat import my_xmlparser
+from geodat.transversmercator import TransverseMercator
+import geodat.inventortools as inventortools
from geodat.say import *
+import geodat.xmltodict
+from geodat.xmltodict import parse
-import time, json, os
+import time
+import json
+import os
import sys
-if sys.version_info[0] !=2:
+if sys.version_info[0] != 2:
from importlib import reload
import urllib.request
-from say import *
-
-import time, json, os
-
try:
import urllib2
except:
import urllib
-import pivy
-from pivy import coin
-
+debug = False
-import geodat.my_xmlparser
-reload (geodat.my_xmlparser)
+# ------------------------------
+#
+# microelly 2016 ..
+#
+# ------------------------------
-import geodat.transversmercator
-from geodat.transversmercator import TransverseMercator
+# get the elevation height of a single point
+def getHeight(b, l):
+ """
+ Get height of a single point with latitude b, longitude l
+ """
-import geodat.inventortools as inventortools
+ anz = 0
-import geodat.xmltodict
-from geodat.xmltodict import parse
-#\endcond
+ while anz < 4:
+ source = "https://maps.googleapis.com/maps/api/elevation/json?locations="+str(b)+','+str(l)
+ try:
+ response = urllib2.urlopen(source)
+ except:
+ response = urllib.request.urlopen(source)
+ ans = response.read()
-#------------------------------
-#
-# microelly 2016 ..
-#
-#------------------------------
+ if ans.find("OVER_QUERY_LIMIT"):
+ anz += 1
+ time.sleep(5)
-import time
+ else:
+ anz = 10
+ s = json.loads(ans)
+ res = s['results']
-## get the elevation height of a single point
-def getHeight(b,l):
- ''' get height of a single point with latitude b, longitude l'''
- anz=0
- while anz<4:
- source="https://maps.googleapis.com/maps/api/elevation/json?locations="+str(b)+','+str(l)
- try:
- response = urllib2.urlopen(source)
- except:
- response = urllib.request.urlopen(source)
- ans=response.read()
- if ans.find("OVER_QUERY_LIMIT"):
- anz += 1
- time.sleep(5)
- else:
- anz=10
- s=json.loads(ans)
- res=s['results']
for r in res:
- return round(r['elevation']*1000,2)
+ return round(r['elevation']*1000, 2)
-## get the heights for a list of points
+# get the heights for a list of points
def getHeights(points):
- ''' get heights for a list of points'''
- i=0
- size=len(points)
- while i0:
+ """
+ Get heights for a list of points
+ """
+
+ i = 0
+ size = len(points)
+
+ while i < size:
+ source = "https://maps.googleapis.com/maps/api/elevation/json?locations="
+ ii = 0
+
+ if i > 0:
time.sleep(1)
+
while ii < 20 and i < size:
- p=points[i]
- ss= p[1]+','+p[2] + '|'
+ p = points[i]
+ ss = p[1]+','+p[2] + '|'
source += ss
i += 1
ii += 1
+
source += "60.0,10.0"
response = urllib.request.urlopen(source)
- ans=response.read()
- s=json.loads(ans)
- res=s['results']
- heights= {}
+ ans = response.read()
+ s = json.loads(ans)
+ res = s['results']
+ heights = {}
+
for r in res:
- key="%0.7f" %(r['location']['lat']) + " " + "%0.7f" %(r['location']['lng'])
- heights[key]=r['elevation']
+ key = "%0.7f" % (r['location']['lat']) + " " + "%0.7f" % (r['location']['lng'])
+ heights[key] = r['elevation']
+
return heights
def organize():
- '''create groups for the different object types
+ """
+ Create groups for the different object types
GRP_highways, GRP_building, GRP_landuse
- '''
- highways=App.activeDocument().addObject("App::DocumentObjectGroup","GRP_highways")
- landuse=App.activeDocument().addObject("App::DocumentObjectGroup","GRP_landuse")
- buildings=App.activeDocument().addObject("App::DocumentObjectGroup","GRP_building")
- pathes=App.activeDocument().addObject("App::DocumentObjectGroup","GRP_pathes")
+ """
+
+ highways = App.activeDocument().addObject("App::DocumentObjectGroup", "GRP_highways")
+ landuse = App.activeDocument().addObject("App::DocumentObjectGroup", "GRP_landuse")
+ buildings = App.activeDocument().addObject("App::DocumentObjectGroup", "GRP_building")
+ pathes = App.activeDocument().addObject("App::DocumentObjectGroup", "GRP_pathes")
for oj in App.activeDocument().Objects:
if oj.Label.startswith('building'):
buildings.addObject(oj)
- # oj.ViewObject.Visibility=False
+
if oj.Label.startswith('highway') or oj.Label.startswith('way'):
highways.addObject(oj)
- oj.ViewObject.Visibility=False
+ oj.ViewObject.Visibility = False
+
if oj.Label.startswith('landuse'):
landuse.addObject(oj)
- oj.ViewObject.Visibility=False
+ oj.ViewObject.Visibility = False
+
if oj.Label.startswith('w_'):
pathes.addObject(oj)
- oj.ViewObject.Visibility=False
-
-#---------------------
-from geodat.say import *
-import re
-
-#fn='/home/thomas/.FreeCAD//geodat3/50.340722-11.232647-0.015'
-#fn='/home/thomas/.FreeCAD/system.cfg'
-
-debug=False
-
-
-
-#--------------------
+ oj.ViewObject.Visibility = False
-## core method to download and import the data
+# core method to download and import the data
#
-#def import_osm(b,l,bk,progressbar,status):
+# def import_osm(b,l,bk,progressbar,status):
# import_osm2(b,l,bk,progressbar,status,False)
-def import_osm2(b,l,bk,progressbar,status,elevation):
+def import_osm2(b, l, bk, progressbar, status, elevation):
-
- dialog=False
- debug=False
+ dialog = False
if progressbar:
- progressbar.setValue(0)
+ progressbar.setValue(0)
if status:
status.setText("get data from openstreetmap.org ...")
FreeCADGui.updateGui()
- content=''
- bk=0.5*bk
- dn=FreeCAD.ConfigGet("UserAppData") + "/geodat3/"
- fn=dn+str(b)+'-'+str(l)+'-'+str(bk)
+ content = ''
+
+ bk = 0.5*bk
+ dn = FreeCAD.ConfigGet("UserAppData") + "geodat3/"
+ fn = dn+str(b)+'-'+str(l)+'-'+str(bk)
import os
+
if not os.path.isdir(dn):
os.makedirs(dn)
-
try:
say("I try to read data from cache file ... ")
say(fn)
- f=open(fn,"r")
- content=f.read()
- # say(content)
- # raise Exception("to debug:force load from internet")
+ f = open(fn, "r")
+ content = f.read()
+
except:
sayW("no cache file, so I connect to openstreetmap.org...")
- lk=bk #
- b1=b-bk/1113*10
- l1=l-lk/713*10
- b2=b+bk/1113*10
- l2=l+lk/713*10
- source='http://api.openstreetmap.org/api/0.6/map?bbox='+str(l1)+','+str(b1)+','+str(l2)+','+str(b2)
+ lk = bk
+ b1 = b-bk/1113*10
+ l1 = l-lk/713*10
+ b2 = b+bk/1113*10
+ l2 = l+lk/713*10
+ source = 'http://api.openstreetmap.org/api/0.6/map?bbox='+str(l1)+','+str(b1)+','+str(l2)+','+str(b2)
say(source)
import requests
response = requests.get(source)
data = response.text
- lines=response.text.split('\n')
- FreeCAD.t=response
-
-
- f=open(fn,"w")
+ lines = response.text.split('\n')
+ FreeCAD.t = response
+
+ f = open(fn, "w")
# f.write(response.text)
if response.status_code == 200:
with open(fn, 'wb') as f:
for chunk in response.iter_content(1024):
f.write(chunk)
f.close()
-# print("huhu");return
-
-
- if 0:
- try:
- say("read--")
- response = urllib.request.urlopen(source)
- #import ssl
- #ssl._create_default_https_context = ssl._create_unverified_context
- #response = urllib.request.urlopen(source)
-
- # import requests
- # response = requests.get(source)
-
- say(response)
- say("2huu")
- first=True
- content=''
- f=open(fn,"w")
- l=0
- z=0
- ct=0
-
- say("2wkkw")
- #say(response.text)
- # lines=response.text.split('\n')
- # say(len(lines))
- say("ll")
- # for line in lines:
- for line in response:
- print ("Y",line)
- if status:
- if z>5000:
- status.setText("read data ..." + str(l))
- z=0
- FreeCADGui.updateGui()
- l+=1
- z+=1
- if first:
- first=False
- else:
- content += line
- f.write(line)
- f.close()
- if status:
- status.setText("FILE CLOSED ..." + str(l))
- FreeCADGui.updateGui()
- response.close()
- except:
- sayErr( "Fehler beim Lesen")
-
- if status:
- status.setText("got data from openstreetmap.org ...")
- FreeCADGui.updateGui()
- sayW("Beeenden - im zweiten versuch daten auswerten")
-
- return False
-
if elevation:
- baseheight=getHeight(b,l)
+ baseheight = getHeight(b, l)
+
else:
- baseheight=0
+ baseheight = 0
if debug:
- say( "-------Data---------")
+ say("-------Data---------")
say(content)
if status:
@@ -278,90 +222,43 @@ def import_osm2(b,l,bk,progressbar,status,elevation):
say("------------------------------")
say(fn)
-# fn='/home/thomas/.FreeCAD//geodat3/50.340722-11.232647-0.015'
say(fn)
+ tree = my_xmlparser.getData(fn)
- tree=geodat.my_xmlparser.getData(fn)
-
-# for element in tree.getiterator('node'):
-# say(element.params)
-
-# say("ways")
-# for element in tree.getiterator('way'):
-# say(element.params)
-# say("relations")
-# for element in tree.getiterator('relation'):
-# say(element.params)
-
-
-
-
- if 0:
- try:
- sd=parse(content)
- except:
- sayexc("Problem parsing data - abort")
- status.setText("Problem parsing data - aborted, for details see Report view")
- return
-
- if debug: say(json.dumps(sd, indent=4))
+ if debug:
+ say(json.dumps(sd, indent=4))
if status:
status.setText("transform data ...")
FreeCADGui.updateGui()
- relations=tree.getiterator('relation')
- nodes=tree.getiterator('node')
- ways=tree.getiterator('way')
- bounds=tree.getiterator('bounds')[0]
+ relations = tree.getiterator('relation')
+ nodes = tree.getiterator('node')
+ ways = tree.getiterator('way')
+ bounds = tree.getiterator('bounds')[0]
# center of the scene
- minlat=float(bounds.params['minlat'])
- minlon=float(bounds.params['minlon'])
- maxlat=float(bounds.params['maxlat'])
- maxlon=float(bounds.params['maxlon'])
+ minlat = float(bounds.params['minlat'])
+ minlon = float(bounds.params['minlon'])
+ maxlat = float(bounds.params['maxlat'])
+ maxlon = float(bounds.params['maxlon'])
- tm=TransverseMercator()
- tm.lat=0.5*(minlat+maxlat)
- tm.lon=0.5*(minlon+maxlon)
+ tm = TransverseMercator()
+ tm.lat = 0.5*(minlat+maxlat)
+ tm.lon = 0.5*(minlon+maxlon)
- center=tm.fromGeographic(tm.lat,tm.lon)
- corner=tm.fromGeographic(minlat,minlon)
- size=[center[0]-corner[0],center[1]-corner[1]]
+ center = tm.fromGeographic(tm.lat, tm.lon)
+ corner = tm.fromGeographic(minlat, minlon)
+ size = [center[0]-corner[0], center[1]-corner[1]]
# map all points to xy-plane
- points={}
- nodesbyid={}
- for n in nodes:
- nodesbyid[n.params['id']]=n
- ll=tm.fromGeographic(float(n.params['lat']),float(n.params['lon']))
- points[str(n.params['id'])]=FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],0.0)
-
-# say(points)
-# say("abbruch3 -hier daten uebernehmen !!");return
-
- # hack to catch deutsche umlaute
- def beaustring(string):
- res=''
- for tk in zz:
- try:
- res += str(tk)
- except:
+ points = {}
+ nodesbyid = {}
- if ord(tk)==223:
- res += 'ß'
- elif ord(tk)==246:
- res += 'ö'
- elif ord(tk)==196:
- res += 'Ä'
- elif ord(tk)==228:
- res += 'ä'
- elif ord(tk)==242:
- res += 'ü'
- else:
- sayErr(["error sign",tk,ord(tk),string])
- res +="#"
- return res
+ for n in nodes:
+ nodesbyid[n.params['id']] = n
+ ll = tm.fromGeographic(float(n.params['lat']), float(n.params['lon']))
+ points[str(n.params['id'])] = FreeCAD.Vector(ll[0]-center[0], ll[1]-center[1], 0.0)
if status:
status.setText("create visualizations ...")
@@ -369,20 +266,22 @@ def beaustring(string):
App.newDocument("OSM Map")
say("Datei erzeugt")
- area=App.ActiveDocument.addObject("Part::Plane","area")
+ area = App.ActiveDocument.addObject("Part::Plane", "area")
obj = FreeCAD.ActiveDocument.ActiveObject
say("grundflaeche erzeugt")
+
try:
viewprovider = obj.ViewObject
- root=viewprovider.RootNode
+ root = viewprovider.RootNode
myLight = coin.SoDirectionalLight()
- myLight.color.setValue(coin.SbColor(0,1,0))
+ myLight.color.setValue(coin.SbColor(0, 1, 0))
root.insertChild(myLight, 0)
say("beleuchtung auf grundobjekt eingeschaltet")
+
except:
sayexc("Beleuchtung 272")
- cam='''#Inventor V2.1 ascii
+ cam = '''#Inventor V2.1 ascii
OrthographicCamera {
viewportMapping ADJUST_CAMERA
orientation 0 0 -1.0001 0.001
@@ -391,230 +290,209 @@ def beaustring(string):
aspectRatio 100
focalDistance 1
'''
- x=0
- y=0
- height=1000000
- height=200*bk*10000/0.6
- cam += '\nposition ' +str(x) + ' ' + str(y) + ' 999\n '
+ x = 0
+ y = 0
+ height = 200*bk*10000/0.6
+ cam += '\nposition ' + str(x) + ' ' + str(y) + ' 999\n '
cam += '\nheight ' + str(height) + '\n}\n\n'
FreeCADGui.activeDocument().activeView().setCamera(cam)
FreeCADGui.activeDocument().activeView().viewAxonometric()
say("Kamera gesetzt")
- area.Length=size[0]*2
- area.Width=size[1]*2
- area.Placement=FreeCAD.Placement(FreeCAD.Vector(-size[0],-size[1],0.00),FreeCAD.Rotation(0.00,0.00,0.00,1.00))
+ area.Length = size[0]*2
+ area.Width = size[1]*2
+ area.Placement = FreeCAD.Placement(FreeCAD.Vector(-size[0], -size[1], 0.00), FreeCAD.Rotation(0.00, 0.00, 0.00, 1.00))
say("Area skaliert")
- wn=-1
- coways=len(ways)
- starttime=time.time()
- refresh=1000
- for w in ways:
- wid=w.params['id']
-
-# say(w.params)
-# say("way content")
-# for c in w.content:
-# say(c)
+ wn = -1
+ coways = len(ways)
+ starttime = time.time()
+ refresh = 1000
- building=False
- landuse=False
- highway=False
+ for w in ways:
+ wid = w.params['id']
+ building = False
+ landuse = False
+ highway = False
wn += 1
- # nur teile testen
- #if wn <2000: continue
+ nowtime = time.time()
+
+ if wn != 0 and (nowtime-starttime)/wn > 0.5:
+ say(("way ---- # " + str(wn) + "/" + str(coways) + " time per house: " + str(round((nowtime-starttime)/wn, 2))))
- nowtime=time.time()
- if wn!=0 and (nowtime-starttime)/wn > 0.5:
- say(("way ---- # " + str(wn) + "/" + str(coways) + " time per house: " + str(round((nowtime-starttime)/wn,2))))
if progressbar:
progressbar.setValue(int(0+100.0*wn/coways))
- st=""
- st2=""
- nr=""
- h=0
- ci=""
+ st = ""
+ st2 = ""
+ nr = ""
+ h = 0
+ ci = ""
for t in w.getiterator('tag'):
- try:
- if debug: say(t)
-# say(t.params['k'])
-# say(t.params['v'])
-
- if str(t.params['k'])=='building':
- building=True
- if st == '':
- st='building'
-
- if str(t.params['k'])=='landuse':
- landuse=True
- st=t.params['k']
- nr=t.params['v']
-
- if str(t.params['k'])=='highway':
- highway=True
- st=t.params['k']
-
- if str(t.params['k'])=='addr:city':
- ci=t.params['v']
-
- if str(t.params['k'])=='name':
- zz=t.params['v']
- nr=beaustring(zz)
- if str(t.params['k'])=='ref':
- zz=t.params['v']
- nr=beaustring(zz)+" /"
-
- if str(t.params['k'])=='addr:street':
- zz=t.params['v']
- st2=" "+beaustring(zz)
- if str(t.params['k'])=='addr:housenumber':
- nr=str(t.params['v'])
-
- if str(t.params['k'])=='building:levels':
- if h==0:
- h=int(str(t.params['v']))*1000*3
- if str(t.params['k'])=='building:height':
- h=int(str(t.params['v']))*1000
+ try:
+ if str(t.params['k']) == 'building':
+ building = True
- except:
- sayErr("unexpected error ######################################################")
+ if st == '':
+ st = 'building'
+
+ if str(t.params['k']) == 'landuse':
+ landuse = True
+ st = t.params['k']
+ nr = t.params['v']
+
+ if str(t.params['k']) == 'highway':
+ highway = True
+ st = t.params['k']
+
+ if str(t.params['k']) == 'addr:city':
+ ci = t.params['v']
+
+ if str(t.params['k']) == 'name':
+ nr = t.params['v']
+
+ if str(t.params['k']) == 'ref':
+ nr = t.params['v']+" /"
+
+ if str(t.params['k']) == 'addr:street':
+ st2 = " "+t.params['v']
- name=str(st) + " " + str(nr)
- name=str(st) + st2+ " " + str(nr)
- if name==' ':
- name='landuse xyz'
- if debug: say(("name ",name))
- #say(name,zz,nr,ci)
+ if str(t.params['k']) == 'addr:housenumber':
+ nr = str(t.params['v'])
- #generate pointlist of the way
- polis=[]
- height=None
+ if str(t.params['k']) == 'building:levels':
+ if h == 0:
+ h = int(str(t.params['v']))*1000*3
+
+ if str(t.params['k']) == 'building:height':
+ h = int(str(t.params['v']))*1000
+
+ except:
+ sayErr("unexpected error ######################################################")
+
+ name = str(st) + st2 + " " + str(nr)
+
+ if name == ' ':
+ name = 'landuse xyz'
+
+ if debug:
+ say(("name ", name))
+
+ # Generate pointlist of the way
+ polis = []
+ height = None
+ llpoints = []
- llpoints=[]
-# say("get nodes",w)
for n in w.getiterator('nd'):
-# say(n.params)
- m=nodesbyid[n.params['ref']]
- llpoints.append([n.params['ref'],m.params['lat'],m.params['lon']])
+ m = nodesbyid[n.params['ref']]
+ llpoints.append([n.params['ref'], m.params['lat'], m.params['lon']])
+
if elevation:
say("get heights for " + str(len(llpoints)))
- heights=getHeights(llpoints)
+ heights = getHeights(llpoints)
for n in w.getiterator('nd'):
- p=points[str(n.params['ref'])]
+ p = points[str(n.params['ref'])]
+
if building and elevation:
if not height:
try:
- height=heights[m.params['lat']+' '+m.params['lon']]*1000 - baseheight
+ height = heights[m.params['lat']+' '+m.params['lon']]*1000 - baseheight
+
except:
sayErr("---no height avaiable for " + m.params['lat']+' '+m.params['lon'])
- height=0
- p.z=height
+ height = 0
+
+ p.z = height
+
polis.append(p)
- #create 2D map
- pp=Part.makePolygon(polis)
+ # Create 2D map
+ pp = Part.makePolygon(polis)
Part.show(pp)
- z=App.ActiveDocument.ActiveObject
- z.Label="w_"+wid
+ z = App.ActiveDocument.ActiveObject
+ z.Label = "w_"+wid
- if name==' ':
- g=App.ActiveDocument.addObject("Part::Extrusion",name)
+ if name == ' ':
+ g = App.ActiveDocument.addObject("Part::Extrusion", name)
g.Base = z
- g.ViewObject.ShapeColor = (1.00,1.00,0.00)
- g.Dir = (0,0,10)
- g.Solid=True
- g.Label='way ex '
+ g.ViewObject.ShapeColor = (1.00, 1.00, 0.00)
+ g.Dir = (0, 0, 10)
+ g.Solid = True
+ g.Label = 'way ex '
if building:
- g=App.ActiveDocument.addObject("Part::Extrusion",name)
+ g = App.ActiveDocument.addObject("Part::Extrusion", name)
g.Base = z
- g.ViewObject.ShapeColor = (1.00,1.00,1.00)
+ g.ViewObject.ShapeColor = (1.00, 1.00, 1.00)
- if h==0:
- h=10000
- g.Dir = (0,0,h)
- g.Solid=True
- g.Label=name
+ if h == 0:
+ h = 10000
+ g.Dir = (0, 0, h)
+ g.Solid = True
+ g.Label = name
obj = FreeCAD.ActiveDocument.ActiveObject
inventortools.setcolors2(obj)
if landuse:
- g=App.ActiveDocument.addObject("Part::Extrusion",name)
+ g = App.ActiveDocument.addObject("Part::Extrusion", name)
g.Base = z
+
if nr == 'residential':
- g.ViewObject.ShapeColor = (1.00,.60,.60)
+ g.ViewObject.ShapeColor = (1.00, 0.60, 0.60)
+
elif nr == 'meadow':
- g.ViewObject.ShapeColor = (0.00,1.00,0.00)
+ g.ViewObject.ShapeColor = (0.00, 1.00, 0.00)
+
elif nr == 'farmland':
- g.ViewObject.ShapeColor = (.80,.80,.00)
+ g.ViewObject.ShapeColor = (0.80, 0.80, 0.00)
+
elif nr == 'forest':
- g.ViewObject.ShapeColor = (1.0,.40,.40)
- g.Dir = (0,0,0.1)
- g.Label=name
- g.Solid=True
+ g.ViewObject.ShapeColor = (1.0, 0.40, 0.40)
+
+ g.Dir = (0, 0, 0.1)
+ g.Label = name
+ g.Solid = True
if highway:
- g=App.ActiveDocument.addObject("Part::Extrusion","highway")
+ g = App.ActiveDocument.addObject("Part::Extrusion", "highway")
g.Base = z
- g.ViewObject.LineColor = (0.00,.00,1.00)
+ g.ViewObject.LineColor = (0.00, 0.00, 1.00)
g.ViewObject.LineWidth = 10
- g.Dir = (0,0,0.2)
- g.Label=name
+ g.Dir = (0, 0, 0.2)
+ g.Label = name
refresh += 1
- if os.path.exists("/tmp/stop"):
+ if os.path.exists("/tmp/stop"):
sayErr("notbremse gezogen")
- FreeCAD.w=w
+ FreeCAD.w = w
raise Exception("Notbremse Manager main loop")
- if refresh >3:
+ if refresh > 3:
FreeCADGui.updateGui()
- # FreeCADGui.SendMsgToActiveView("ViewFit")
- refresh=0
-
+ refresh = 0
- FreeCAD.activeDocument().recompute()
FreeCADGui.updateGui()
FreeCAD.activeDocument().recompute()
if status:
status.setText("import finished.")
+
if progressbar:
- progressbar.setValue(100)
+ progressbar.setValue(100)
organize()
- endtime=time.time()
+ endtime = time.time()
say(("running time ", int(endtime-starttime), " count ways ", coways))
- return True
-
+ return True
-import FreeCAD,FreeCADGui
-import WebGui
-
-
-#import geodat.import_osm
-#reload(geodat.import_osm)
-
-'''
-{
- "error_message" : "You have exceeded your daily request quota for this API. We recommend registering for a key at the Google Developers Console: https://console.developers.google.com/",
- "results" : [],
- "status" : "OVER_QUERY_LIMIT"
-}
-
-'''
-
-## the dialog layout as miki string
-#
-s6='''
+# The dialog layout as miki string
+s6 = '''
#VerticalLayoutTab:
MainWindow:
#DockWidget:
@@ -746,35 +624,6 @@ def beaustring(string):
clicked.connect: app.showMap
setFixedHeight: 20
- QtGui.QLabel:
- QtGui.QLabel:
- setText:"P r e d e f i n e d L o c a t i o n s"
-# QtGui.QLabel:
-
- QtGui.QRadioButton:
- setText: "Sonneberg Outdoor Inn"
- clicked.connect: app.run_sternwarte
-
- QtGui.QRadioButton:
- setText: "Coburg university and school "
- clicked.connect: app.run_co2
-
- QtGui.QRadioButton:
- setText: "Berlin Alexanderplatz/Haus des Lehrers"
- clicked.connect: app.run_alex
-
- QtGui.QRadioButton:
- setText: "Berlin Spandau"
- clicked.connect: app.run_spandau
-
- QtGui.QRadioButton:
- setText: "Paris Rue de Seine"
- clicked.connect: app.run_paris
-
- QtGui.QRadioButton:
- setText: "Tokyo near tower"
- clicked.connect: app.run_tokyo
-
QtGui.QLabel:
QtGui.QLabel:
setText:"P r o c e s s i n g:"
@@ -791,239 +640,183 @@ def beaustring(string):
'''
-## the gui backend
+# The gui backend
class MyApp(object):
- '''execution layer of the Gui'''
+ """
+ Execution layer of the Gui
+ """
+ def run(self, b, l):
+ """
+ Run(self,b,l) imports area with center coordinates latitude b, longitude l
+ """
- def run(self,b,l):
- '''run(self,b,l) imports area with center coordinates latitude b, longitude l'''
- s=self.root.ids['s'].value()
- key="%0.7f" %(b) + "," + "%0.7f" %(l)
+ s = self.root.ids['s'].value()
+ key = "%0.7f" % b + "," + "%0.7f" % l
self.root.ids['bl'].setText(key)
- import_osm2(b,l,float(s)/10,self.root.ids['progb'],self.root.ids['status'],False)
-
- def run_alex(self):
- '''imports Berlin Aleancderplatz'''
- self.run(52.52128,l=13.41646)
-
- def run_paris(self):
- '''imports Paris'''
- self.run(48.85167,2.33669)
-
- def run_tokyo(self):
- '''imports Tokyo near tower'''
- self.run(35.65905,139.74991)
-
- def run_spandau(self):
- '''imports Berlin Spandau'''
- self.run(52.508,13.18)
-
- def run_co2(self):
- '''imports Coburg Univerity and School'''
- self.run(50.2631171, 10.9483)
-
- def run_sternwarte(self):
- '''imports Sonneberg Neufang observatorium'''
- self.run(50.3736049,11.191643)
-
+ import_osm2(b, l, float(s)/10, self.root.ids['progb'], self.root.ids['status'], False)
def showHelpBox(self):
- msg=PySide.QtGui.QMessageBox()
+ msg = PySide.QtGui.QMessageBox()
msg.setText("Help")
- msg.setInformativeText("Import_osm map dialogue box can also accept links from following sites in addition to (latitude, longitude)
OpenStreetMap
e.g. https://www.openstreetmap.org/#map=15/30.8611/75.8610
Google Maps
e.g. https://www.google.co.in/maps/@30.8611,75.8610,5z
Bing Map
e.g. https://www.bing.com/maps?osid=339f4dc6-92ea-4f25-b25c-f98d8ef9bc45&cp=30.8611~75.8610&lvl=17&v=2&sV=2&form=S00027
Here Map
e.g. https://wego.here.com/?map=30.8611,75.8610,15,normal
(latitude,longitude)
e.g. 30.8611,75.8610
If in any case, the latitude & longitudes are estimated incorrectly, you can use different separators in separator box or can put latitude & longitude directly into their respective boxes.")
+ msg.setInformativeText(
+ "Import_osm map dialogue box can also accept links from following "
+ "sites in addition to (latitude, longitude)"
+ "
OpenStreetMap
e.g. "
+ "https://www.openstreetmap.org/#map=15/30.8611/75.8610 "
+ "
Google Maps
e.g. "
+ "https://www.google.co.in/maps/@30.8611,75.8610,5z"
+ "
Bing Map
e.g. "
+ "https://www.bing.com/maps?osid=339f4dc6-92ea-4f25-b25c-f98d8ef9bc45&cp=30.8611~75.8610&lvl=17&v=2&sV=2&form=S00027"
+ "
Here Map
e.g. "
+ "https://wego.here.com/?map=30.8611,75.8610,15,normal"
+ "
(latitude,longitude)
e.g. 30.8611,75.8610
"
+ " If in any case, the latitude & longitudes are estimated incorrectly,"
+ " you can use different separators in separator box or can put latitude &"
+ " longitude directly into their respective boxes."
+ )
msg.exec_()
def showHelpBoxY(self):
- #self.run_sternwarte()
+ # self.run_sternwarte()
say("showHelpBox called")
def getSeparator(self):
- bl=self.root.ids['bl'].text()
+ bl = self.root.ids['bl'].text()
+
if bl.find('openstreetmap.org') != -1:
self.root.ids['sep'].setText('/')
+
elif bl.find('google.co') != -1:
self.root.ids['sep'].setText('@|,')
+
elif bl.find('bing.com') != -1:
self.root.ids['sep'].setText('=|~|&')
+
elif bl.find('wego.here.com') != -1:
self.root.ids['sep'].setText('=|,')
+
elif bl.find(',') != -1:
self.root.ids['sep'].setText(',')
+
elif bl.find(':') != -1:
self.root.ids['sep'].setText(':')
+
elif bl.find('/') != -1:
self.root.ids['sep'].setText('/')
-
-
def getCoordinate(self):
- sep=self.root.ids['sep'].text()
- bl=self.root.ids['bl'].text()
+ sep = self.root.ids['sep'].text()
+ bl = self.root.ids['bl'].text()
import re
- spli=re.split(sep, bl)
- flag='0'
+ spli = re.split(sep, bl)
+ flag = '0'
+
for x in spli:
try:
float(x)
if x.find('.') != -1:
- if flag=='0':
+ if flag == '0':
self.root.ids['lat'].setText(x)
- flag='1'
- elif flag=='1':
- self.root.ids['long'].setText(x)
- flag='2'
- except:
- flag=flag
-
+ flag = '1'
+ elif flag == '1':
+ self.root.ids['long'].setText(x)
+ flag = '2'
+ except:
+ flag = flag
def swap(self):
- tmp1=self.root.ids['lat'].text()
- tmp2=self.root.ids['long'].text()
+ tmp1 = self.root.ids['lat'].text()
+ tmp2 = self.root.ids['long'].text()
self.root.ids['long'].setText(tmp1)
self.root.ids['lat'].setText(tmp2)
-
-
def downloadData(self):
- '''download data from osm'''
- button=self.root.ids['runbl1']
+ """
+ Download data from osm
+ """
+
+ button = self.root.ids['runbl1']
button.hide()
- br=self.root.ids['running']
+ br = self.root.ids['running']
br.show()
+ bl_disp = self.root.ids['lat'].text()
+ b = float(bl_disp)
+ bl_disp = self.root.ids['long'].text()
+ l = float(bl_disp)
+ s = self.root.ids['s'].value()
+ elevation = self.root.ids['elevation'].isChecked()
+ rc = import_osm2(float(b), float(l), float(s)/10, self.root.ids['progb'], self.root.ids['status'], elevation)
-
- bl_disp=self.root.ids['lat'].text()
- b=float(bl_disp)
- bl_disp=self.root.ids['long'].text()
- l=float(bl_disp)
-
-
- s=self.root.ids['s'].value()
- elevation=self.root.ids['elevation'].isChecked()
-
- rc= import_osm2(float(b),float(l),float(s)/10,self.root.ids['progb'],self.root.ids['status'],elevation)
if not rc:
- button=self.root.ids['runbl2']
+ button = self.root.ids['runbl2']
button.show()
+
else:
- button=self.root.ids['runbl1']
+ button = self.root.ids['runbl1']
button.show()
- br.hide()
-
+ br.hide()
def applyData(self):
- '''apply downloaded or cached data to create the FreeCAD models'''
- button=self.root.ids['runbl2']
+ """
+ Apply downloaded or cached data to create the FreeCAD models
+ """
+
+ button = self.root.ids['runbl2']
button.hide()
- br=self.root.ids['running']
+ br = self.root.ids['running']
br.show()
-
- bl_disp=self.root.ids['lat'].text()
- b=float(bl_disp)
- bl_disp=self.root.ids['long'].text()
- l=float(bl_disp)
-
-
- s=self.root.ids['s'].value()
- elevation=self.root.ids['elevation'].isChecked()
-
- import_osm2(float(b),float(l),float(s)/10,self.root.ids['progb'],self.root.ids['status'],elevation)
- button=self.root.ids['runbl1']
+ bl_disp = self.root.ids['lat'].text()
+ b = float(bl_disp)
+ bl_disp = self.root.ids['long'].text()
+ l = float(bl_disp)
+ s = self.root.ids['s'].value()
+ elevation = self.root.ids['elevation'].isChecked()
+ import_osm2(float(b), float(l), float(s)/10, self.root.ids['progb'], self.root.ids['status'], elevation)
+ button = self.root.ids['runbl1']
button.show()
br.hide()
-
-
def showMap(self):
- '''open a webbrowser window and display the openstreetmap presentation of the area'''
-
- bl_disp=self.root.ids['lat'].text()
- b=float(bl_disp)
- bl_disp=self.root.ids['long'].text()
- l=float(bl_disp)
+ """
+ Open a webbrowser window and display the openstreetmap presentation of the area
+ """
- s=self.root.ids['s'].value()
- WebGui.openBrowser( "http://www.openstreetmap.org/#map=16/"+str(b)+'/'+str(l))
+ bl_disp = self.root.ids['lat'].text()
+ b = float(bl_disp)
+ bl_disp = self.root.ids['long'].text()
+ l = float(bl_disp)
+ s = self.root.ids['s'].value()
+ WebGui.openBrowser("http://www.openstreetmap.org/#map=16/"+str(b)+'/'+str(l))
def showDistanceOnLabel(self):
- distance=self.root.ids['s'].value()
- showDistanceLabel=self.root.ids['showDistanceLabel']
+ distance = self.root.ids['s'].value()
+ showDistanceLabel = self.root.ids['showDistanceLabel']
showDistanceLabel.setText('Distance is '+str(float(distance)/10)+'km.')
-## the gui startup
+# The gui startup
def mydialog():
- ''' starts the gui dialog '''
- app=MyApp()
-
+ """
+ Starts the gui dialog
+ """
+
+ app = MyApp()
import geodat.miki as miki
- reload(miki)
-
- miki=miki.Miki()
- miki.app=app
- app.root=miki
+ miki = miki.Miki()
+ miki.app = app
+ app.root = miki
miki.parse2(s6)
miki.run(s6)
+
return miki
def importOSM():
- mydialog()
-
-
-
-'''
-#-----------------
-# verarbeiten
-
-import xml.etree.ElementTree as ET
-
-fn='/home/thomas/.FreeCAD//geodat3/50.340722-11.232647-0.015'
-#tree = ET.parse(fn)
-
-data_as_string=''
-
- 1
- 2008
- 141100
-
-
-
-
- 4
- 2011
- 59900
-
-
-
- 68
- 2011
- 13600
-
-
-
-
-''
-
-root = ET.fromstring(data_as_string)
-
-
-for element in tree.getiterator('node'):
- print(element.attrib)
-
-
-root = tree.getroot()
-ET.dump(root)
-
-for elem in root:
- print (elem.tag,elem.attrib)
-#----------------
-'''
-
+ mydialog()
\ No newline at end of file
diff --git a/geodat/import_srtm.py b/geodat/import_srtm.py
index 31b29a3..a6af3b6 100644
--- a/geodat/import_srtm.py
+++ b/geodat/import_srtm.py
@@ -1,75 +1,55 @@
-'''import srtm data'''
-
-'''
-
-http://wiki.openstreetmap.org/wiki/DE:SRTM
-http://geoweb.hft-stuttgart.de/SRTM/srtm_as_osm/Lat50Lon11Lat51Lon12.osm.zip
-
-'''
-
-#\cond
-testsatz='''
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-'''
-#\endcond
+"""
+Import srtm data
+"""
+
+import platform
+import urllib
+from urllib.request import urlretrieve
+import time
+import traceback
+import zipfile
+import FreeCADGui
+import FreeCAD
+import os
+from geodat.say import *
+import Draft
+import Points
+from geodat.transversmercator import TransverseMercator
+import math
+import re
+import sys
+if sys.version_info[0] != 2:
+ from importlib import reload
-## create a QProgressBar widget for long running process
+# Create a QProgressBar widget for long running process
def createProgressBar(label=None):
- w=QtGui.QWidget()
+ w = QtGui.QWidget()
hbox = QtGui.QHBoxLayout()
w.setLayout(hbox)
- pb=QtGui.QProgressBar()
+ pb = QtGui.QProgressBar()
w.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
- if label!=None:
- lab=QtGui.QLabel(label)
+
+ if label != None:
+ lab = QtGui.QLabel(label)
hbox.addWidget(lab)
hbox.addWidget(pb)
w.show()
- FreeCAD.w=w
+ FreeCAD.w = w
pb.setValue(0)
- w.pb=pb
+ w.pb = pb
return w
-import Draft
-import Points
-
-import re, math
-
-import sys
-if sys.version_info[0] !=2:
- from importlib import reload
-
-import geodat.transversmercator
-from geodat.transversmercator import TransverseMercator
-
-## create contour curve points list
-def runfile(fn, xw,xe,ys,yn,ox=0,oy=0):
- f= 100000000
+# create contour curve points list
+def runfile(fn, xw, xe, ys, yn, ox=0, oy=0):
+ f = 100000000
- tm=TransverseMercator()
- tm.lat=0.5*(yn+ys)
- tm.lon=0.5*(xw+xe)
-
- center=tm.fromGeographic(tm.lat,tm.lon)
+ tm = TransverseMercator()
+ tm.lat = 0.5*(yn+ys)
+ tm.lon = 0.5*(xw+xe)
+ center = tm.fromGeographic(tm.lat, tm.lon)
xw *= f
xe *= f
@@ -77,35 +57,33 @@ def runfile(fn, xw,xe,ys,yn,ox=0,oy=0):
yn *= f
ox *= f
oy *= f
- pts=[]
- poss={}
- nds=[]
- elev=-1
-
- c=0
-
+ pts = []
+ poss = {}
+ nds = []
+ elev = -1
- #Gui.ActiveDocument.ActiveView.setAnimationEnabled(False)
+ c = 0
- pb=createProgressBar(label="create Elevations " + os.path.basename(fn) )
+ # Gui.ActiveDocument.ActiveView.setAnimationEnabled(False)
+ pb = createProgressBar(label="create Elevations " + os.path.basename(fn))
# file = open('/home/microelly2/Downloads/Lat50Lon11Lat51Lon12.osm', 'r')
- file =open(fn)
+ file = open(fn)
# pb.pb.setValue(10)
for line in file.readlines():
c += 1
# if c == 100000: break
- pb.pb.setValue((c/100)%100)
+ pb.pb.setValue((c/100) % 100)
m = re.match(r'.*2:
# d=Draft.makeWire(pts)
# if len(pts)==1:
# d=Draft.makePoint(pts[0])
- c +=1
+ c += 1
- poss={}
- elev=0
- nds=[]
+ poss = {}
+ elev = 0
+ nds = []
continue
pb.hide()
@@ -145,29 +124,28 @@ def runfile(fn, xw,xe,ys,yn,ox=0,oy=0):
# download the file
-import sys, os, zipfile, traceback, time, urllib, re, platform
-
-from geodat.say import *
-
-
+import sys, os, zipfile, traceback, time, re, platform
## download the data files from /geoweb.hft-stuttgart.de/SRTM
-def getdata(directory,dat):
+def getdata(directory, dat):
zipfilename=directory + "/{}.osm.zip".format(dat)
source="http://geoweb.hft-stuttgart.de/SRTM/srtm_as_osm/{}.osm.zip".format(dat)
- fn=directory+"/"+dat+".osm"
+ fn = directory+"/"+dat+".osm"
if not os.path.exists(fn):
if not os.path.exists(zipfilename):
- say("get "+ source)
- tg=urllib.urlretrieve(source,zipfilename)
- targetfile=tg[0]
+ say("get " + source)
+ tg = urlretrieve(source, zipfilename)
+ targetfile = tg[0]
say("targetfile:"+targetfile)
+ fh = open(targetfile, 'rb')
+
else:
fh = open(zipfilename, 'rb')
+
zfile = zipfile.ZipFile(fh)
zfile.extractall(directory)
fh.close()
@@ -175,86 +153,97 @@ def getdata(directory,dat):
## get the date from files,create a point cloud
-def run(mx,my,dx,dy):
-
- ys=my-dy
- yn=my+dy
- xw=mx-dx
- xe=mx+dx
-
- dats=[]
-
- say(xw,ys,xe,yn)
- for ix in range(int(math.floor(xw)),int(math.floor(xe))+1):
- for iy in range(int(math.floor(ys)),int(math.floor(yn))+1):
- dat="Lat"+str(iy)+"Lon"+str(ix)+"Lat"+str(iy+1)+"Lon"+str(ix+1)
- say(dat)
- dats.append(dat)
+def run(mx, my, dx, dy):
+
+ ys = my-dy
+ yn = my+dy
+ xw = mx-dx
+ xe = mx+dx
- directory=FreeCAD.ConfigGet("UserAppData") + "/geodat_SRTM/"
+ dats = []
+ say(xw, ys, xe, yn)
+ for ix in range(int(math.floor(xw)), int(math.floor(xe))+1):
+ for iy in range(int(math.floor(ys)), int(math.floor(yn))+1):
+ dat = "Lat"+str(iy)+"Lon"+str(ix)+"Lat"+str(iy+1)+"Lon"+str(ix+1)
+ say(dat)
+ dats.append(dat)
+ directory = FreeCAD.ConfigGet("UserAppData") + "/geodat_SRTM/"
if not os.path.isdir(directory):
os.makedirs(directory)
for dat in dats:
- getdata(directory,dat)
- fn=directory+"/"+dat+".osm"
- pts=runfile(fn,xw,xe,ys,yn,mx,my)
-
- p=Points.Points(pts)
- Points.show(p)
- Gui.updateGui()
- Gui.SendMsgToActiveView("ViewFit")
-
-
+ getdata(directory, dat)
+ fn = directory+"/"+dat+".osm"
+ pts = runfile(fn, xw, xe, ys, yn, mx, my)
+
+ # Get or create "Point_Groups".
+ try:
+ PointGroups = FreeCAD.ActiveDocument.Point_Groups
+ except:
+ PointGroups = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", 'Point_Groups')
+ PointGroups.Label = "Point Groups"
+
+ # Get or create "Points".
+ try:
+ FreeCAD.ActiveDocument.Points
+ except:
+ Points = FreeCAD.ActiveDocument.addObject('Points::Feature', "Points")
+ PointGroups.addObject(Points)
+
+ PointGroup = FreeCAD.ActiveDocument.addObject('Points::Feature', "Point_Group")
+ PointGroup.Label = dat
+ FreeCAD.ActiveDocument.Point_Groups.addObject(PointGroup)
+ PointObject = PointGroup.Points.copy()
+ PointObject.addPoints(pts)
+ PointGroup.Points = PointObject
+
+ FreeCAD.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
- return pts
-
+ return pts
# test daten
-dy=0.09
-dx=0.09
+dy = 0.09
+dx = 0.09
# zugspitze
-my=47.4210641
-mx=10.9678556
+my = 47.4210641
+mx = 10.9678556
# nizza
-my=43.6827455
-mx=7.255056
+my = 43.6827455
+mx = 7.255056
# puy de dome Clermont Ferrand
-my=45.7750419
-mx=2.902975
+my = 45.7750419
+mx = 2.902975
# run(mx,my,dx,dy)
# mount everest
-my=28.0020784
-mx=86.9238805
+my = 28.0020784
+mx = 86.9238805
# friesener berg
-my=50.2714589
-mx=11.3614118
+my = 50.2714589
+mx = 11.3614118
# outdoor inn
-my=50.3736049
-mx=11.1916430
+my = 50.3736049
+mx = 11.1916430
-
-
-s6='''
+s6 = '''
MainWindow:
VerticalLayout:
id:'main'
@@ -263,7 +252,7 @@ def run(mx,my,dx,dy):
move: PySide.QtCore.QPoint(100,100)
QtGui.QLabel:
- setText:"I m p o r t S R T M Elevations"
+ setText:"I m p o r t S R T M Elevations"
QtGui.QLabel:
setText:"Location:"
@@ -328,7 +317,7 @@ def run(mx,my,dx,dy):
class MyApp(object):
- #\cond
+ # \cond
def run_nizza(self):
self.root.ids['bl'].setText("43.6827455,7.255056")
@@ -354,68 +343,65 @@ def run_outdoorinn(self):
# Guayaquil Ecuador-2.1523858,-80.0501215
- def run_browser(self):
+ def run_browser(self):
import WebGui
- bl=self.root.ids['bl'].text()
- spli=bl.split(',')
- my=float(spli[0])
- mx=float(spli[1])
- WebGui.openBrowser( "http://www.openstreetmap.org/#map=12/"+str(my)+'/'+str(mx))
-
- def run_google(self):
+ bl = self.root.ids['bl'].text()
+ spli = bl.split(',')
+ my = float(spli[0])
+ mx = float(spli[1])
+ WebGui.openBrowser(
+ "http://www.openstreetmap.org/#map=12/"+str(my)+'/'+str(mx))
+
+ def run_google(self):
import WebGui
- bl=self.root.ids['bl'].text()
- spli=bl.split(',')
- my=float(spli[0])
- mx=float(spli[1])
- WebGui.openBrowser( "https://www.google.de/maps/@"+str(my)+','+str(mx) +",8000m/data=!3m1!1e3")
-
- def run_reitwander(self):
+ bl = self.root.ids['bl'].text()
+ spli = bl.split(',')
+ my = float(spli[0])
+ mx = float(spli[1])
+ WebGui.openBrowser("https://www.google.de/maps/@" +
+ str(my)+','+str(mx) + ",8000m/data=!3m1!1e3")
+
+ def run_reitwander(self):
import WebGui
- bl=self.root.ids['bl'].text()
- spli=bl.split(',')
- my=float(spli[0])
- mx=float(spli[1])
- WebGui.openBrowser( "http://www.wanderreitkarte.de/index.php?lon="+str(mx)+"&lat="+str(my)+"&zoom=12")
-
-
-
-
-
+ bl = self.root.ids['bl'].text()
+ spli = bl.split(',')
+ my = float(spli[0])
+ mx = float(spli[1])
+ WebGui.openBrowser(
+ "http://www.wanderreitkarte.de/index.php?lon="+str(mx)+"&lat="+str(my)+"&zoom=12")
def runbl(self):
- bl=self.root.ids['bl'].text()
- spli=bl.split(',')
- my=float(spli[0])
- mx=float(spli[1])
+ bl = self.root.ids['bl'].text()
+ spli = bl.split(',')
+ my = float(spli[0])
+ mx = float(spli[1])
# dy=0.09
# dx=0.09
- dbl=self.root.ids['dbl'].text()
- spli=dbl.split(',')
- dy=float(spli[0])
- dx=float(spli[1])
-
- run(mx,my,dx,dy)
+ dbl = self.root.ids['dbl'].text()
+ spli = dbl.split(',')
+ dy = float(spli[0])
+ dx = float(spli[1])
+ run(mx, my, dx, dy)
def runValues(self):
- b=self.root.ids['b'].text()
- l=self.root.ids['l'].text()
- s=self.root.ids['s'].value()
- say([l,b,s])
+ b = self.root.ids['b'].text()
+ l = self.root.ids['l'].text()
+ s = self.root.ids['s'].value()
+ say([l, b, s])
import WebGui
# WebGui.openBrowser( "http://www.openstreetmap.org/#map=19/"+str(b)+'/'+str(l))
import geodat.import_osm
- geodat.import_osm.import_osm(float(b),float(l),float(s)/10,self.root.ids['progb'],self.root.ids['status'])
-
+ geodat.import_osm.import_osm(float(b), float(l), float(
+ s)/10, self.root.ids['progb'], self.root.ids['status'])
def showMap(self):
- b=self.root.ids['b'].text()
- l=self.root.ids['l'].text()
- s=self.root.ids['s'].value()
- say([l,b,s])
+ b = self.root.ids['b'].text()
+ l = self.root.ids['l'].text()
+ s = self.root.ids['s'].value()
+ say([l, b, s])
import WebGui
WebGui.openBrowser( "http://www.openstreetmap.org/#map=9/"+str(b)+'/'+str(l))
@@ -424,26 +410,24 @@ def showMap(self):
##the gui startup
def mydialog():
- app=MyApp()
+ app = MyApp()
import geodat.miki as miki
- reload(miki)
-
- miki=miki.Miki()
- miki.app=app
- app.root=miki
+ miki = miki.Miki()
+ miki.app = app
+ app.root = miki
miki.parse2(s6)
miki.run(s6)
- m=miki.ids['main']
+ m = miki.ids['main']
return miki
## testcase start and hide the dialog
def runtest():
- m=mydialog()
+ m = mydialog()
m.objects[0].hide()
def importSRTM():
@@ -451,4 +435,3 @@ def importSRTM():
if __name__ == '__main__':
runtest()
-
diff --git a/geodat/import_xyz.py b/geodat/import_xyz.py
index 91d33ad..b327dd4 100644
--- a/geodat/import_xyz.py
+++ b/geodat/import_xyz.py
@@ -87,7 +87,7 @@ def getShape(pts):
try:dists[dist] += 1
except: dists[dist]=1
say(dists.keys())
- mm=np.mean(dists.keys())
+ mm=np.mean(list(dists.keys()))
tts=[]
ia=-1
@@ -188,10 +188,20 @@ def import_xyz(mode,filename="/tmp/test.xyz",label='',ku=20, kv=10,lu=0,lv=0):
App.ActiveDocument.grids
except:
grids=App.ActiveDocument.addObject("App::DocumentObjectGroup","grids")
+
+ # Get or create "Point_Groups".
+ try:
+ PointGroups = FreeCAD.ActiveDocument.Point_Groups
+ except:
+ PointGroups = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", 'Point_Groups')
+ PointGroups.Label = "Point Groups"
+
+ # Get or create "Points".
try:
- App.ActiveDocument.points
+ FreeCAD.ActiveDocument.Points
except:
- points=App.ActiveDocument.addObject("App::DocumentObjectGroup","points")
+ Points = FreeCAD.ActiveDocument.addObject('Points::Feature', "Points")
+ PointGroups.addObject(Points)
objs=App.ActiveDocument.getObjectsByLabel(label)
@@ -219,10 +229,19 @@ def import_xyz(mode,filename="/tmp/test.xyz",label='',ku=20, kv=10,lu=0,lv=0):
App.ActiveDocument.grids
except:
grids=App.ActiveDocument.addObject("App::DocumentObjectGroup","grids")
+ # Get or create "Point_Groups".
try:
- App.ActiveDocument.points
+ PointGroups = FreeCAD.ActiveDocument.Point_Groups
except:
- points=App.ActiveDocument.addObject("App::DocumentObjectGroup","points")
+ PointGroups = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", 'Point_Groups')
+ PointGroups.Label = "Point Groups"
+
+ # Get or create "Points".
+ try:
+ FreeCAD.ActiveDocument.Points
+ except:
+ Points = FreeCAD.ActiveDocument.addObject('Points::Feature', "Points")
+ PointGroups.addObject(Points)
fn=filename
@@ -258,14 +277,24 @@ def import_xyz(mode,filename="/tmp/test.xyz",label='',ku=20, kv=10,lu=0,lv=0):
if ku>1 and kv>1:
pts=reduceGrid(pts,ku,kv)
- p=Points.Points(pts)
- Points.show(p)
- App.ActiveDocument.ActiveObject.ViewObject.ShapeColor=(1.0,.0,0.0)
- App.ActiveDocument.ActiveObject.ViewObject.PointSize=3.0
- Gui.updateGui()
- Gui.SendMsgToActiveView("ViewFit")
+
+ head, tail = os.path.split(fn)
+
+ PointGroup = FreeCAD.ActiveDocument.addObject('Points::Feature', "Point_Group")
+ PointGroup.Label = tail[:-4]
+ FreeCAD.ActiveDocument.Point_Groups.addObject(PointGroup)
+ PointObject = PointGroup.Points.copy()
+ PointObject.addPoints(pts)
+ PointGroup.Points = PointObject
+
App.ActiveDocument.ActiveObject.ViewObject.hide()
- return pts
+ PointGroup.ViewObject.ShapeColor=(1.0,.0,0.0)
+ PointGroup.ViewObject.PointSize=3.0
+
+ FreeCAD.ActiveDocument.recompute()
+ Gui.SendMsgToActiveView("ViewFit")
+
+ return pts
sdialog='''
@@ -435,7 +464,7 @@ def update(self):
# lu,lv = getShape(self.pts)
say("update")
lu=int(self.root.ids['lu'].text())
- lv=int(self.root.ids['lv'].text())
+ lv=float(self.root.ids['lv'].text())
say("dd,ud,vd",self.root.ids['dd'].value(),self.root.ids['ud'].value(),self.root.ids['vd'].value())
dmax = min(lu - self.root.ids['ud'].value(), lv - self.root.ids['vd'].value(),101) -1
@@ -509,7 +538,7 @@ def showFrame(self):
v=self.root.ids['vd'].value()
d=self.root.ids['dd'].value()
lu=int(self.root.ids['lu'].text())
- lv=int(self.root.ids['lv'].text())
+ lv=float(self.root.ids['lv'].text())
showFrame(self.pts,u,v,d,lu,lv)
@@ -521,7 +550,7 @@ def createNurbs(self):
d=self.root.ids['dd'].value()
# lu,lv = getShape(self.pts)
lu=int(self.root.ids['lu'].text())
- lv=int(self.root.ids['lv'].text())
+ lv=float(self.root.ids['lv'].text())
say(("create nurbs for subset",u,v,d,lu,lv))
suv(self,u,v,d,lu,lv)
@@ -534,7 +563,7 @@ def createMesh(self):
d=self.root.ids['dd'].value()
# lu,lv = getShape(self.pts)
lu=int(self.root.ids['lu'].text())
- lv=int(self.root.ids['lv'].text())
+ lv=float(self.root.ids['lv'].text())
muv(self,u,v,d+1,lu,lv)
@@ -543,11 +572,8 @@ def createMesh(self):
def mydialog(run=True):
'''the gui startup'''
- import geodat
import geodat.miki as miki
- reload(miki)
-
app=MyApp()
miki=miki.Miki()
@@ -785,8 +811,7 @@ def suv(app,u=3,v=5,d=10,la=100,lb=100):
return tt
-'''
-alt - kann weg
+
def suv2(label,pts,u=3,v=5,d=10,la=100,lb=100):
try:
@@ -818,7 +843,7 @@ def suv2(label,pts,u=3,v=5,d=10,la=100,lb=100):
pu=[]
say([ "(wb,eb,sb,nb,du,dv)", (wb,eb,sb,nb,du,dv)])
for k in range(dv):
- pu += pts[u+v*la+la*k:u+v*la+du+la*k]
+ pu.append(pts[u+v*la+la*k:u+v*la+du+la*k])
uu.append(pts[u+v*la+la*k:u+v*la+du+la*k])
color=(1-0.5*random.random(),1-0.5*random.random(),1-0.5*random.random())
@@ -866,7 +891,7 @@ def suv2(label,pts,u=3,v=5,d=10,la=100,lb=100):
# return tt
return a
-'''
+
# generate 100 quads with each 100 interpolation points
diff --git a/geodat/my_xmlparser.py b/geodat/my_xmlparser.py
index d7d244c..38ffe44 100644
--- a/geodat/my_xmlparser.py
+++ b/geodat/my_xmlparser.py
@@ -91,7 +91,7 @@ def getData(fn,pb=None):
say("Read data from cache file ...")
say(fn)
- f=open(fn,"r")
+ f=open(fn,"r") #, encoding="utf8")
content=f.readlines()
c2=[]
diff --git a/geodat/navigator.py b/geodat/navigator.py
index b5a6299..111b2bf 100644
--- a/geodat/navigator.py
+++ b/geodat/navigator.py
@@ -338,7 +338,7 @@ def eventFilter(self, o, e):
#
def stop():
- mw=QtGui.qApp
+ mw=QtGui.QApplication
ef=FreeCAD.eventfilter
mw.removeEventFilter(ef)
#mw.setOverrideCursor(QtCore.Qt.SizeAllCursor)
@@ -1005,7 +1005,7 @@ def navi():
'''navigator startup'''
- mw=QtGui.qApp
+ mw=QtGui.QApplication
#widget.setCursor(QtCore.Qt.SizeAllCursor)
#cursor ausblenden
#mw.setOverrideCursor(QtCore.Qt.BlankCursor)