Skip to content

Commit

Permalink
Fix load CRS and add time
Browse files Browse the repository at this point in the history
  • Loading branch information
geoyee committed Dec 16, 2021
1 parent e57661b commit 3bdb502
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
15 changes: 12 additions & 3 deletions buildseg/buildSeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
14 changes: 8 additions & 6 deletions buildseg/utils/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
polygonize_raster(mask, shp_save_path, proj, geot, display=False)

0 comments on commit 3bdb502

Please sign in to comment.