From 3bdb5024395517dac520aaf45d4e2651ff4016b7 Mon Sep 17 00:00:00 2001 From: geoyee Date: Thu, 16 Dec 2021 22:37:00 +0800 Subject: [PATCH] Fix load CRS and add time --- buildseg/buildSeg.py | 15 ++++++++++++--- buildseg/utils/shape.py | 14 ++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/buildseg/buildSeg.py b/buildseg/buildSeg.py index e0cbf90..df0d9cc 100644 --- a/buildseg/buildSeg.py +++ b/buildseg/buildSeg.py @@ -33,9 +33,11 @@ # from qgis.utils import iface from qgis.core import ( QgsMapLayerProxyModel, QgsVectorFileWriter, QgsProject, Qgis) -import os.path as osp from qgis.utils import iface +import os.path as osp +import time + try: from osgeo import gdal except ImportError: @@ -287,6 +289,8 @@ def run(self): result = self.dlg.exec_() # See if OK was pressed if result: + # Start timing + time_start = time.time() # Do something useful here - delete the line containing pass and # substitute with your code. # layers = iface.activeLayer() # Get the currently active layer @@ -339,5 +343,10 @@ def run(self): iface.addVectorLayer(simp_save_path, "deepbands-simplified", "ogr") else : print ('No') - # Reset model params - self.infer_worker.reset_model() + # # Reset model params + # self.infer_worker.reset_model() + time_end = time.time() + iface.messageBar().pushMessage( + "The whole operation is performed in less than " + str(time_end - time_start) + " seconds", + level=Qgis.Info, + duration=30) diff --git a/buildseg/utils/shape.py b/buildseg/utils/shape.py index 10d3275..0397316 100644 --- a/buildseg/utils/shape.py +++ b/buildseg/utils/shape.py @@ -31,10 +31,12 @@ def polygonize_raster(mask, shp_save_path, proj, geot, rm_tmp=True, display=True drv = ogr.GetDriverByName("ESRI Shapefile") dst_ds = drv.CreateDataSource(shp_save_path) prosrs = osr.SpatialReference(wkt=ds.GetProjection()) - ESPGValue = prosrs.GetAttrValue("AUTHORITY", 1) - sr = osr.SpatialReference() - sr.ImportFromEPSG(int(ESPGValue)) - dst_layer = dst_ds.CreateLayer("Building boundary", geom_type=ogr.wkbPolygon, srs=sr) + # print("proj_1: ", prosrs) # test + # ESPGValue = prosrs.GetAttrValue("AUTHORITY", 1) + # sr = osr.SpatialReference() + # sr.ImportFromEPSG(int(ESPGValue)) + # print("proj_2:", sr) # test + dst_layer = dst_ds.CreateLayer("Building boundary", geom_type=ogr.wkbPolygon, srs=prosrs) dst_fieldname = "DN" fd = ogr.FieldDefn(dst_fieldname, ogr.OFTInteger) dst_layer.CreateField(fd) @@ -55,9 +57,9 @@ def polygonize_raster(mask, shp_save_path, proj, geot, rm_tmp=True, display=True import numpy as np from PIL import Image ras_path = r"C:\Users\Geoyee\Desktop\dd\ras.tif" - shp_save_path = r"C:\Users\Geoyee\Desktop\dd\shp.shp" + shp_save_path = r"C:\Users\Geoyee\Desktop\dd\shp_2.shp" mask = np.asarray(Image.open(ras_path).convert("P")) ras_ds = gdal.Open(ras_path) geot = ras_ds.GetGeoTransform() proj = ras_ds.GetProjection() - polygonize_raster(mask, shp_save_path, proj, geot) \ No newline at end of file + polygonize_raster(mask, shp_save_path, proj, geot, display=False) \ No newline at end of file