Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduction of -fl (fixed levels) #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/raster_isobands/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ There are two scripts, that are used exacly the same and produce the same result

```
Usage: isobands_matplotlib.py [-h] [-b band] [-off offset] [-i interval]
[-fl fixed levels [fixed levels ...]]
[-nln layer_name] [-a attr_name] [-f formatname]
src_file out_file
Calculates the isobands from a raster into a vector file
Expand All @@ -22,6 +23,8 @@ There are two scripts, that are used exacly the same and produce the same result
-b band The band in the source file to process (default 1)
-off offset The offset to start the isobands (default 0)
-i interval The interval (default 0)
-fl fixed levels [fixed levels ...]
List of fixed levels (float)
-nln layer_name The out layer name (default bands)
-a attr_name The out layer attribute name (default h)
-f formatname The output file format name (default ESRI Shapefile)
Expand Down
2 changes: 1 addition & 1 deletion python/raster_isobands/isobands_gdal.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def isobands(in_file, band, out_file, out_format, layer_name, attr_name,
xsize_in = band_in.XSize
ysize_in = band_in.YSize

stats = band_in.GetStatistics(True, True)
stats = band_in.GetStatistics(False, True)

if min_level == None:
min_value = stats[0]
Expand Down
33 changes: 20 additions & 13 deletions python/raster_isobands/isobands_matplotlib.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
from os.path import exists
from os import remove
from argparse import ArgumentParser

import matplotlib
matplotlib.use('Agg') #workaround to make it run on systems without Xwindows
import matplotlib.pyplot as plt



def isobands(in_file, band, out_file, out_format, layer_name, attr_name,
offset, interval, min_level = None):
offset, interval, fixed_levels, min_level = None):
'''
The method that calculates the isobands
'''
Expand Down Expand Up @@ -58,17 +61,18 @@ def isobands(in_file, band, out_file, out_format, layer_name, attr_name,

raster_values = band_in.ReadAsArray(0, 0, xsize_in, ysize_in)

stats = band_in.GetStatistics(True, True)
if min_level == None:
min_value = stats[0]
min_level = offset + interval * floor((min_value - offset)/interval)

max_value = stats[1]
#Due to range issues, a level is added
max_level = offset + interval * (1 + ceil((max_value - offset)/interval))

levels = arange(min_level, max_level, interval)

if fixed_levels != None:
levels = fixed_levels
else:
stats = band_in.GetStatistics(False, True)
if min_level == None:
min_value = stats[0]
min_level = offset + interval * floor((min_value - offset)/interval)

max_value = stats[1]
#Due to range issues, a level is added
max_level = offset + interval * (1 + ceil((max_value - offset)/interval))
levels = arange(min_level, max_level, interval)
contours = plt.contourf(x_grid, y_grid, raster_values, levels)


Expand Down Expand Up @@ -120,6 +124,9 @@ def isobands(in_file, band, out_file, out_format, layer_name, attr_name,
PARSER.add_argument("-i",
help="The interval (default 0)",
type=float, default = 0.0, metavar = 'interval')
PARSER.add_argument("-fl",
help="List of fixed levels (float)",
type=float, nargs="+", metavar = 'fixed levels')
PARSER.add_argument("-nln",
help="The out layer name (default bands)",
default = 'bands', metavar = 'layer_name')
Expand All @@ -132,4 +139,4 @@ def isobands(in_file, band, out_file, out_format, layer_name, attr_name,
ARGS = PARSER.parse_args()

isobands(ARGS.src_file, ARGS.b, ARGS.out_file, ARGS.f, ARGS.nln, ARGS.a,
ARGS.off, ARGS.i)
ARGS.off, ARGS.i, ARGS.fl)