Skip to content

Commit

Permalink
Provide an error message if there is a CRS mismatch. Fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
borysiasty committed Jan 9, 2018
1 parent fbce01b commit cbdf545
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ver 0.4.2
Provide an error message if there is a CRS mismatch. Fixes #5


ver 0.4.1
Multiselection of columns and bands with Ctrl and Shift keys

Expand All @@ -9,6 +13,7 @@ First Version for QGIS 2
ver 0.3.8 (The last version for QGIS 1.x)
Fix bug introduced in 0.3.7


ver 0.3.7
Optimizations for VRT rasters.
Recent (0.3.6) polygon optimizations ported also to API <=1.8
Expand Down
38 changes: 33 additions & 5 deletions doPointSamplingTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,49 @@ def accept(self): # Called when "OK" button pressed (based on the Carson Farmer'
for j in range(1, len(self.rastItems[i])):
if self.rastItems[i][j][2]:
nothingSelected = False

if self.inSample.currentText() == "":
self.tabWidget.setCurrentIndex(0)
QMessageBox.information(self, "Point Sampling Tool", "Please select vector layer containing the sampling points")
elif nothingSelected:
return
if nothingSelected:
self.tabWidget.setCurrentIndex(0)
QMessageBox.information(self, "Point Sampling Tool", "Please select at least one polygon or raster layer")
elif self.outShape.text() == "":
QMessageBox.information(self, "Point Sampling Tool", "Please select at least one polygon attribute or raster band")
return
if self.outShape.text() == "":
self.tabWidget.setCurrentIndex(0)
QMessageBox.information(self, "Point Sampling Tool", "Please specify output shapefile name")
return
# check if destination field names are unique
elif not self.testFieldsNames(self.fields):
if not self.testFieldsNames(self.fields):
self.updateFieldsTable()
self.tabWidget.setCurrentIndex(1)
QMessageBox.warning(self, "Point Sampling Tool", "At least two field names are the same!\nPlease type unique names.")
else:
return

# Check if there a CRS mismatch
pointLayerSrid = self.sampItems.values()[0][0].crs().postgisSrid()
msg = u'''<html>All layers must have the same coordinate refere system. The <b>%s</b> layer seems to have different CRS id (<b>%d</b>)
than the point layer (<b>%d</b>). If they are two different CRSes, you need to reproject one of the layers first,
otherwise results will be wrong.<br/>
However, if you are sure both CRSes are the same, and they are just improperly recognized, you can safely continue.
Do you want to continue?</html>'''
for i in self.polyItems:
for j in range(1, len(self.polyItems[i])):
if self.polyItems[i][j][2]:
layerSrid = self.polyItems[i][0].crs().postgisSrid()
if layerSrid != pointLayerSrid:
if QMessageBox.question(self, "Point Sampling Tool: layer CRS mismatch!", msg % (i, layerSrid, pointLayerSrid), QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
return
for i in self.rastItems:
for j in range(1, len(self.rastItems[i])):
if self.rastItems[i][j][2]:
layerSrid = self.rastItems[i][0].crs().postgisSrid()
if layerSrid != pointLayerSrid:
if QMessageBox.question(self, "Point Sampling Tool: layer CRS mismatch!", msg % (i, layerSrid, pointLayerSrid), QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
return

if True:
# all tests passed! Let's go on
self.statusLabel.setText("Processing the output file name...")
self.repaint()
Expand Down
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name=Point sampling tool
description=Samples polygon attributes and raster values from multiple layers at specified sampling points
description[pl]=Próbkuje atrybuty poligonów i/lub wartości rastra (również z wielu warstw naraz) w podanych punktach.
about=The Point Sampling Tool Plugin collects polygon attributes and raster values from multiple layers at specified sampling points. You need a point layer with locations of sampling points and at least one polygon or raster layer to probe values from. The plugin creates a new point layer with locations given by the sampling points and attributes taken from all the underlying polygons or/and raster cells. Please use Control and Shift keys in order to select multiple columns and bands. Note this tool is not compatible with mulitipoint sources, unless each multipoint contains exactly one point. Using multipoint samples that contain more points in multipoints may produce unreliable results.
version=0.4.1
version=0.4.2
qgisMinimumVersion=2.0

# Optional items:
Expand Down

0 comments on commit cbdf545

Please sign in to comment.