少し前まで、個人アカウント(gmail)用のGoogleスプレッドシートのスクリプトサービスが利用可能になりました。
googledocs.blogspot.com/2010/03/apps-script-gallery-for-google.html簡単な説明
www.google.com/google-ds/scripts/scripts.htmlさらに、テーブルから直接、ギャラリーにスクリプトを公開するサービスが利用可能になりました。
これで、Googleスプレッドシート用のスクリプトを作成し、既製をダウンロードして公開し、他のユーザーと共有できます。
スクリプトには豊富な機能があります。 Googleサービスで利用可能なすべてのコントロールを使用できます。
www.google.com/google-ds/scripts/overview.htmlたとえば、スクリプトの結果は次のようになります。
- 標準セットにはない新機能。
- SOAP、WSDLなどを含むWebサービスによって返される値。
- サイト、カレンダー、メーリングリストなどの他のサービスの管理。
- テーブルの自動入力(スプレッドシートの直接制御);
- ユーザーインターフェイスの作成(カスタムスプレッドシートUI)。
新地理で使用するために作成されたスクリプトの例大きな円弧に沿ったポイント間の距離の計算
Copy Source | Copy HTML
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
function GCD1(lat1, lon1, lat2, lon2) { // Return Great Circle Distance between points calculation function radians(a) { var outNum =Math.PI*a/180; return outNum; } var R = 6372.795; var d1=Math.sin(radians(lat1))*Math.sin(radians(lat2))+Math.cos(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var d2=Math.cos(radians(lat2))*Math.sin(radians(lon2)-radians(lon1)); var d3=Math.cos(radians(lat1))*Math.sin(radians(lat2))-Math.sin(radians(lat1))*Math.cos(radians(lat2))*Math.cos(radians(lon2)-radians(lon1)); var len=R*Math.atan2(Math.sqrt(d2*d2+d3*d3),d1); return len; }
ダイレクトジオコーディング場所名でKMLを返す
Copy Source | Copy HTML
- 関数getKML(placeName){
- // KMLを地名で返す
- if(placeName == ""){
- return "名前を場所に書く必要があります"
- }
- var url = "http://maps.google.com/maps/geo?q="+ placeName +"&output = kml ";
- var response = UrlFetchApp.fetch(url);
- var str = response.getContentText();
- return str;
- }
場所名で座標を返す
- 関数getLngLat(placeName){
- //地名でLngLatitudeを返します
- if(placeName == ""){
- return "名前を場所に書く必要があります"
- }
- var url = "http://maps.google.com/maps/geo?q="+ placeName +"&output = json ";
- var response = UrlFetchApp.fetch(url);
- var str = eval( '(' + response.getContentText()+ ')')。Placemark [0] .Point.coordinates;
- return str;
- }
場所名で経度を返す
- 関数getLng(placeName){
- //地名で経度を返します
- if(placeName == ""){
- return "名前を場所に書く必要があります"
- }
- var url = "http://maps.google.com/maps/geo?q="+ placeName +"&output = json ";
- var response = UrlFetchApp.fetch(url);
- var str = eval( '(' + response.getContentText()+ ')')。目印[0] .Point.coordinates [0];
- return str;
- }
場所名で緯度を返す
- 関数getLat(placeName){
- //地名で緯度を返します
- if(placeName == ""){
- return "名前を場所に書く必要があります"
- }
- var url = "http://maps.google.com/maps/geo?q="+ placeName +"&output = json ";
- var response = UrlFetchApp.fetch(url);
- var str = eval( '(' + response.getContentText()+ ')')。Placemark [0] .Point.coordinates [1];
- return str;
- }
逆ジオコーディング座標で住所を返す
- 関数getAddress(placeCoord){
- // placeCoord(逆ジオコーディング)で住所を返すplaceCoord = lat、lng
- if(placeCoord == ""){
- return "名前を場所に書く必要があります"
- }
- var url = "http://maps.google.com/maps/geo?q="+ placeCoord +"&output = json ";
- var response = UrlFetchApp.fetch(url);
- var str = eval( '(' + response.getContentText()+ ')')。Placemark [0] .address;
- return str;
- }
これらのスクリプトを使用した計算表の例news.eastgeology.com/2010/04/google-spreadsheets.html