Skip to content

Commit

Permalink
add srs to shp + model autocomplete step 3
Browse files Browse the repository at this point in the history
  • Loading branch information
nkarasiak committed Feb 20, 2016
1 parent f30b09c commit c962416
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
17 changes: 11 additions & 6 deletions function_historical_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import gmm_ridge as gmmr
import scipy as sp
from scipy import ndimage
from osgeo import gdal, ogr
from osgeo import gdal, ogr, osr
from PyQt4.QtGui import QProgressBar, QApplication
from PyQt4 import QtCore
from qgis.utils import iface
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self,inImage,outName,inShapeGrey,inShapeMedian,iterMedian):
d = data.RasterCount

# Progress Bar
maxStep=d*2+(2*iterMedian)
maxStep=d+d*iterMedian
try:
filterProgress=progressBar(' Filtering...',maxStep)
except:
Expand Down Expand Up @@ -280,7 +280,7 @@ def __init__(self,inRaster,inVector,inField='Class',inSplit=0.5,inSeed=0,outMode
learningProgress.reset()
learningProgress=None
def scale(self,x,M=None,m=None):
"""@brief! Function that standardize the data.
"""!@brief Function that standardize the data.
Input:
x: the data
Expand Down Expand Up @@ -310,7 +310,7 @@ def scale(self,x,M=None,m=None):
return xs,M,m

class classifyImage():
"""@brief! Classify image with learn clasifier and learned model
"""!@brief Classify image with learn clasifier and learned model
Create a raster file, fill hole from your give class (inClassForest), convert to a vector,
remove parcel size which are under a certain size (defined in inMinSize) and save it to shp.
Expand Down Expand Up @@ -430,11 +430,16 @@ def __init__(self,inRaster,inModel,outShpFile,inMask=None,inMinSize=5000,inNODAT
if os.path.exists(outShpFile):
driver.DeleteDataSource(outShpFile)
outDatasource = driver.CreateDataSource(outShpFile)
outLayer = outDatasource.CreateLayer(outShpFile, srs=None)
# get proj from raster
srs = osr.SpatialReference()
srs.ImportFromWkt( sourceRaster.GetProjectionRef() )
# create layer with proj
outLayer = outDatasource.CreateLayer(outShpFile,srs)
# Add class column (1,2...) to shapefile
newField = ogr.FieldDefn('Class', ogr.OFTInteger)
outLayer.CreateField(newField)
gdal.Polygonize(band, None,outLayer, 0,[],callback=None)
gdal.Polygonize()
outDatasource.Destroy()
sourceRaster = None
except:
Expand Down Expand Up @@ -686,4 +691,4 @@ def reset(self):
#classified=classifyImage(outFilter,outModel,outShpFile,None,6000,-10000,1)

# inFilteredStep3,inTrainingStep3,outRasterClass,None,inMinSize,None,'Class',inNODATA=-10000
# inRaster,inModel,outRaster,inMask=None,inMinSize=6,outShpFolder='img/samples/outSHP/',inField='Class',inNODATA=-10000
# inRaster,inModel,outRaster,inMask=None,inMinSize=6,outShpFolder='img/samples/outSHP/',inField='Class',inNODATA=-10000
10 changes: 7 additions & 3 deletions historical_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def __init__(self, iface):
self.dlg.outShp.clear()
self.dlg.selectOutShp.clicked.connect(self.select_output_file)


## init fields

self.dlg.inTraining.currentIndexChanged[int].connect(self.onChangedLayer)

## By default field list is empty, so we fill with current layer
Expand Down Expand Up @@ -233,8 +235,8 @@ def unload(self):
def select_output_file(self):
"""!@brief Select file to save, and gives the right extension if the user don't put it"""
sender = self.sender()

fileName = QFileDialog.getSaveFileName(self.dlg, "Select output file","")
fileName = QFileDialog.getSaveFileName(self.dlg, "Select output file")

if not fileName:
return
Expand Down Expand Up @@ -342,6 +344,7 @@ def runTrain(self):
QtGui.QMessageBox.warning(self, 'Information missing or invalid', message, QtGui.QMessageBox.Ok)

else:

# Getting variables from UI
inFiltered=self.dlg.inFiltered.currentLayer()
inFiltered=inFiltered.dataProvider().dataSourceUri()
Expand All @@ -360,7 +363,8 @@ def runTrain(self):
inSeed=int(inSeed)
inSplit=self.dlg.inSplit.value()


# add model to step 3
self.dlg.inModel.setText(outModel)
# Do the job
fhm.learnModel(inFiltered,inTraining,inField,inSplit,inSeed,outModel,outMatrix,inClassifier)

Expand Down
6 changes: 3 additions & 3 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
name=Historical Map
qgisMinimumVersion=2.0
description=Automatic vectorization of old forests from historical maps
version=0.5
version=0.5.1
author=Nicolas Karasiak (aka Nicolaï Van Lennepkade), Antoine Lomellini
email=karasiak.nicolas@gmail.com

about=Made by Nicolas Karasiak & Antoine Lomellini<br>Based on the work of Pierre-Alexis with the help of Mathieu Fauvel.<br><br>This plugin allow the user to filter an image (tif) with closing filter and median filter (you can set the parameters), then you can train with a shapefile of your perimeter, and to finish you get a shapefile with your selected class (ie: a shapefile of the forest from historical map, of your wine parcels...)<br><br><b>We suggest you to install sklearn before installing the plugin (or you will be forced to use GMM classifier and not KNN,RF or SVM).<br>For more information you can consult our tutorial at the <a href="https://github.com/lennepkade/Historical-Map/">Historical Map plugin page</a>.
about=Made by Nicolas Karasiak & Antoine Lomellini<br>Based on the work of Pierre-Alexis with the help of Mathieu Fauvel.<br><br>This plugin allow the user to filter an image (tif) with closing filter and median filter (you can set the parameters), then you can train with a shapefile of your perimeter, and to finish you get a shapefile with your selected class (ie: a shapefile of the forest from historical map, or of the vineyards...)<br><br><b>We suggest you to install SciKit-Learn before installing the plugin (or you will be forced to use GMM classifier and not KNN,RF or SVM).<br>For more information you can consult our tutorial at the <a href="https://github.com/lennepkade/Historical-Map/">Historical Map plugin page</a>.

tracker=https://github.com/lennepkade/HistoricalMap/issues
repository=https://github.com/lennepkade/HistoricalMap/
Expand All @@ -23,7 +23,7 @@ repository=https://github.com/lennepkade/HistoricalMap/
# Recommended items:

# Uncomment the following line and add your changelog:
# changelog=
changelog=Add projection for the shp at the last step<br>If you save a model at step 2, it will be automatically added at step 3

# Tags are comma separated with spaces allowed
tags=historicalmap,classify,filter,old map,forest
Expand Down

0 comments on commit c962416

Please sign in to comment.