Skip to content

Commit

Permalink
Merge 032b4b1 into 080c403
Browse files Browse the repository at this point in the history
  • Loading branch information
faselm committed May 22, 2020
2 parents 080c403 + 032b4b1 commit 2416547
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Not really useable now, wait on the first release.
Be sure you have:
- GNU Make: https://www.gnu.org/software/make/
- Docker: https://www.docker.com/
- Docker-compoe: https://docs.docker.com/compose/
- Docker-compose: https://docs.docker.com/compose/

Then run simply: `make run`

Expand Down
2 changes: 2 additions & 0 deletions data/mapfiles/fonts.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
arial fonts/Arial.TTF
arial_bold fonts/Arialbd.TTF
arial_italic fonts/Ariali.TTF
arial_bold_italic fonts/Arialbi.TTF
verdana_bold fonts/Verdanab.TTF
verdana_italic fonts/Verdanai.TTF
verdana fonts/Verdana.TTF
Expand Down
17 changes: 17 additions & 0 deletions data/mapfiles/raster_resampling_average.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LAYER
NAME "raster_simple_raster"
TYPE RASTER
PROCESSING "RESAMPLE=AVERAGE"
DATA "../rasters/raster.tif"
EXTENT -180 -90 180 90
METADATA
"wms_title" "raster_simple_raster"
"wms_srs" "EPSG:4326"
END
CLASS
NAME "Test raster"
STYLE
OPACITY 100
END
END
END
17 changes: 17 additions & 0 deletions data/mapfiles/raster_resampling_nearest.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LAYER
NAME "raster_simple_raster"
TYPE RASTER
PROCESSING "RESAMPLE=NEAREST"
DATA "../rasters/raster.tif"
EXTENT -180 -90 180 90
METADATA
"wms_title" "raster_simple_raster"
"wms_srs" "EPSG:4326"
END
CLASS
NAME "Test raster"
STYLE
OPACITY 100
END
END
END
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
LAYER
NAME "Simple raster"
TYPE RASTER
DATA "../rasters/raster.tif"
STATUS DEFAULT
CLASSITEM "[pixel]"
CLASS
NAME "0- 100"
EXPRESSION ( ( [pixel] > 0 ) AND ( [pixel] <= 100 ) )
STYLE
COLOR 0 255 0
OPACITY 100
END
END
CLASS
NAME "100 - 200"
EXPRESSION ( ( [pixel] > 100 ) AND ( [pixel] <= 200 ) )
STYLE
COLOR 0 0 255
OPACITY 100
END
END
END
25 changes: 25 additions & 0 deletions data/mapfiles/raster_simple_raster_many_classes_filter_ramp.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
LAYER
NAME "Simple raster"
TYPE RASTER
DATA "../rasters/raster.tif"
STATUS DEFAULT
CLASSITEM "[pixel]"
CLASS
NAME "0- 100"
EXPRESSION ( ( [pixel] > 0 ) AND ( [pixel] <= 100 ) )
STYLE
COLORRANGE 0 0 0 0 50 0
DATARANGE 0 100
RANGEITEM "pixel"
END
END
CLASS
NAME "100 - 200"
EXPRESSION ( ( [pixel] > 100 ) AND ( [pixel] <= 200 ) )
STYLE
COLORRANGE 0 50 0 0 50 80
DATARANGE 101 200
RANGEITEM "pixel"
END
END
END
23 changes: 23 additions & 0 deletions data/mapfiles/raster_simple_raster_many_classes_filter_values.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
LAYER
NAME "Simple raster"
TYPE RASTER
DATA "../rasters/raster.tif"
STATUS DEFAULT
CLASSITEM "[pixel]"
CLASS
NAME "0"
EXPRESSION "0"
STYLE
COLOR 0 255 0
OPACITY 100
END
END
CLASS
NAME "1"
EXPRESSION "1"
STYLE
COLOR 0 0 255
OPACITY 100
END
END
END
15 changes: 15 additions & 0 deletions data/styles/raster_resampling_average.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Style } from 'geostyler-style';

const rasterStyle: Style = {
'name': 'raster_simple_raster',
'rules': [{
'name': 'Test raster',
'symbolizers': [{
'kind': 'Raster',
'opacity': 1.0,
'resampling': 'linear'
}]
}]
};

