I am trying to merge different raster files into one using GEE. Since the data source of some of them is int, i am first transforming the rasters to float and then i am trying to merge them. However, the the output is missing some of the cells that i am trying to merge. The code I am using is:
var cell10 = cell_10.float()
var cell21 = cell_21.float()
var cell11 = cell_21.float()
var cell22 = cell_22.float()
var cell23 = cell_23.float()
var cell35 = cell_35.float()
var cell37 = cell_37.float()
var cell38 = cell_38.float()
var cell39 = cell_39.float()
var cell47 = cell_47.float()
var cell50 = cell_50.float()
var cell51 = cell_51.float()
var cell60 = cell_60.float()
var cell61 = cell_61.float()
var cell62 = cell_62.float()
var cell73 = cell_73.float()
var cell74 = cell_74.float()
var cell7 = cell_7.float()
var cell8 = cell_8.float()
var cell9 = cell_9.float()
var merged = ee.ImageCollection([cell10, cell21,cell11, cell22, cell23, cell35, cell37,
cell38, cell39, cell47, cell50, cell51, cell60, cell61, cell62, cell73, cell74, cell7, cell8, cell9,
worldcover]).mosaic()
I already tried to inspect each of the cells one by one by adding them to the map and printing them, and they all the same bands/ properties.
What am I doing wrong?
Thanks!
Related
I don't need empty how I should do, I think problem in lastrow funtion (see in picture)
I want to create pdf with can select area and select sheet without hide other sheet is posible ?
this is code(copy from some youtube)
function test() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var shtprint = ss.getSheetByName("Test print");
var shtkishu = ss.getSheetByName('proplan');
var shmaster = ss.getSheetByName('Master')
var shsetting = ss.getSheetByName('SETTING')
var shdata = ss.getSheetByName('DATA')
var shzttpp = ss.getSheetByName('ZTTPP038')
var LastRow = shtkishu.getRange(5,8).getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow();
var kishu = shtkishu.getRange(5,8,+LastRow).getValues().flat().map(v=>[v.slice(-7)]);
Logger.log(kishu)
for (var i = 0;i < kishu.length;i++){
shtprint.getRange('E2').setValue(kishu[i][0]);
var name = shtprint.getRange('E2').getValue();
shtkishu.hideSheet();
shmaster.hideSheet();
shsetting.hideSheet();
shdata.hideSheet();
shzttpp.hideSheet();
var folder = DriveApp.getFoldersByName("test").next();
var Blob = shtkishu.getParent().getBlob().getAs('application/pdf');
folder.createFile(Blob).setName(name);
}
shtkishu.showSheet();
}
don't know how to fix that
I'm attempting to combine two strings of rich text, while keeping their formatting.
function formatCombi() {
// get the sheet and the page
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// get the plaintext value of both cells, and their combined value
var text1 = sheet.getRange(1,1).getValue();
var text2 = sheet.getRange(1,2).getValue();
var text3 = text1 + text2;
var range = sheet.getRange(1,3);
// get the rich text value of both cells
var rtf1 = sheet.getRange(1,1).getRichTextValue();
var rtf2 = sheet.getRange(1,2).getRichTextValue();
// get the length of both strings and the combined length
var length1 = text1.length;
var length2 = text2.length;
var length3 = length1 + length2;
//get the formats of both strings
var bold1 = rtf1.getTextStyle().isBold();
var bold2 = rtf2.getTextStyle().isBold();
var italic1 = rtf1.getTextStyle().isItalic();
var italic2 = rtf2.getTextStyle().isItalic();
var under1 = rtf1.getTextStyle().isUnderline();
var under2 = rtf2.getTextStyle().isUnderline();
var strike1 = rtf1.getTextStyle().isStrikethrough();
var strike2 = rtf2.getTextStyle().isStrikethrough();
var colour1 = rtf1.getTextStyle().getForegroundColor();
var colour2 = rtf2.getTextStyle().getForegroundColor();
//create style for each string
const style1 = SpreadsheetApp.newTextStyle()
.setUnderline(under1)
.setBold(bold1)
.setItalic(italic1)
.setForegroundColor(colour1)
.build();
const style2 = SpreadsheetApp.newTextStyle()
.setUnderline(under2)
.setBold(bold2)
.setItalic(italic2)
.setForegroundColor(colour2)
.build();
//set the style for string based on the lengths
var rtf3 = SpreadsheetApp.newRichTextValue()
.setText(text3)
.setTextStyle(0,length1,style1)
.setTextStyle(length1,length3,style2)
.build();
range.setRichTextValues(rtf3);
}
This is the code I have so far, but for some reason it always spits out the same error code:
Exception: The parameters (String) don't match the method signature for SpreadsheetApp.Range.setRichTextValues.
formatCombi # Code.gs:70
Does anyone know why this is? I cant see the point of RichTextBuilder being able to have varied formatting if I can't set it as a value, and the examples of this from the documentation work fine.
I am working on a sheet that combines 10 CSV files that are stored in a google folder into one google sheet. I have been able to run the code previously, but I am starting to run into a lot of time based errors. I am hoping that someone can help streamline the following code. I know that I could run this in a loop, but I don't think that would be any faster.
//Sets Sheets to variable
var AUG = DriveApp.getFilesByName("Set1.csv").next();
var Sep1 = DriveApp.getFilesByName("Set2.csv").next();
var Sep2 = DriveApp.getFilesByName("Set3.csv").next();
var Oct1 = DriveApp.getFilesByName("Set4.csv").next();
var Oct2 = DriveApp.getFilesByName("Set5.csv").next();
var Nov1 = DriveApp.getFilesByName("Set6.csv").next();
var Nov2 = DriveApp.getFilesByName("Set7.csv").next();
var Dec1 = DriveApp.getFilesByName("Set8.csv").next();
var Dec2 = DriveApp.getFilesByName("Set9.csv").next();
var Dec3 = DriveApp.getFilesByName("Set10.csv").next();
//Parse String
var csvAUG = Utilities.parseCsv(AUG.getBlob().getDataAsString());
var csvNov1 = Utilities.parseCsv(Nov1.getBlob().getDataAsString());
var csvNov2 = Utilities.parseCsv(Nov2.getBlob().getDataAsString());
var csvOct1 = Utilities.parseCsv(Oct1.getBlob().getDataAsString());
var csvOct2 = Utilities.parseCsv(Oct2.getBlob().getDataAsString());
var csvSep1 = Utilities.parseCsv(Sep1.getBlob().getDataAsString());
var csvSep2 = Utilities.parseCsv(Sep2.getBlob().getDataAsString());
var csvDec1 = Utilities.parseCsv(Dec1.getBlob().getDataAsString());
var csvDec2 = Utilities.parseCsv(Dec2.getBlob().getDataAsString());
var csvDec3 = Utilities.parseCsv(Dec3.getBlob().getDataAsString());
//Determine Lengths
var rowset1 = csvAUG.length
var rowset2 = rowset1+csvSep1.length;
var rowset3 = rowset2+csvSep2.length;
var rowset4 = rowset3+csvOct1.length;
var rowset5 = rowset4+csvOct2.length;
var rowset6 = rowset5+csvNov1.length;
var rowset7 = rowset6+csvNov2.length;
var rowset8 = rowset7+csvDec1.length;
var rowset9 = rowset8+csvDec2.length;
var rowset10 = rowset9+csvDec3.length;
var colset = csvAUG[0].length;
//Start Combines CSV's for Scores
ss.setActiveSheet(ss.getSheetByName("Raw Scores"));
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.getRange(1, 1, rowset1, colset).setValues(csvAUG);
sheet.getRange(1+rowset2, 1, csvSep1.length, colset).setValues(csvSep1);
sheet.getRange(1+rowset3, 1, csvSep2.length, colset).setValues(csvSep2);
sheet.getRange(1+rowset4, 1, csvOct1.length, colset).setValues(csvOct1);
sheet.getRange(1+rowset5, 1, csvOct2.length, colset).setValues(csvOct2);
sheet.getRange(1+rowset6, 1, csvNov1.length, colset).setValues(csvNov1);
sheet.getRange(1+rowset7, 1, csvNov2.length, colset).setValues(csvNov2);
sheet.getRange(1+rowset8, 1, csvDec1.length, colset).setValues(csvDec1);
sheet.getRange(1+rowset9, 1, csvDec2.length, colset).setValues(csvDec2);
sheet.getRange(1+rowset10, 1, csvDec3.length,colset).setValues(csvDec3);
I am trying to copy over all of the values and formats to a different spreadsheet, week by week, creating a new sheet within the workbook each time. This is for archival purposes. I have pieced together the following:
function ArchiveByWeek(){
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('CRS Stats By Week')
var buildVersion = Browser.inputBox("What is the Weekend Ending Date?");
var sValues = source.getDataRange().getValues();
var sBG = source.getDataRange().getBackgrounds();
var sFC = source.getDataRange().getFontColors();
var sFF = source.getDataRange().getFontFamilies();
var sFL = source.getDataRange().getFontLines();
var sFFa = source.getDataRange().getFontFamilies();
var sFSz = source.getDataRange().getFontSizes();
var sFSt = source.getDataRange().getFontStyles();
var sFW = source.getDataRange().getFontWeights();
var sHA = source.getDataRange().getHorizontalAlignments();
var sVA = source.getDataRange().getVerticalAlignments();
var sNF = source.getDataRange().getNumberFormats();
var sWR = source.getDataRange().getWraps();
var destination = SpreadsheetApp.openById('1WVfJGDbdOewO2H-aMhQiek7sCOolK6xH7cSbfZ8KQgY');
var destinationSheet = destination.insertSheet(buildVersion, 1);
destinationSheet.getRange(1,1,sValues.length,sValues[0].length).setValues(sValues)
.setBackgrounds(sBG)
.setFontColors(sFC)
.setFontFamilies(sFF)
.setFontLines(sFL)
.setFontFamilies(sFFa)
.setFontSizes(sFSz)
.setFontStyles(sFSt)
.setFontWeights(sFW)
.setHorizontalAlignments(sHA)
.setVerticalAlignments(sVA)
.setNumberFormats(sNF)
.setWraps(sWR);
}
This seems to work fine, only some cells are not copied. For some reason, it is only cells that are summing other cells. Can't figure out why.
I found the following script, which worked perfectly, only I was unable to find a way to give each new sheet a unique name:
function copySheetValues(){
var source = SpreadsheetApp.getActiveSheet();
var sourcename = source.getSheetName();
var sValues = source.getDataRange().getValues();
var sBG = source.getDataRange().getBackgrounds();
var sFC = source.getDataRange().getFontColors();
var sFF = source.getDataRange().getFontFamilies();
var sFL = source.getDataRange().getFontLines();
var sFFa = source.getDataRange().getFontFamilies();
var sFSz = source.getDataRange().getFontSizes();
var sFSt = source.getDataRange().getFontStyles();
var sFW = source.getDataRange().getFontWeights();
var sHA = source.getDataRange().getHorizontalAlignments();
var sVA = source.getDataRange().getVerticalAlignments();
var sNF = source.getDataRange().getNumberFormats();
var sWR = source.getDataRange().getWraps();
var destination = SpreadsheetApp.openById('15ucPbZrIYXZAOCYVdpK6OA0oyQT1NcsmuiJmDRfdpHQ');
var destinationSheet = destination.insertSheet(sourcename, 0);
destinationSheet.getRange(1,1,sValues.length,sValues[0].length).setValues(sValues)
.setBackgrounds(sBG)
.setFontColors(sFC)
.setFontFamilies(sFF)
.setFontLines(sFL)
.setFontFamilies(sFFa)
.setFontSizes(sFSz)
.setFontStyles(sFSt)
.setFontWeights(sFW)
.setHorizontalAlignments(sHA)
.setVerticalAlignments(sVA)
.setNumberFormats(sNF)
.setWraps(sWR);
}
I was actually able to come up with a solution that I was satisfied with. This was able to paste all of the values, and formats exactly as they were on the sheet when viewing. It asks for a name of the new sheet, which was my intention:
function Archive() {
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SHEET NAME')
var sValues = source.getDataRange()
.getValues();
var weekEnding = Browser.inputBox("What is the Weekend Ending Date?");
var destination = SpreadsheetApp.openById('SHEET ID');
var copy = source.copyTo(destination)
.setName(weekEnding)
copy.getRange(1, 1, sValues.length, sValues[0].length)
.setValues(sValues); // overwrite all formulas that the copyTo preserved
Can someone help me how can I get the text between ; characters?
14;original;6711039;2;original;65535;9;6711039;52377;34;original;original
I need this:
var tag1:Number = 14
var tag2:String = original
var tag3:String = 6711039
var tag4:Number = 2
var tag5:String = original
... etc
how can I get it?
You are looking for String.split(), which takes a String and splits it into an array at a specific character.
var s:String = "14;original;6711039;2;original;65535;9;6711039;52377;34;original;original";
var a:Array = s.split(";");
var tag1:Number = a[0];
var tag2:String = a[1];
var tag3:String = a[2];
var tag4:Number = a[3];
var tag5:String = a[4];
Note: I didn't check if the tags are correctly aligned, so you may need to use different indexes.