Giter VIP home page Giter VIP logo

Comments (5)

giswqs avatar giswqs commented on August 22, 2024 1

I have improved convert_js_to_python.py. See the example below. Simply change in_file_path to your JavaScript file path or in_dir to your JavaScript folder.

As @csaybar mentioned, the conversion is not always perfect. Depending on the complexity of your scripts, some manual changes might be needed.

if __name__ == '__main__':

    ## Convert one JavaScript file to Python
    root_dir = os.path.dirname(os.path.abspath(__file__))
    in_file_path = os.path.join(root_dir, "JavaScripts/NormalizedDifference.js")  # change this path to your JavaScript file
    out_file_path = os.path.splitext(in_file_path)[0] + ".py"
    js_to_python(in_file_path, out_file_path)
    print("Saved python script: {}".format(out_file_path))

    ## Convert all JavaScript files in a folder to Python
    in_dir = os.path.join(root_dir, "JavaScripts")   # change this path to your JavaScript folder
    for in_file_path in Path(in_dir).rglob('*.js'):
        out_file_path = os.path.splitext(in_file_path)[0] + ".py"
        js_to_python(in_file_path, out_file_path)
    print("Saved python script folder: {}".format(in_dir))

from qgis-earthengine-examples.

giswqs avatar giswqs commented on August 22, 2024 1

@csaybar @aixiaodetianshi @Lecaethomas I have improved the conversion script significantly. Check here.

from qgis-earthengine-examples.

csaybar avatar csaybar commented on August 22, 2024

You might use the cover_js_to_python module to help you in the translation. However, additional changes could also be necessary, it's depending on code complexity. A reproducible example here

#script
!wget https://raw.githubusercontent.com/giswqs/qgis-earthengine-examples/master/convert_js_to_python.py
#js example
!wget https://raw.githubusercontent.com/renelikestacos/Google-Earth-Engine-JavaScript-Examples/master/010-modis_zonal_statistics_calculation.js
from convert_js_to_python import js_to_python
in_file_path = '/content/010-modis_zonal_statistics_calculation.js'
with open(in_file_path, 'r') as f:
  for line in f:
    print(line)
js_to_python('/content/010-modis_zonal_statistics_calculation.js')
with open(in_file_path, 'r') as f:
  for line in f:
    print(line)

from qgis-earthengine-examples.

Lecaethomas avatar Lecaethomas commented on August 22, 2024

Hi,
I'm really interested too, I have a lot of JS script, but I don't get how you make your script work. Could you give explanation about the context and method? By advance thanks,
Thomas

from qgis-earthengine-examples.

giswqs avatar giswqs commented on August 22, 2024

@Lecaethomas Here are the steps:

  1. Clone the repo (git clone https://github.com/giswqs/qgis-earthengine-examples.git)
  2. Copy whatever GEE JavaScripts you want to convert into the JavaScripts folder
  3. Run convert_js_to_python.py
  4. Check the converted Python scripts under the JavaScripts folder
  5. Depending on the complexity of your JavaScripts, additional manual changes might be needed.

from qgis-earthengine-examples.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.