LineString and multiLine openlayer3 - openlayers-3

I want to show lines on the map using ol.genom.lineString, my plan is in the future to implement 3 lines at the same time using multiLineString. My problem is that i cant figure out how the LineString should be implemented. this is where im at now:
http://jsfiddle.net/6RS2z/125/
(function(){
var map = new ol.Map({
layers: [new ol.layer.Tile({source: new ol.source.OSM()})],
target: document.getElementById('map'),
view: new ol.View({
center: [0, 0],
zoom: 1
})
});
var vectorSource = new ol.source.Vector({
//create empty vector
});
var plyFeature = new ol.Feature({
genometry : new ol.geom.LineString([0,0,18,60], 'EPSG:4326', 'EPSG:3857')
});
vectorSource.addFeature(plyFeature);
var plyLayer = new ol.layer.Vector({
source : vectorSource
})
map.addLayer(plyLayer);
})();

To create an ol.geom.LineString, you provide an array of points as first constructor argument:
var geom = new ol.geom.LineString([[0, 0], [18, 60]]);
To transform the geometry to the view projection, you do the following:
geom.transform('EPSG:4326', 'EPSG:3857');
When you create an ol.geom.MultiLineString, you provide an array of linestrings as first constructor argument:
var multigeom = new ol.geom.MultiLineString([
[[0, 0], [18, 60]],
[[18, 60], [9, 30]]
]);
Coordinate transforms work the same for all geometry types.

Related

Spectral signature of classified image in GEE using Random Forest

I am using this script to draw average spectral signature of all classes together and each class separately of a classified image by RF algorithm in GEE.
var bands = ['B1', 'B2', 'B3', 'B4','B5','B6','B7', 'B8', 'B8A', 'B9' ,'B11', 'B12','NDVI', 'EVI', 'GNDVI', 'NBR', 'NDII'];
var Training_Points = Water.merge(Residential).merge(Agricultural).merge(Arbusti).merge(BoschiMisti).merge(Latifoglie).merge(Conifere).merge(BareSoil);
var classes = ee.Image().byte().paint(Training_Points, "land_class").rename("land_class")
var stratified_points = classes.stratifiedSample({
numPoints: 50,
classBand: 'land_class',
scale: 10,
region: Training_Points,
geometries: false,
tileScale: 6
})
print(stratified_points, 'stratified_points')
//Create training data
var training_Stratified = RF_classified.select(bands).sampleRegions({
collection: stratified_points,
properties: ['land_class'],
scale:10,
tileScale:2
});
var bands = RF_classified.bandNames()
var numBands = bands.length()
var bandsWithClass = bands.add('land_class')
var classIndex = bandsWithClass.indexOf('land_class')
// Use .combine() to get a reducer capable of computing multiple stats on the input
var combinedReducer = ee.Reducer.mean().combine({
reducer2: ee.Reducer.stdDev(),
sharedInputs: true})
// Use .repeat() to get a reducer for each band and then use .group() to get stats by class
var repeatedReducer = combinedReducer.repeat(numBands).group(classIndex)
var stratified_points_Stats = training_Stratified.reduceColumns({
selectors: bands.add('land_class'),
reducer: repeatedReducer,
})
// Result is a dictionary, we do some post-processing to extract the results
var groups = ee.List(stratified_points_Stats.get('groups'))
var classNames = ee.List(['Water','Residential', 'Agricultural', 'Arbusti', 'BoschiMisti', 'Latifoglie','Conifere', 'BareSoil'])
var fc = ee.FeatureCollection(groups.map(function(item) {
// Extract the means
var values = ee.Dictionary(item).get('mean')
var groupNumber = ee.Dictionary(item).get('group')
var properties = ee.Dictionary.fromLists(bands, values)
var withClass = properties.set('class', classNames.get(groupNumber))
return ee.Feature(null, withClass)
}))
// Chart spectral signatures of training data
var options = {
title: 'Average Spectral Signatures',
hAxis: {title: 'Bands'},
vAxis: {title: 'Reflectance',
viewWindowMode:'explicit',
viewWindow: {
max:6000,
min:0
}},
lineWidth: 1,
pointSize: 4,
series: {
0: {color: '105af0'},
1: {color: 'dc350a'},
2: {color: 'caa712'},
3: {color: 'b9ffa4'},
4: {color: '369b47'},
5: {color: '21ff2d'},
6: {color: '275b25'},
7: {color: 'f7e084'},
}};
// Default band names don't sort propertly Instead, we can give a dictionary with labels for each band in the X-Axis
var bandDescriptions = {
'B2': 'B2/Blue',
'B3': 'B3/Green',
'B4': 'B4/Red',
'B5': 'B5/Red Edge 1',
'B6': 'B5/Red Edge 2',
'B7': 'B7/Red Edge 3',
'B8': 'B8/NIR',
'B8A': 'B8A/Red Edge 4',
'B11': 'B11/SWIR-1',
'B12': 'B12/SWIR-2'
}
// Create the chart and set options.
var chart = ui.Chart.feature.byProperty({
features: fc,
xProperties: bandDescriptions,
seriesProperty: 'class'
})
.setChartType('ScatterChart')
.setOptions(options);
print(chart)
var classChart = function(land_class, label, color) {
var options = {
title: 'Spectral Signatures for ' + label + ' Class',
hAxis: {title: 'Bands'},
vAxis: {title: 'Reflectance',
viewWindowMode:'explicit',
viewWindow: {
max:6000,
min:0
}},
lineWidth: 1,
pointSize: 4,
};
var fc = training_Stratified.filter(ee.Filter.eq('land_class', land_class))
var chart = ui.Chart.feature.byProperty({
features: fc,
xProperties: bandDescriptions,
})
.setChartType('ScatterChart')
.setOptions(options);
print(chart)
}
classChart(0, 'Water')
classChart(1, 'Residential')
classChart(2, 'Agricultural')
classChart(3, 'Arbusti')
classChart(4, 'BoschiMisti')
classChart(5, 'Latifoglie')
classChart(6, 'Conifere')
classChart(7, 'BareSoil')
I receive the error:
Error generating chart: Image.select: Pattern 'B1' did not match any
bands.
I do not understand where is the problem since I used the same script before to draw histogram of training data and it worked well.

