|
@@ -55,6 +55,10 @@ class RDigitController(wx.EvtHandler):
|
|
self._backgroundRaster = None
|
|
self._backgroundRaster = None
|
|
# name of temporary raster used to backup original state
|
|
# name of temporary raster used to backup original state
|
|
self._backupRasterName = None
|
|
self._backupRasterName = None
|
|
|
|
+ # if we edit an old raster or a new one (important for setting color table)
|
|
|
|
+ self._editOldRaster = False
|
|
|
|
+ # type of output raster map (CELL, FCELL, DCELL)
|
|
|
|
+ self._mapType = None
|
|
# GraphicsSet for drawing areas, lines, points
|
|
# GraphicsSet for drawing areas, lines, points
|
|
self._areas = None
|
|
self._areas = None
|
|
self._lines = None
|
|
self._lines = None
|
|
@@ -335,6 +339,8 @@ class RDigitController(wx.EvtHandler):
|
|
GError(parent=self._mapWindow, message=_("Failed to create backup copy of edited raster map."))
|
|
GError(parent=self._mapWindow, message=_("Failed to create backup copy of edited raster map."))
|
|
return False
|
|
return False
|
|
self._editedRaster = name
|
|
self._editedRaster = name
|
|
|
|
+ self._mapType = grast.raster_info(map=name)['datatype']
|
|
|
|
+ self._editOldRaster = True
|
|
return True
|
|
return True
|
|
|
|
|
|
def SelectNewMap(self):
|
|
def SelectNewMap(self):
|
|
@@ -374,7 +380,7 @@ class RDigitController(wx.EvtHandler):
|
|
gcore.run_command('r.colors', map=name, raster=self._backgroundRaster, quiet=True)
|
|
gcore.run_command('r.colors', map=name, raster=self._backgroundRaster, quiet=True)
|
|
if mapType == 'CELL':
|
|
if mapType == 'CELL':
|
|
values = gcore.read_command('r.describe', flags='1n',
|
|
values = gcore.read_command('r.describe', flags='1n',
|
|
- map=backgroundMap, quiet=True).strip()
|
|
|
|
|
|
+ map=name, quiet=True).strip()
|
|
if values:
|
|
if values:
|
|
self.uploadMapCategories.emit(values=values.split('\n'))
|
|
self.uploadMapCategories.emit(values=values.split('\n'))
|
|
except CalledModuleError:
|
|
except CalledModuleError:
|
|
@@ -383,6 +389,7 @@ class RDigitController(wx.EvtHandler):
|
|
|
|
|
|
name = name + '@' + gcore.gisenv()['MAPSET']
|
|
name = name + '@' + gcore.gisenv()['MAPSET']
|
|
self._editedRaster = name
|
|
self._editedRaster = name
|
|
|
|
+ self._mapType = mapType
|
|
self.newRasterCreated.emit(name=name)
|
|
self.newRasterCreated.emit(name=name)
|
|
|
|
|
|
def _backupRaster(self, name):
|
|
def _backupRaster(self, name):
|
|
@@ -426,16 +433,17 @@ class RDigitController(wx.EvtHandler):
|
|
(lastCellValue != item.GetPropertyVal('cellValue') or
|
|
(lastCellValue != item.GetPropertyVal('cellValue') or
|
|
lastWidthValue != item.GetPropertyVal('widthValue')):
|
|
lastWidthValue != item.GetPropertyVal('widthValue')):
|
|
if text:
|
|
if text:
|
|
- out = self._rasterize(text, lastWidthValue, tempRaster)
|
|
|
|
|
|
+ out = self._rasterize(text, lastWidthValue, self._mapType, tempRaster)
|
|
rastersToPatch.append(out)
|
|
rastersToPatch.append(out)
|
|
text = []
|
|
text = []
|
|
self._writeItem(item, text)
|
|
self._writeItem(item, text)
|
|
out = self._rasterize(text, item.GetPropertyVal('widthValue'),
|
|
out = self._rasterize(text, item.GetPropertyVal('widthValue'),
|
|
- tempRaster)
|
|
|
|
|
|
+ self._mapType, tempRaster)
|
|
rastersToPatch.append(out)
|
|
rastersToPatch.append(out)
|
|
text = []
|
|
text = []
|
|
else:
|
|
else:
|
|
self._writeItem(item, text)
|
|
self._writeItem(item, text)
|
|
|
|
+
|
|
lastCellValue = item.GetPropertyVal('cellValue')
|
|
lastCellValue = item.GetPropertyVal('cellValue')
|
|
lastWidthValue = item.GetPropertyVal('widthValue')
|
|
lastWidthValue = item.GetPropertyVal('widthValue')
|
|
|
|
|
|
@@ -444,14 +452,17 @@ class RDigitController(wx.EvtHandler):
|
|
wx.PostEvent(self, evt)
|
|
wx.PostEvent(self, evt)
|
|
if text:
|
|
if text:
|
|
out = self._rasterize(text, item.GetPropertyVal('widthValue'),
|
|
out = self._rasterize(text, item.GetPropertyVal('widthValue'),
|
|
- tempRaster)
|
|
|
|
|
|
+ self._mapType, tempRaster)
|
|
rastersToPatch.append(out)
|
|
rastersToPatch.append(out)
|
|
|
|
|
|
- gcore.run_command('r.patch', input=sorted(rastersToPatch, reverse=True) + [self._backupRasterName],
|
|
|
|
|
|
+ gcore.run_command('r.patch', input=rastersToPatch[::-1] + [self._backupRasterName],
|
|
output=self._editedRaster, overwrite=True, quiet=True)
|
|
output=self._editedRaster, overwrite=True, quiet=True)
|
|
gcore.run_command('g.remove', type='rast', flags='f', name=rastersToPatch + [tempRaster],
|
|
gcore.run_command('g.remove', type='rast', flags='f', name=rastersToPatch + [tempRaster],
|
|
quiet=True)
|
|
quiet=True)
|
|
try:
|
|
try:
|
|
|
|
+ # setting the right color table
|
|
|
|
+ if self._editOldRaster:
|
|
|
|
+ return
|
|
if not self._backgroundRaster:
|
|
if not self._backgroundRaster:
|
|
table = UserSettings.Get(group='rasterLayer', key='colorTable', subkey='selection')
|
|
table = UserSettings.Get(group='rasterLayer', key='colorTable', subkey='selection')
|
|
gcore.run_command('r.colors', color=table, map=self._editedRaster, quiet=True)
|
|
gcore.run_command('r.colors', color=table, map=self._editedRaster, quiet=True)
|
|
@@ -484,12 +495,13 @@ class RDigitController(wx.EvtHandler):
|
|
elif item in self._points.GetAllItems():
|
|
elif item in self._points.GetAllItems():
|
|
self._writeFeature(item, vtype='P', text=text)
|
|
self._writeFeature(item, vtype='P', text=text)
|
|
|
|
|
|
- def _rasterize(self, text, bufferDist, tempRaster):
|
|
|
|
|
|
+ def _rasterize(self, text, bufferDist, mapType, tempRaster):
|
|
"""Performs the actual rasterization using r.in.poly
|
|
"""Performs the actual rasterization using r.in.poly
|
|
and buffering with r.grow if required.
|
|
and buffering with r.grow if required.
|
|
|
|
|
|
:param str text: string in r.in.poly format
|
|
:param str text: string in r.in.poly format
|
|
:param float bufferDist: buffer distance in map units
|
|
:param float bufferDist: buffer distance in map units
|
|
|
|
+ :param str mapType: CELL, FCELL, DCELL
|
|
:param str tempRaster: name of temporary raster used in computation
|
|
:param str tempRaster: name of temporary raster used in computation
|
|
|
|
|
|
:return: output raster map name as a result of digitization
|
|
:return: output raster map name as a result of digitization
|
|
@@ -498,13 +510,15 @@ class RDigitController(wx.EvtHandler):
|
|
asciiFile = tempfile.NamedTemporaryFile(delete=False)
|
|
asciiFile = tempfile.NamedTemporaryFile(delete=False)
|
|
asciiFile.write('\n'.join(text))
|
|
asciiFile.write('\n'.join(text))
|
|
asciiFile.close()
|
|
asciiFile.close()
|
|
|
|
+
|
|
if bufferDist:
|
|
if bufferDist:
|
|
|
|
+ bufferDist /= 2.
|
|
gcore.run_command('r.in.poly', input=asciiFile.name, output=tempRaster,
|
|
gcore.run_command('r.in.poly', input=asciiFile.name, output=tempRaster,
|
|
- overwrite=True, quiet=True)
|
|
|
|
|
|
+ type_=mapType, overwrite=True, quiet=True)
|
|
gcore.run_command('r.grow', input=tempRaster, output=output,
|
|
gcore.run_command('r.grow', input=tempRaster, output=output,
|
|
flags='m', radius=bufferDist, quiet=True)
|
|
flags='m', radius=bufferDist, quiet=True)
|
|
else:
|
|
else:
|
|
gcore.run_command('r.in.poly', input=asciiFile.name, output=output,
|
|
gcore.run_command('r.in.poly', input=asciiFile.name, output=output,
|
|
- quiet=True)
|
|
|
|
|
|
+ type_=mapType, quiet=True)
|
|
os.unlink(asciiFile.name)
|
|
os.unlink(asciiFile.name)
|
|
return output
|
|
return output
|