export default rasterStyle;
15 changes: 15 additions & 0 deletions data/styles/raster_resampling_nearest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Style } from 'geostyler-style';

const rasterStyle: Style = {
'name': 'raster_simple_raster',
'rules': [{
'name': 'Test raster',
'symbolizers': [{
'kind': 'Raster',
'opacity': 1.0,
'resampling': 'nearest'
}]
}]
};

export default rasterStyle;
25 changes: 25 additions & 0 deletions data/styles/raster_simple_raster_many_classes_filter_intervals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Style } from 'geostyler-style';

const rasterStyle: Style = {
name: 'raster_simple_raster_many_classes_filter_intervals',
rules: [{
name: 'Test raster',
symbolizers: [{
kind: 'Raster',
colorMap: {
type: 'intervals',
colorMapEntries: [{
color: '#00FF00',
quantity: 100,
opacity: 1
}, {
color: '#0000FF',
quantity: 200,
opacity: 1
}]
},
}]
}]
};

export default rasterStyle;
27 changes: 27 additions & 0 deletions data/styles/raster_simple_raster_many_classes_filter_ramp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Style } from 'geostyler-style';

const rasterStyle: Style = {
name: 'raster_simple_raster_many_classes_filter_ramp',
rules: [{
name: 'Test raster',
symbolizers: [{
kind: 'Raster',
colorMap: {
type: 'ramp',
colorMapEntries: [{
color: '#000000',
quantity: 0
}, {
color: '#003200',
quantity: 100,
opacity: 1
}, {
color: '#003250',
quantity: 200
}]
},
}]
}]
};

export default rasterStyle;
25 changes: 25 additions & 0 deletions data/styles/raster_simple_raster_many_classes_filter_values.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Style } from 'geostyler-style';

const rasterStyle: Style = {
name: 'raster_simple_raster_many_classes_filter_values',
rules: [{
name: 'Test raster',
symbolizers: [{
kind: 'Raster',
colorMap: {
type: 'values',
colorMapEntries: [{
color: '#00FF00',
quantity: 0,
opacity: 1
}, {
color: '#0000FF',
quantity: 1,
opacity: 1
}]
},
}]
}]
};

export default rasterStyle;
45 changes: 45 additions & 0 deletions src/MapfileStyleParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import point_st_sample_point_style_tags_single_filter_regex from '../data/styles
import line_simple_line from '../data/styles/line_simple_line';
import polygon_simple_polygon from '../data/styles/polygon_simple_polygon';
import raster_simple_raster from '../data/styles/raster_simple_raster';
import raster_simple_raster_many_classes_filter_intervals from '../data/styles/raster_simple_raster_many_classes_filter_intervals';
import raster_simple_raster_many_classes_filter_values from '../data/styles/raster_simple_raster_many_classes_filter_values';
import raster_simple_raster_many_classes_filter_ramp from '../data/styles/raster_simple_raster_many_classes_filter_ramp';
import raster_resampling_average from '../data/styles/raster_resampling_average';
import raster_resampling_nearest from '../data/styles/raster_resampling_nearest';