Google Calendar Orderby when using two linq queries

I am using google charts to display a stacked column chart. I am using entity framework and linq queries to gather my data from the db.
The problems I am having is:
that it will not order the chart. I have ordered the chart but the x-axis remains un-ordered. Can this be done through the linq query or could I do it in the script?
Currently it only displays x-axis values for data that I have. Example is on the x-axis I have month number but it only displays marks for data I have eg. 1,4,5,6. Is there a way to include from 1-12 although there is no data for that particular month number?
Code:
#region Total Hours Per Month sick
var querythpshols = (from r in db.HolidayRequestForms
where (r.StartDate) >= dateAndTime
group r by r.MonthOfHoliday into g
select new { Value = g.Key, Count = g.Sum(h => h.HoursTaken)});
var resultthpshols = querythpshols.ToList();
var datachartthpshols = new object[resultthpshols.Count];
int G = 0;
foreach (var i in resultthpshols)
{
datachartthpshols[G] = new object[] { i.Value.ToString(), i.Count };
G++;
}
string datathpshols = JsonConvert.SerializeObject(datachartthpshols, Formatting.None);
ViewBag.datajthpshols = new HtmlString(datathpshols);
#endregion
#region Total Hours Per Month
var querythpshols1 = (from r in db.HolidayRequestForms
where (r.StartDate) <= dateAndTime
group r by r.MonthOfHoliday into g
select new { Value = g.Key, Count1 = g.Sum(r => r.HoursTaken) })
;
var resultthpshols1 = querythpshols1.ToList();
var datachartthpshols1 = new object[resultthpshols1.Count];
int P = 0;
foreach (var i in resultthpshols1)
{
datachartthpshols1[P] = new object[] { i.Value.ToString(), i.Count1 };
P++;
}
string datathpshols1 = JsonConvert.SerializeObject(datachartthpshols1, Formatting.None);
ViewBag.datajthpshols1 = new HtmlString(datathpshols1);
#endregion
Script:
#*TOTAL HOURS PER MONTH CHART*#
<scipt>
<script>
var datathpshols = '#ViewBag.datajthpshols';
var datassthpshols = JSON.parse(datathpshols);
var datathpshols1 = '#ViewBag.datajthpshols1';
var datassthpshols1 = JSON.parse(datathpshols1);
</script>
<script type="text/javascript">
// Load the Visualization API and the corechart package.
google.charts.load('current', { 'packages': ['corechart'] });
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChartA);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChartA() {
// Create the data table.
var data1 = new google.visualization.DataTable();
data1.addColumn('string', 'Value');
data1.addColumn('number', 'Holiday Hours Booked');
data1.addRows(datassthpshols);
var data2 = new google.visualization.DataTable();
data2.addColumn('string', 'Value');
data2.addColumn('number', 'Holiday Hours Taken');
data2.addRows(datassthpshols1);
var joinedData = google.visualization.data.join(data1, data2, 'full', [[0, 0]], [1], [1]);
// Set chart options
var options = {
'title': 'Holiday Hours Taken Per Month',
'width': 600,
'height': 350,
'hAxis': { title: 'Month Number' },
'vAxis': { title: 'Holiday Hours Taken' },
'is3D': true,
'isStacked': true,
'legend': 'right'
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ColumnChart(document.getElementById('chartTHPShols_div'));
chart.draw(joinedData, options);
}
</script>
1) Use data table method --> sort -- to order the x-axis.
joinedData.sort([{column: 0}]);
2) strings produce a discrete axis, and will only display the data available. numbers produce a continuous axis, and provide much more flexibility for the axis ticks. probably the most simplest solution would be to use a data view to convert the x-axis to numbers. (use the data view to draw the chart)
var joinedData = google.visualization.data.join(data1, data2, 'full', [[0, 0]], [1], [1]);
var dataView = new google.visualization.DataView(joinedData);
dataView.setColumns([{
calc: function (dt, row) {
return parseFloat(dt.getValue(row, 0));
},
label: joinedData.getColumnLabel(0),
type: 'number'
}, 1, 2]);
chart.draw(dataView, options);

