Changeset c04676b
- Timestamp:
- Apr 19, 2020, 6:20:04 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- f0e8020
- Parents:
- 2a31181
- Files:
-
- 4 edited
-
src/gnuboat/common/datahandler/loghandler.py (modified) (8 diffs)
-
src/gnuboat/common/spatial/tilegenerator.py (modified) (16 diffs)
-
src/gnuboat/common/tests/test_tilegenerator.py (modified) (4 diffs)
-
tox.ini (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/gnuboat/common/datahandler/loghandler.py
r2a31181 rc04676b 88 88 nmea_file_date_should = datetime.datetime.utcnow().strftime("%Y-%m-%d") 89 89 mode = 'A' 90 if self._nmea_file == None or self._nmea_file_date is None or self._nmea_file_date != nmea_file_date_should: 90 if (self._nmea_file is None or self._nmea_file_date is None or 91 self._nmea_file_date != nmea_file_date_should): 91 92 if self._nmea_file: 92 93 self._nmea_file.close() … … 189 190 } 190 191 191 """ Reads the original gnuboat log files and calls a callable function on all complete LogDataset192 callback must be of a function wich excepts the LogDataset as a parameter.193 """194 195 192 def gnuboat_read_file( 196 193 self, … … 200 197 errors_ignore=False 201 198 ): 199 """ 200 Reads the original gnuboat log files and calls a callable function 201 on all complete LogDataset callback must be of a function wich 202 excepts the LogDataset as a parameter. 203 """ 202 204 result = LogParsingResult() 203 205 … … 217 219 return result 218 220 219 """ Reads the original gnuboat log from input_list and calls a callable function on all complete LogDataset220 callback must be of a function wich excepts the LogDataset as a parameter.221 """222 223 221 def gnuboat_read( 224 222 self, input_list, callback, checksums_fix=False, errors_ignore=False 225 223 ): 224 """ 225 Reads the original gnuboat log from input_list and calls a callable 226 function on all complete LogDataset callback must be of a function 227 wich excepts the LogDataset as a parameter. 228 """ 226 229 result = LogParsingResult() 227 230 … … 272 275 last_row.water_depth_set(None) 273 276 last_row.water_temperature_set(None) 274 elif nmea_sentence.sentence_type == 'DPT' and last_row is not None: 277 elif (nmea_sentence.sentence_type == 'DPT' and 278 last_row is not None): 275 279 last_row.water_depth_set( 276 280 self._to_float(nmea_sentence.depth, current_row) 277 281 ) 278 elif nmea_sentence.sentence_type == 'MTW' and last_row is not None: 282 elif (nmea_sentence.sentence_type == 'MTW' and 283 last_row is not None): 279 284 last_row.water_temperature_set( 280 285 self._to_float(nmea_sentence.temperature, current_row) … … 294 299 except ValueError as error: 295 300 print( 296 'INFO: Failed to convert value from line {} into numeric: {}\n Message: {}' 297 .format(current_row, string, error) 301 ('INFO: Failed to convert value from line ' 302 '{} into numeric: {}\n Message: {}').format( 303 current_row, string, error) 298 304 ) 299 305 return 0 … … 306 312 if matches is None: 307 313 print( 308 'INFO: Failed to convert latitude position value from line {} into decimal degrees: {}'309 .format(current_row, nmea_value)314 ('INFO: Failed to convert latitude position value from line ' 315 '{} into decimal degrees: {}').format(current_row, nmea_value) 310 316 ) 311 317 return … … 321 327 if matches is None: 322 328 print( 323 'INFO: Failed to convert longitude position value from line {} into decimal degrees: {}'324 .format(current_row, nmea_value)329 ('INFO: Failed to convert longitude position value from line ' 330 '{} into decimal degrees: {}').format(current_row, nmea_value) 325 331 ) 326 332 return -
src/gnuboat/common/spatial/tilegenerator.py
r2a31181 rc04676b 33 33 from dataclasses import dataclass 34 34 35 #@dataclass36 #class TileWidth:37 #"""38 #tile_size: The tile size in Pixel,39 #longitude: The width of the Tile in decimal degrees40 #latitude: The height of the Tile in decimal degrees41 #"""42 #tile_size: int43 #longitude: float44 #latitude: float45 46 35 @dataclass 47 36 class ResultPath: 48 37 """ 49 path: Absolute path of the created results 50 prefixes: Dict with meaningful prefixes in the path. e.g. {'tile_size': '512', 'density': '10_100'} 51 """ 38 path: Absolute path of the created results 39 prefixes: Dict with meaningful prefixes in the path. e.g. 40 {'tile_size': '512', 'density': '10_100'} 41 """ 52 42 path: str 53 43 prefixes: dict 54 44 55 45 except ImportError: 56 #class TileWidth: 57 #""" 58 #Workaround for @dataclass, until python 3.7 is available in main distros 59 #""" 60 #def __init__(self, tile_size, longitude, latitude): 61 #self.tile_size = tile_size 62 #self.longitude = longitude 63 #self.latitude = latitude 64 46 # Workaround for @dataclass, until python 3.7 is available in 47 # main distros 65 48 class ResultPath: 66 49 """ 67 path: Absolute path of the created results 68 prefixes: Dict with meaningful prefixes in the path. e.g. {'tile_size': '512', 'density': '10_100'} 69 """ 50 path: Absolute path of the created results 51 prefixes: Dict with meaningful prefixes in the path. e.g. 52 {'tile_size': '512', 'density': '10_100'} 53 """ 70 54 def __init__(self, path, prefixes): 71 55 self.path = path … … 133 117 class RasterSlice(dict): 134 118 """ 135 lng_lat_box: LngLatBbox136 zoom_range: ZoomRange137 tile_size: The tile size in Pixel,138 grid_width: The width of the resulting rastr139 grid_height: The height of the resulting rastr140 141 It's derived from dict to be json serialisable142 """119 lng_lat_box: LngLatBbox 120 zoom_range: ZoomRange 121 tile_size: The tile size in Pixel, 122 grid_width: The width of the resulting rastr 123 grid_height: The height of the resulting rastr 124 125 It's derived from dict to be json serialisable 126 """ 143 127 def __init__( 144 128 self, lng_lat_box, zoom_range, tile_size, grid_width, grid_height … … 180 164 class TileGenerator: 181 165 """ 182 - tile_sizes = Array of tile sizes in pixel, which should be rendered 183 - zoom_range = Range of zooms, tiles are created for 184 - densities = Array with counts of data points per density_base, where tiles are created for 185 - density_base = Radios of circle as a datum plane for the densities values 186 - nodata_value = Value used for pixels without valid data 187 """ 166 - tile_sizes = Array of tile sizes in pixel, which should be rendered 167 - zoom_range = Range of zooms, tiles are created for 168 - densities = Array with counts of data points per density_base, where 169 tiles are created for 170 - density_base = Radios of circle as a datum plane for the densities 171 values 172 - nodata_value = Value used for pixels without valid data 173 """ 188 174 def __init__( 189 175 self, … … 200 186 self._debug = debug 201 187 202 # -999 is a workaround, as long gdal python api does not handle addAlpha 188 # -999 is a workaround, as long gdal python api does not handle 189 # addAlpha 203 190 self._colors = { 204 191 -999: '255 255 255', … … 213 200 def fit_extent_to_tiles(self, lng_lat_box, zoom_range): 214 201 """ 215 Enlarges the extent (given by lng_lat_box) to the borders of the tiles 216 lng_lat_box is of Type LngLatBbox217 """202 Enlarges the extent (given by lng_lat_box) to the borders of the 203 tiles lng_lat_box is of Type LngLatBbox 204 """ 218 205 tile_bounding = mercantile.bounding_tile( 219 206 lng_lat_box.west(), lng_lat_box.south(), lng_lat_box.east(), … … 241 228 ): 242 229 """ 243 Slice the complete area of input_file into smaller pieces, 244 so that each created raster file is smaller than raster_file_size_max 245 and cut into pieces at the borders of tiles and not thorugh tiles. 246 It returns an array of latitude longitude boxes representaing the borders, per slice. 247 """ 230 Slice the complete area of input_file into smaller pieces, 231 so that each created raster file is smaller than 232 raster_file_size_max and cut into pieces at the borders of 233 tiles and not thorugh tiles. It returns an array of latitude 234 longitude boxes representaing the borders, per slice. 235 """ 248 236 if tile_sizes is None: 249 237 tile_sizes = self._tile_sizes … … 259 247 LngLatBbox(west, south, east, north), zoom_range 260 248 ) 261 # The lng_lat_box is exactly on the border between tiles. Since there are rounding errors, 262 # we move the corner edges a very little bit (about a few mm) into the tile. This makes sure, 263 # that we only get those tiles returned, which are really in the lng_lat_box. 249 # The lng_lat_box is exactly on the border between tiles. 250 # Since there are rounding errors, we move the corner edges 251 # a very little bit (about a few mm) into the tile. This makes 252 # sure, that we only get those tiles returned, which are really 253 # in the lng_lat_box. 264 254 tiles_zoom_min = mercantile.tiles( 265 255 lng_lat_box.west() + 1 * 10**-7, … … 349 339 ): 350 340 """ 351 Runs all nescessary steps to create the tiles. 352 All default parameters equal to none are replaced by the one of the object 353 input_file = vrt source file used as a base for all steps to creating the tiles 354 Returns an array of paths with the created tiles if successfull 355 """ 341 Runs all nescessary steps to create the tiles. 342 All default parameters equal to none are replaced by the one 343 of the object input_file = vrt source file used as a base for 344 all steps to creating the tiles. Returns an array of paths with 345 the created tiles if successfull 346 """ 356 347 if densities is None: 357 348 densities = self._densities … … 364 355 datasource = self._datasource_open(input_file) 365 356 source_layer = datasource.GetLayerByIndex(0) 366 source_x_min, source_x_max, source_y_min, source_y_max = source_layer.GetExtent(367 )357 (source_x_min, source_x_max, 358 source_y_min, source_y_max) = source_layer.GetExtent() 368 359 source_layer_name = source_layer.GetName() 369 360 … … 379 370 tile_result_paths = [] 380 371 for density_min in densities: 381 gridding_algorithm = 'average:radius1={}:radius2={}:angle=0.0:min_points={}:nodata={}'.format( 372 gridding_algorithm = ('average:radius1={}:radius2={}:angle=0.0:' 373 'min_points={}:nodata={}').format( 382 374 radius_x, radius_y, density_min, nodata_value 383 375 ) … … 433 425 ) 434 426 # create the tiles 435 title = 'GNUBoat {} datasets per {} squaremetre, Tilesize: {}'.format( 427 title = ('GNUBoat {} datasets per {} squaremetre, ' 428 'Tilesize: {}').format( 436 429 density_min, density_base, tile_slice.tile_size() 437 430 ) … … 468 461 ): 469 462 """ 470 Rastering the data from source file into a tif.471 The input should be a vrt source file.472 The function returns the path to the generated tif file.473 """463 Rastering the data from source file into a tif. 464 The input should be a vrt source file. 465 The function returns the path to the generated tif file. 466 """ 474 467 if nodata_value is None: 475 468 nodata_value = self._nodata_value … … 504 497 ): 505 498 """ 506 Creates the hillshade from a raster tif file and returns the path to the resulting tif file 507 """ 499 Creates the hillshade from a raster tif file and returns the path 500 to the resulting tif file 501 """ 508 502 gdal.DEMProcessing( 509 503 output_file, … … 521 515 ): 522 516 """ 523 Creates the color relief from a raster tif and returns the path to the resulting tif file 524 """ 517 Creates the color relief from a raster tif and returns 518 the path to the resulting tif file 519 """ 525 520 if colors is None: 526 521 colors = self._colors … … 596 591 zoom_range.minimum(), zoom_range.maximum() 597 592 ) 598 # using the patched (tilesize) gdal2tiles.py script here, until the upstream version mades it in the distros 593 # using the patched (tilesize) gdal2tiles.py script here, until the 594 # upstream version mades it in the distros 599 595 subprocess.run([ 600 596 'gdal2tiles-gnuboat.py', '-q', '-w', 'none', 601 '--tilesize={}'.format(tile_size), '-z', tile_zoom_option, '-t', 602 title, input_file, output_directory 603 ], 604 check=True, 605 stdout=subprocess.PIPE, 606 stderr=subprocess.PIPE) 597 '--tilesize={}'.format(tile_size), '-z', tile_zoom_option, 598 '-t', title, input_file, output_directory], 599 check=True, 600 stdout=subprocess.PIPE, 601 stderr=subprocess.PIPE) 607 602 608 603 def move_tiles_in_place(self, source_path, target_path, skip_empty=True): 609 604 """ 610 Moves the generated tiles from the source_path into the target_path. 611 It moves file per file, so that the tiles are going to be integrated into an existing folder. 612 If skip_emtpy = True only one empty tile is copied to the top level directory. All other empty 613 tiles are not moved into target_path. 614 """ 605 Moves the generated tiles from the source_path into the 606 target_path. It moves file per file, so that the tiles are 607 going to be integrated into an existing folder. If 608 skip_emtpy = True only one empty tile is copied to the 609 top level directory. All other empty tiles are not moved 610 into target_path. 611 """ 615 612 copied_empty_tile = False 616 613 … … 663 660 return True 664 661 665 # def contours_create():662 # def contours_create(): 666 663 # @todo Cut Tifs / warp 667 #contour_input = gdal.Open(gdal_file, gdalconst.GA_ReadOnly) 668 #contour_input_band = contour_input.GetRasterBand(1) 669 ##Generate layer to save Contourlines in 670 #contour_output = ogr.GetDriverByName("ESRI Shapefile").CreateDataSource(gdal_file_contours) 671 #proj = osr.SpatialReference() 672 #proj.SetWellKnownGeogCS(input_epsg) 673 #for depth in colors: 674 #contour_layer = contour_output.CreateLayer('contour_{}_{}_{}'.format(density_min, density_base, depth), srs = proj) 675 #field_definition = ogr.FieldDefn("ID", ogr.OFTInteger) 676 #contour_layer.CreateField(field_definition) 677 #field_definition = ogr.FieldDefn("elev", ogr.OFTReal) 678 #contour_layer.CreateField(field_definition) 679 ##Generate Contourlines 680 #gdal.ContourGenerate(contour_input_band, depth, 0, [], 0, 0, contour_layer, 0, 1) 681 #contour_output = None 682 #del contour_output 683 #print(" Created contour lines {}".format(gdal_file_contours)) 684 685 #def crop(): 686 # cropping the tifs 687 #gdal.Warp('/tmp/gnuboat/test.tif', gdal_file_color_relief, options = gdal.WarpOptions(format = 'GTiff', dstAlpha = True, srcNodata = "255 255 255", dstNodata = target_nodata_value, cutlineDSName = '/tmp/gnuboat/contours/contour-0.shp', cutlineLayer="contour-0", cropToCutline=True)) 664 # contour_input = gdal.Open(gdal_file, gdalconst.GA_ReadOnly) 665 # contour_input_band = contour_input.GetRasterBand(1) 666 # Generate layer to save Contourlines in 667 # contour_output = ogr.GetDriverByName("ESRI Shapefile") 668 # .CreateDataSource(gdal_file_contours) 669 # proj = osr.SpatialReference() 670 # proj.SetWellKnownGeogCS(input_epsg) 671 # for depth in colors: 672 # contour_layer = contour_output.CreateLayer('contour_{}_{}_{}' 673 # .format(density_min, density_base, depth), srs = proj) 674 # field_definition = ogr.FieldDefn("ID", ogr.OFTInteger) 675 # contour_layer.CreateField(field_definition) 676 # field_definition = ogr.FieldDefn("elev", ogr.OFTReal) 677 # contour_layer.CreateField(field_definition) 678 # Generate Contourlines 679 # gdal.ContourGenerate(contour_input_band, depth, 0, [], 0, 0, 680 # contour_layer, 0, 1) 681 # contour_output = None 682 # del contour_output 683 # print(" Created contour lines {}".format(gdal_file_contours)) 684 685 # def crop(): 686 # cropping the tifs 687 # gdal.Warp('/tmp/gnuboat/test.tif', gdal_file_color_relief, 688 # options = gdal.WarpOptions(format = 'GTiff', dstAlpha = True, 689 # srcNodata = "255 255 255", dstNodata = target_nodata_value, 690 # cutlineDSName = '/tmp/gnuboat/c contours/contour-0.shp', 691 # cutlineLayer="contour-0", cropToCutline=True)) -
src/gnuboat/common/tests/test_tilegenerator.py
r2a31181 rc04676b 260 260 datasource = ogr.Open(datasource_vrt) 261 261 source_layer = datasource.GetLayerByIndex(0) 262 source_x_min, source_x_max, source_y_min, source_y_max = source_layer.GetExtent(263 )262 (source_x_min, source_x_max, 263 source_y_min, source_y_max) = source_layer.GetExtent() 264 264 source_layer_name = source_layer.GetName() 265 265 lon_metre_max = 60 * 1852 * math.cos( … … 272 272 273 273 tilegen = tilegenerator.TileGenerator() 274 gridding_algorithm = 'average:radius1={}:radius2={}:angle=0.0:min_points={}:nodata={}'.format( 274 gridding_algorithm = ('average:radius1={}:radius2={}:angle=0.0:' 275 'min_points={}:nodata={}').format( 275 276 radius_x, radius_y, 10, -999 276 277 ) … … 318 319 'density_base': 319 320 100, 320 'nodata_value': 321 -999, 321 'nodata_value': -999, 322 322 'skip_empty': 323 323 True … … 346 346 'density_base': 347 347 100, 348 'nodata_value': 349 -999, 348 'nodata_value': -999, 350 349 'skip_empty': 351 350 True -
tox.ini
r2a31181 rc04676b 27 27 pep8ignore = 28 28 src/gnuboat/mapservice_impl/tasks/tileconfig.py E701 29 src/gnuboat/common/spatial/tilegenerator.py E701 29 30 src/gnuboat/mapservice/controllers/*.py E501 30 31 src/gnuboat/mapservice/models/*.py E501 31 src/gnuboat/mapservice/test/test_.py E501 32 src/gnuboat/mapservice/test/*.py E501 W293 33 src/gnuboat/common/bin/gdal2tiles-gnuboat.py ALL
Note:
See TracChangeset
for help on using the changeset viewer.