it('MapfileStyleParser is defined', () => {
Expand Down Expand Up @@ -64,7 +69,47 @@ describe('MapfileStyleParser implements StyleParser', () => {
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(raster_simple_raster);
});
/*
it('can read a simple MapFile RasterSymbolizer with many classes intervals', async () => {
expect.assertions(2);
const mapfile = fs.readFileSync( './data/mapfiles/raster_simple_raster_many_classes_filter_intervals.map', 'utf8');
const geoStylerStyle = await styleParser.readStyle(mapfile);
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(raster_simple_raster_many_classes_filter_intervals);
});
it('can read a simple MapFile RasterSymbolizer with many classes values', async () => {
expect.assertions(2);
const mapfile = fs.readFileSync( './data/mapfiles/raster_simple_raster_many_classes_filter_values.map', 'utf8');
const geoStylerStyle = await styleParser.readStyle(mapfile);
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(raster_simple_raster_many_classes_filter_values);
});
it('can read a simple MapFile RasterSymbolizer with many classes ramp', async () => {
expect.assertions(2);
const mapfile = fs.readFileSync( './data/mapfiles/raster_simple_raster_many_classes_filter_ramp.map', 'utf8');
const geoStylerStyle = await styleParser.readStyle(mapfile);
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(raster_simple_raster_many_classes_filter_ramp);
});
it('can resample a simple MapFile RasterSymbolizer (average)', async () => {
expect.assertions(2);
const mapfile = fs.readFileSync( './data/mapfiles/raster_resampling_average.map', 'utf8');
const geoStylerStyle = await styleParser.readStyle(mapfile);
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(raster_resampling_average);
});
it('can resample a simple MapFile RasterSymbolizer (nearest)', async () => {
expect.assertions(2);
const mapfile = fs.readFileSync( './data/mapfiles/raster_resampling_nearest.map', 'utf8');
const geoStylerStyle = await styleParser.readStyle(mapfile);
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(raster_resampling_nearest);
});
*/
it('can read a simple MapFile Label', async () => {
expect.assertions(2);
const mapfile = fs.readFileSync( './data/mapfiles/point_simple_point_label.map', 'utf8');
Expand Down
32 changes: 30 additions & 2 deletions src/MapfileStyleParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,35 @@ export class MapfileStyleParser implements StyleParser {
}

/**
* Get the GeoStyler-Style Basic Symbolizer Parameter from an Mapfile STYLE / LABEL.
* Get the GeoStyler-Style RasterSymbolizer from an Mapfile STYLE.
*
* @param {object} styleParameters The Mapfile Style Parameters
* @return {RasterSymbolizer} The GeoStyler-Style RasterSymbolizer
*/
getRasterSymbolizerFromMapfileStyle(styleParameters: MapfileStyle): RasterSymbolizer {
const rasterSymbolizer = { kind: 'Raster' } as RasterSymbolizer;

if (styleParameters.opacity) {
rasterSymbolizer.opacity = styleParameters.opacity / 100;
}
/*
if (styleParameters.resamplingMethod) {
const resamplingMethod = styleParameters.resamplingMethod;
switch (resamplingMethod.toLowerCase()) {
case 'average':
rasterSymbolizer.resampling = 'linear';
break;
case 'nearest':
rasterSymbolizer.resampling = 'nearest';
break;
}
}
*/
return rasterSymbolizer;
}

/**
* Get the GeoStyler-Style Basic Symbolizer Parameter from an Mapfile STYLE.
*
* @param {MapfileStyle | MapfileLabel} styleParameters The Mapfile Style
* @return {Symbolizer} The GeoStyler-Style Symbolizer Parameters
Expand Down Expand Up @@ -667,7 +695,7 @@ export class MapfileStyleParser implements StyleParser {
symbolizer = this.getFillSymbolizerFromMapfileStyle(mapfileStyle);
break;
case 'raster':
symbolizer = { kind: 'Raster' } as RasterSymbolizer;
symbolizer = this.getRasterSymbolizerFromMapfileStyle(mapfileStyle);
break;
case 'query':
// layer can be queried but not drawn
Expand Down
22 changes: 17 additions & 5 deletions src/Useful.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
/**
* Convert a color in RGB (R G B) format to hexadecimal (#RRGGBB) format
*
* @param {string} s The string representing the color in RGB in the Mapfile file
* @return {string} The same color in hexadecimal format
*/
* Convert a color in RGB (R G B) format to hexadecimal (#RRGGBB) format
*
* @param {string} s The string representing the color in RGB in the Mapfile file
* @return {string} The same color in hexadecimal format
*/
export function rgbToHex(s: string): string {
const rgb = s.split(' ').map(Number);
// eslint-disable-next-line no-bitwise
return '#' + ((1 << 24) + (rgb[0] << 16) + (rgb[1] << 8) + rgb[2]).toString(16).toUpperCase().slice(1);
}

/**
* Convert a color range in RGB (R G B R G B) format to hexadecimal (#RRGGBB) array
*
* @param {string} s The strings representing the range of colors in RGB in the Mapfile file
* @return {string[]} The same colors as an array of strings in hexadecimal format
*/
export default function rgbRangeToHexArray(s: string): string[] {
const lowerBoundColor = rgbToHex(s.split(' ').slice(1, 3).join(' '));
const upperBoundColor = rgbToHex(s.split(' ').slice(4, 6).join(' '));
return [lowerBoundColor, upperBoundColor];
}

0 comments on commit 2416547

Please sign in to comment.