title on vAxis isn't set but displayed on hAxis

I'm using Google Charts to display a SCATTER chart and the vAxis title is not displayed.
When I go on my chart graphic editor, I can see that my hAxis title is set but vAxis not.
For testing you can try with this simple code that reproduced the problem :
function test1() {
var app = SpreadsheetApp;
var classeur = app.getActiveSpreadsheet();
var sheet = classeur.getActiveSheet();
var range = sheet.getRange("A1:B7");
var data = [
['Age', 'Weight'],
[ 8, 12],
[ 4, 5.5],
[ 11, 14],
[ 4, 5],
[ 3, 3.5],
[ 6.5, 7]
];
range.setValues(data);
var chart = sheet.newChart()
.setChartType(Charts.ChartType.SCATTER)
.addRange(range)
.setPosition(5, 5, 0, 0)
.setOption('title','title')
.setOption('width', 300)
.setOption('height', 400)
.setOption('hAxis', {title: 'labelX'})
.setOption('vAxis', {title: 'labelY'})
.build()
sheet.insertChart(chart);
}
Thanks in advance for your help !

JsxGraph from Dart using Dart JS interop

I am trying to use the plotting library JSXGraph from Dart using dart js but I have problems.
This is working javascript code
var board = JXG.JSXGraph.initBoard(
'box',
{
boundingbox: [-10, 10, 2, -1],
axis: true,
keepaspectratio: false,
showNavigation: false
}
);
var graph = board.create(
'functiongraph',
[function(x){ return 3*x*x + 5*x + 1;}, -10, 10],
{strokeColor: '#ffff00'}
);
You can try it here on jsFiddle.
I want to do basically the identicall thing but from dart. This is what I have come up with so far:
JsObject jsxGraph = context['JXG']['JSXGraph'];
var board = jsxGraph.callMethod('initBoard', [
'box',
new JsObject.jsify({
'boundingbox': [-10, 10, 2, -1],
'axis': true,
'keepaspectratio': false,
'showNavigation': false
})
]);
var graph = board.callMethod('create', [
'functiongraph',
[(x){return 3*x*x + 5*x + 1;}, -10, 10],
new JsObject.jsify({'strokeColor': '#ffff00'})
]);
I get the plot area and axes but I can't get the actual plot line. Instead, there is an error on the console: Uncaught TypeError: this.Y is not a function.
Could someone, please, point me to what I could be doing wrong? I suspect it is something about the callback function but I really don't know what.
There's a jsify missing in your code:
JsObject jsxGraph = context['JXG']['JSXGraph'];
var board = jsxGraph.callMethod('initBoard', [
'box',
new JsObject.jsify({
'boundingbox': [-10, 10, 2, -1],
'axis': true,
'keepaspectratio': false,
'showNavigation': false
})
]);
var graph = board.callMethod('create', [
'functiongraph',
new JsObject.jsify([(x){return 3*x*x + 5*x + 1;}, -10, 10]},
new JsObject.jsify({'strokeColor': '#ffff00'})
]);

.Net MVC Radar Chart Polygon?

I'm trying to create a radar chart with the drawing style as polygon instead of circle in the MVC chart helper but i cannot find the AreaDrawingStyle anywhere in it.
I know in the regular ASP chart control i can do:
chart1.Series["Default"]["AreaDrawingStyle"] = "Polygon";
But in my MVC code, i have:
Chart myChart = new Chart(width: 600, height: 400)
.AddTitle("Chart Title")
.AddSeries(
name: "Employee",
chartType: "Radar",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: new[] { "20", "60", "41", "55", "33" });
Does anyone know where to find it? I searched lots of places but i am having a hard time finding specific details about this particular type of chart.
I just had to make my MVC chart use polygon as well. This link helped me a lot by allowing me to style the chart using the underlying System.Web.UI.DataVisualization.Charting classes:
http://truncatedcodr.wordpress.com/2012/09/18/system-web-helpers-chart-custom-themes/
In short, try this nasty stuff...
System.Web.UI.DataVisualization.Charting.ChartArea ca = new System.Web.UI.DataVisualization.Charting.ChartArea("Default");
var chart = new System.Web.UI.DataVisualization.Charting.Chart();
chart.Series.Add("MySeries");
chart.Series["MySeries"]["AreaDrawingStyle"] = "Polygon";
var cs = chart.Serializer;
cs.IsTemplateMode = true;
cs.Format = System.Web.UI.DataVisualization.Charting.SerializationFormat.Xml;
var sb = new System.Text.StringBuilder();
using ( System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(sb))
{
cs.Save(xw);
}
string theme = sb.ToString().Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
System.Web.Helpers.Chart myChart = new System.Web.Helpers.Chart(width: 1024, height: 768, theme:theme);
And now you have a whole new name space to look into for formatting your charts!

Resources