2015年11月25日 星期三

ReNamer, Script for delete BEFORE or AFTER specific strings

Some PascalScripts for ReNamer


This Script search and delete filename AFTER the specific strings, include itself.


  1. { This script cut filename by string - }

  2. const
  3.   SEARCH_STRING = 'specific strings here';

  4. var
  5.   BaseName: WideString; Length, Position: Integer;

  6. begin
  7.   BaseName := WideExtractBaseName(FileName);
  8.   Length := WideLength(BaseName);
  9.   Position := WidePos(SEARCH_STRING, BaseName);
  10.   WideDelete(BaseName, Position-1, Length-Position+2);
  11.   FileName := BaseName + WideExtractFileExt(FileName);

  12. end.

This Script opposite to Search and delete filename BEFORE the specific strings, include itself too.


Custom Functions Unique()

Original Function Unique() returns each columns's unique rows in the provided source range.

This script return unique data in provided source range (in each cells) . Rows are returned and sorted.


  1. var cache = CacheService.getUserCache();
  2. function uniqueEach(input) {  
  3.   cache.put("unique", input); // drop input data into cache
  4.   var input = cache.get("unique").toString().split(",").sort(); // receive input as 1D array and sort it
  5.   var result = new Array();
  6.   var cell = input[0]; // give initial value to avoid error
  7.   result.push(cell);
  8.   for (i in input) {
  9.     if (cell != input[i]) {
  10.       cell = input[i];
  11.       result.push(cell);
  12.     }
  13.   }
  14.   return result;
  15. }
Use CacheService to get a simple and fast bunch of data.
And sort make data processing more easy.

Cache Service in Apps Script



Cache Service allows a script to temporarily cache results.

But puts values like Array into Cache, when you take it out will become a String.

Example :
#00#01#02
#10#11#12

Put array into cache when get will return a string.

#00,#01,#02,#10,#11,#12


So we can use Split string, return result to a array object.

#00#01#02#10#11#12

  1. var cache = CacheService.getUserCache();
  2. function putCache(key, array) {
  3.   cache.put(key, array);
  4. }
  5. function getCache(key) {
  6.   var result = cache.get(key).toString().split(",");
  7.   return result;
  8. }

2015年9月27日 星期日

QGIS : Merge two layers using Raster calculator include NoData values 合併圖層

Press Ctrl+Alt+M open commander

Open Processing algorithm: Raster calculator



QGIS 2.10.x
  • Main input layer 
Select first input layer ( as variable a, DEM, sea level == NoData )

Sea = white area

2015年9月25日 星期五

ImageMagick : Image split in two halves 左右分割


convert [path][filename.extension] [-options] -crop 2x1@ -set filename:tile "%t_%[fx:not(page.x)]" "[path]%[filename:tile].[extension]"

Split file into two images for right [filename_0] and left [filename_1].
Example :
convert image.png -crop 2x1@ -set filename:tile "%t_%[fx:not(page.x)]" "%[filename:tile].png"
Result : Right side image_0.png and left side image_1.png 
 convert image.jpg -crop 2x1@ -set filename:tile "%t_%[fx:not(notpage.x)]" "%[filename:tile].jpg"
Result : Left side image_0.jpg and right side image_1.jpg

2015年9月24日 星期四

QGIS : Merge two layers using Raster calculator 合併圖層

Press Ctrl+Alt+M open commander

Open Processing algorithm: Raster calculator



QGIS 2.10.x 


  • Main input layer 
Select first input layer ( as variable a, high resolution DEM, sea level == 0 )



QGIS : Set Zero values to Null using Raster calculator 替換數值

Press Ctrl+Alt+M open commander

Open Processing algorithm: Raster calculator



QGIS 2.8.x 
QGIS 2.10.x