0

Good people of stackoverflow.

I would like to write a custom function in google sheets for coordinate transformation. The function shuld transform coordinates in Slovene natioanl grid (EPSG: 3912) to WGS84 (EPSG: 4326). I think that this could be elegantly done with proj4js library.

But since I am complety new to javascript and Google app scripts I am wondering if it is possible to import a library to app scripts. I found out that proj4js is hosted on cdnjs and could be directly used in browser applications but I dont know how to import it in Google app scripts.

I tried to add this library by Script ID, where I used the proj4js cdnjs links as Script ID but I got an error: "Unable to look up library. Check the ID and access permissions and try again."

I would be really gratefull if anybody could help me overcome this rookie obstacle.

GregorS
  • 13
  • 4

1 Answers1

2

Fetch the content from the library URL with UrlFetchApp.fetch, and evaluate the retrieved content with eval().

You can then use this library.

Code sample:

const libraryUrl = "https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.3/proj4.min.js";
eval(UrlFetchApp.fetch(libraryUrl).getContentText());
proj4(...);
Iamblichus
  • 18,540
  • 2
  • 11
  • 27