Comments (5)
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.
@csaybar @aixiaodetianshi @Lecaethomas I have improved the conversion script significantly. Check here.
from qgis-earthengine-examples.
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.
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.
@Lecaethomas Here are the steps:
- Clone the repo (
git clone https://github.com/giswqs/qgis-earthengine-examples.git
) - Copy whatever GEE JavaScripts you want to convert into the JavaScripts folder
- Run convert_js_to_python.py
- Check the converted Python scripts under the JavaScripts folder
- Depending on the complexity of your JavaScripts, additional manual changes might be needed.
from qgis-earthengine-examples.
Related Issues (8)
- Import shapefile/FilterBound HOT 2
- Test
- QGIS cannot install Google Earth Engine Plugins HOT 1
- ee.Classifier.svm is deprecated
- Getting an error while using "training = input.addBands(modis).sample({ 'numPixels': 5000, 'seed': 0 })"
- missing example - Geometry Visualization and Information
- How to export gee table using qgis+python? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qgis-earthengine-examples.