def onSearch(self): searchterm = self.search.text().split() self.lat = ( GIS2BIM.NominatimAPI(searchterm))[0] #Use Nominatim for geocoding self.lon = (GIS2BIM.NominatimAPI(searchterm))[1] if self.lat is None: dialog = QtWidgets.QMessageBox() dialog.setText("Address not found") dialog.setWindowTitle("Warning") dialog.exec_() else: JS = open(self.filepathJSSearch, "r") JS = JS.read() JS = JS.replace("51LAT", str(self.lat)) JS = JS.replace("4LONG", str(self.lon)) JS = JS.replace("FOLDERNAME", self.temptxtPath) self.webPage.runJavaScript(JS) # set view
def __init__(self, parent=None): super(GISOSM_Dialog, self).__init__(parent) self.sitename = "GIS-Sitedata" #Get/set parameters for GIS self.tempFolderName = "GIStemp/" self.lat = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).WGS84_Latitude) self.lon = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).WGS84_Longitude) self.bboxWidthStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).BoundingboxWidth) self.bboxHeightStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).BoundingboxHeight) #Set Style self.setStyleSheet( "QWidget {background-color: rgb(68, 68, 68)} QPushButton { background-color: black } QGroupBox {border: 1px solid grey; }" ) #margin: 2px; #Download files self.URLmap = GIS2BIM.GetWebServerData("HTMLwfs", "Other", "URL") #self.filepathBaseMap = GIS2BIM.DownloadURL(GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName),self.URLmap,"basemapWFS.html") #Basemap from GIS2BIM Repository for preview #self.filepathNewMap = GIS2BIM.DownloadURL(GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName),self.URLmap,"mapWFS.html") #Edited Basemap with location and bbox self.filepathBaseMap = "C:/Users/mikev/OneDrive/Bureaublad/TEMP/GIStemp/basemapWFS.html" self.filepathNewMap = "C:/Users/mikev/OneDrive/Bureaublad/TEMP/GIStemp/mapWFS.html" self.tempFolderPath = GIS2BIM_FreeCAD.CreateTempFolder( self.tempFolderName) os.remove(self.filepathNewMap) BaseMap = open(self.filepathBaseMap, "r") BaseMapstr = BaseMap.read() Newstr = BaseMapstr.replace("51LAT", str(self.lat)) Newstr = Newstr.replace("4LONG", str(self.lon)) Newstr = Newstr.replace("WBBOX", self.bboxWidthStart) Newstr = Newstr.replace("HBBOX", self.bboxHeightStart) open(self.filepathNewMap, "x") f1 = open(self.filepathNewMap, "w") f1.write(Newstr) f1.close() #Overall Grid grid = QtWidgets.QGridLayout() grid.addWidget(self.webViewGroup(), 0, 0, 1, 2) grid.addWidget(self.locationGroup(), 3, 0, QtCore.Qt.AlignTop) grid.addLayout(self.buttonGroup(), 4, 0, 1, 2) grid.setRowStretch(0, 2) self.setLayout(grid) self.setWindowTitle("Load 2D Vector Data with WFS(Web Feature Server)") self.resize(920, 910)
def CurvesFromWFS(serverName, boundingBoxString, xPathString, dx, dy, scale, DecimalNumbers, closedValue, Face, DrawStyle, LineColor): curves = GIS2BIM.PointsFromWFS(serverName, boundingBoxString, xPathString, dx, dy, scale, DecimalNumbers) FCcurves = [] for i in curves: pointlist = [] for j in i: pointlist.append(FreeCAD.Vector(j[0], j[1], 0)) a = Draft.makeWire(pointlist, closed=closedValue) a.MakeFace = Face a.ViewObject.DrawStyle = DrawStyle a.ViewObject.LineColor = LineColor FCcurves.append(a) return FCcurves
def onOk(self): # Find latest version of temp.txt which contains the chosen coordinates filenames = [] filestamps = [] for filename in os.listdir(self.tempFolderPath): if filename.endswith(".txt"): filenames.append(filename) i = os.path.getmtime(self.tempFolderPath + "/" + filename) filestamps.append( time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(i))) latest = max(filestamps) indexof = filestamps.index(latest) latestfile = filenames[indexof] filepathTempfileLATLONData = self.tempFolderPath + "/" + latestfile #most recent file tempFileCoordinates = open(filepathTempfileLATLONData, "r") CoordinatesString = tempFileCoordinates.read() tempFileCoordinates.close() strsplit = re.split("[(, )]", CoordinatesString) self.lat = strsplit[1] self.lon = strsplit[3] SiteObject = GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename) CRS_EPSG_SRID = SiteObject.CRS_EPSG_SRID = GIS2BIM_CRS.inputChars[ self.cboCRS.currentIndex()] SiteObject.WGS84_Longitude = self.lon SiteObject.WGS84_Latitude = self.lat SiteObject.Longitude = float(self.lon) SiteObject.Latitude = float(self.lat) Transformation = GIS2BIM.TransformCRS_epsg("4326", CRS_EPSG_SRID, self.lon, self.lat) SiteObject.CRS_x = float(Transformation[0]) SiteObject.CRS_y = float(Transformation[1]) SiteObject.BoundingboxWidth = float(self.bboxWidth.text()) SiteObject.BoundingboxHeight = float(self.bboxHeight.text()) SiteObject.CRS_EPSG_Description = GIS2BIM_CRS.getCRSdata(CRS_EPSG_SRID) #Set GeoOrigin if self.CBGeoOrigin: obj = geo_origin.get() obj.Origin = FreeCAD.Vector( float(Transformation[0]) * 1000, float(Transformation[1]) * 1000, 0) self.close()
def onImport(self): self.bboxString = GIS2BIM.CreateBoundingBox( float(GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).CRS_x), float(GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).CRS_y), float(self.bboxWidth.text()), float(self.bboxHeight.text()), 2) url = self.request.text() xpathstr = self.xPathStr.text() closedValue = self.clsPolygon.isChecked() makeFaceValue = self.clsCreateFace.isChecked() drawStyle = str(self.linePattern.currentText()) Curves = GIS2BIM_FreeCAD.CurvesFromWFS(url, self.bboxString, xpathstr, -float(self.X), -float(self.Y), 1000, 3, closedValue, makeFaceValue, drawStyle, (0.7, 0.0, 0.0)) GIS2BIM_FreeCAD.CreateLayer(self.groupName.text()) FreeCAD.activeDocument().getObject( self.groupName.text()).addObjects(Curves) FreeCAD.ActiveDocument.recompute() self.close()
SiteName = "GIS-Sitedata" TempFolderName = "GIStemp/" sitename = SiteName #Get/set parameters for GIS tempFolderName = "GIStemp/" X = GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_x Y = GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_y lat = str(GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).WGS84_Latitude) lon = str(GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).WGS84_Longitude) bboxWidthStart = GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).BoundingboxWidth bboxHeightStart = GIS2BIM_FreeCAD.ArchSiteCreateCheck( sitename).BoundingboxHeight CRS = str(GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_EPSG_SRID) CRSDescription = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_EPSG_Description) bboxString = GIS2BIM.CreateBoundingBox( GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_x, GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_y, bboxWidthStart, bboxHeightStart, 0) GIS_2D_Ruimtelijke_Plannen = GIS2BIM_FreeCAD.CreateLayer( "GIS_2D_Ruimtelijke_Plannen") test = RuimtelijkePlannenBouwvlakCurves = GIS2BIM_FreeCAD.CurvesFromWFS( GIS2BIM_NL.NLRuimtelijkeplannenBouwvlak, bboxString, ".//{http://www.opengis.net/gml}posList", -X, -Y, 1000, 3, False, False, u"Solid", (0.0, 0.0, 1.0)) print(test)
importlib.reload(GIS2BIM_FreeCAD) sitename = "GIS-Sitedata" tempFolderName = "GIStemp/BAG3D/" tempFolder = GIS2BIM_FreeCAD.CreateTempFolder(tempFolderName) X = str(GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_x) Y = str(GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_y) dx = -float(X) * 1000 dy = -float(Y) * 1000 bboxWidthStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).BoundingboxWidth) bboxHeightStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).BoundingboxHeight) bboxString = GIS2BIM.CreateBoundingBox( float(GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_x), float(GIS2BIM_FreeCAD.ArchSiteCreateCheck(sitename).CRS_y), float(bboxWidthStart), float(bboxHeightStart), 0) jsonFileNames = GIS2BIM_NL.BAG3DDownload(bboxString, tempFolder) #Import JSON for jsonFile in jsonFileNames: GIS2BIM_FreeCAD.CityJSONImport(jsonFile, X, Y, 2, bboxWidthStart, bboxHeightStart) FreeCAD.ActiveDocument.recompute()
def __init__(self): super(GISLocation_Dialog, self).__init__() self.sitename = "GIS-Sitedata" self.tempFolderName = "GIStemp" #Get/set parameters for GIS self.lat = GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).WGS84_Latitude self.lon = GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).WGS84_Longitude self.bboxWidthStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).BoundingboxWidth) self.bboxHeightStart = str( GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).BoundingboxHeight) self.CRS = GIS2BIM_FreeCAD.ArchSiteCreateCheck( self.sitename).CRS_EPSG_SRID #Create temp folders/files self.URLmap = GIS2BIM.GetWebServerData("HTMLLocationData", "Other", "URL") self.URLSearch = GIS2BIM.GetWebServerData( "HTMLLocationDataJSmapfilesearch", "Other", "URL") self.URLUpdate = GIS2BIM.GetWebServerData( "HTMLLocationDataJSmapbboxupdate", "Other", "URL") #self.filepathBaseMap = GIS2BIM.DownloadURL(GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName),self.URLmap,"basemap.html") self.filepathJSSearch = GIS2BIM.DownloadURL( GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName), self.URLSearch, "map_filesearch.js") self.filepathJSUpdate = GIS2BIM.DownloadURL( GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName), self.URLUpdate, "map_bboxupdate.js") self.filepathBaseMap = "C:/Users/mikev/OneDrive/Bureaublad/TEMP/GIStemp/basemapNewVersion.html" self.tempFolderPath = GIS2BIM_FreeCAD.CreateTempFolder( self.tempFolderName) self.filepathNewMap = self.tempFolderPath + "/map.html" self.temptxtPath = self.tempFolderPath + "/temp.txt" #Set Style self.setStyleSheet(GIS2BIM_GUI.StyleSheet) #margin: 2px for file in os.listdir(self.tempFolderPath): # Cleanup of txt-files if file.endswith(".txt"): self.filename = self.tempFolderPath + "/" + file os.remove(self.filename) #self.application = QApplication(sys.argv) #extend this to kill the webengineprocess #Overall Grid grid = QtWidgets.QGridLayout() grid.addWidget(self.webViewGroup(), 0, 0) grid.addWidget(self.locationGroup(), 1, 0, QtCore.Qt.AlignTop) grid.addLayout(self.buttonGroup(), 2, 0) grid.setRowStretch(0, 3) self.setLayout(grid) self.setWindowTitle("Set Geographic Location") self.resize(920, 900) #Download map.html from GIS2BIM Repository and set projectlocation os.remove(self.filepathNewMap) BaseMap = open(self.filepathBaseMap, "r") BaseMapstr = BaseMap.read() Newstr = BaseMapstr.replace("51LAT", self.lat) Newstr = Newstr.replace("4LONG", self.lon) Newstr = Newstr.replace("FOLDERNAME", self.temptxtPath) Newstr = Newstr.replace("WBBOX", self.bboxWidthStart) Newstr = Newstr.replace("HBBOX", self.bboxHeightStart) open(self.filepathNewMap, "x") f1 = open(self.filepathNewMap, "w") f1.write(Newstr) f1.close()