def onTest(self): self.ServerName = self.request.text() TMS = GIS2BIM.TMS_WMTSCombinedMapFromLatLonBbox(float(self.lat),float(self.lon),float(self.bboxWidth.text()),float(self.bboxHeight.text()),int(self.zoomLevel.text()),self.pixels,self.TMS_WMTS,self.ServerName) fileLocationTMS = self.tempFolder + self.imageName.text() + '.jpg' TMS[0].save(fileLocationTMS) if self.cbGrayscale.checkState(): img = Image.open(fileLocationTMS) fileLocationTMS2 = self.tempFolder + self.imageName.text() + '_gray.jpg' gray_image = ImageOps.grayscale(img) gray_image.save(fileLocationTMS2) else: fileLocationTMS2 = fileLocationTMS picture = QPixmap(fileLocationTMS2) picture = picture.scaledToWidth(800) pictheight = picture.height() if pictheight > 600: scale = 600/pictheight pictheight = 600 pictwidth = 800*scale picture = picture.scaledToWidth(pictwidth) else: pictwidth = 800 picture = picture.scaledToWidth(pictwidth) self.pictlabel.setPixmap(picture) self.pictlabel.setGeometry(QtCore.QRect(40, 40, pictwidth-40, pictheight-40)) self.pictlabel.hide() self.pictlabel.show()
def onImport(self): width = float(self.bboxWidth.text()) height = float(self.bboxHeight.text()) if width > 1000 or height > 1000 and int(self.zoomLevel.text()) >17: dialog = QtWidgets.QMessageBox() dialog.setText("Boundingbox is larger then 1000 meters. Set zoomlevel lower then 18 to prevent extreem large imagefiles") dialog.setWindowTitle("Warning") dialog.exec_() else: test = "test" dx = float(self.dx.text())*1000 dy = float(self.dy.text())*1000 fileLocationTMS = self.tempFolder + self.imageName.text() + '.jpg' TMS = GIS2BIM.TMS_WMTSCombinedMapFromLatLonBbox(float(self.lat),float(self.lon),float(self.bboxWidth.text()),float(self.bboxHeight.text()),int(self.zoomLevel.text()),self.pixels,self.TMS_WMTS,self.ServerName) TMS[0].save(fileLocationTMS) if self.cbGrayscale.checkState(): img = Image.open(fileLocationTMS) fileLocationTMS2 = self.tempFolder + self.imageName.text() + '_gray.jpg' gray_image = ImageOps.grayscale(img) gray_image.save(fileLocationTMS2) else: fileLocationTMS2 = fileLocationTMS ImageMap = GIS2BIM_FreeCAD.ImportImage(fileLocationTMS2,float(self.bboxWidth.text()),float(self.bboxHeight.text()),1000, str(self.imageName.text()), dx,dy) GIS2BIM_FreeCAD.CreateLayer("GIS_Raster") FreeCAD.ActiveDocument.recompute() FreeCAD.activeDocument().getObject("GIS_Raster").addObject(FreeCAD.activeDocument().getObject(ImageMap.Label)) FreeCAD.ActiveDocument.recompute() self.close()
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.isChecked() is True: obj = geo_origin.get() obj.Origin = FreeCAD.Vector( float(Transformation[0]) * 1000, float(Transformation[1]) * 1000, 0) if self.CBAerialphoto.isChecked() is True: fileLocationTMS = self.tempFolderPath + 'ESRI_aerialphoto.jpg' TMS = GIS2BIM.TMS_WMTSCombinedMapFromLatLonBbox( float(self.lat), float(self.lon), float(self.bboxWidth.text()), float(self.bboxHeight.text()), 17, 256, 0, "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}.png" ) TMS[0].save(fileLocationTMS) ImageMap = GIS2BIM_FreeCAD.ImportImage( fileLocationTMS, float(self.bboxWidth.text()), float(self.bboxHeight.text()), 1000, "ESRI aerialMap", 0, 0) GIS2BIM_FreeCAD.CreateLayer("GIS_Raster") FreeCAD.ActiveDocument.recompute() FreeCAD.activeDocument().getObject("GIS_Raster").addObject( FreeCAD.activeDocument().getObject(ImageMap.Label)) self.close()