diff --git a/display/displaydrivers.md b/display/displaydrivers.md index e05ade705dc..f8009785c97 100644 --- a/display/displaydrivers.md +++ b/display/displaydrivers.md @@ -19,7 +19,7 @@ this variable. Currently only Python scrips are supported. Lets start with simple example of Python script called *render.py*: -```sh +```python #!/usr/bin/env python3 import os diff --git a/general/g.findfile/g.findfile.md b/general/g.findfile/g.findfile.md index cae7b0bd2fb..92395d688ba 100644 --- a/general/g.findfile/g.findfile.md +++ b/general/g.findfile/g.findfile.md @@ -81,10 +81,10 @@ more info. Note: The Python tab in the *wxGUI* can be used for entering the following code: -```sh -import grass.script as gcore +```python +import grass.script as gs -gcore.find_file('elevation', element = 'cell') +gs.find_file('elevation', element = 'cell') ``` ## SEE ALSO diff --git a/general/g.parser/g.parser.md b/general/g.parser/g.parser.md index f1da65d3fe8..c4f1c377c93 100644 --- a/general/g.parser/g.parser.md +++ b/general/g.parser/g.parser.md @@ -257,6 +257,9 @@ Example: ```sh v.in.db driver=sqlite database=mysqlite.db table=pointsfile x=x y=y z=z key=idcol out=dtmpoints --json +``` + +```json { "module": "v.in.db", "id": "v.in.db_1804289383", @@ -348,7 +351,7 @@ Parameters: ### Example code for Python -```sh +```python #!/usr/bin/env python3 # g.parser demo script for python programming @@ -471,7 +474,7 @@ g.message message="Value of GIS_OPT_vect: '$GIS_OPT_vector'" ### Example code for Perl -```sh +```perl #!/usr/bin/perl -w use strict; @@ -543,7 +546,9 @@ output is shown below: ```sh v.what.rast --script +``` +```python #!/usr/bin/env python3 ############################################################################ # diff --git a/general/g.version/g.version.md b/general/g.version/g.version.md index 3f910bbeff5..b0d9aa4b2d8 100644 --- a/general/g.version/g.version.md +++ b/general/g.version/g.version.md @@ -21,10 +21,10 @@ printed by **-e** flag. See also function `version()` from [Python Scripting Library](https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library). -```sh -import grass.script as gcore +```python +import grass.script as gs -print gcore.version() +print(gs.version()) ``` ## EXAMPLES diff --git a/lib/init/grass.md b/lib/init/grass.md index 7f2f1c37237..d6388efc722 100644 --- a/lib/init/grass.md +++ b/lib/init/grass.md @@ -341,7 +341,7 @@ grass /path/to/grassdata/test1/PERMANENT/ --exec python test.py A very simple Python script ("test.py") may look like this: -```sh +```python #!/usr/bin/env python3 # import GRASS Python bindings (see also pygrass) diff --git a/raster/r.category/r.category.md b/raster/r.category/r.category.md index 8cdda5f5d2d..31dcd789523 100644 --- a/raster/r.category/r.category.md +++ b/raster/r.category/r.category.md @@ -154,7 +154,7 @@ r.category map=landclass96 cats=3,4 output_format=json generates the following JSON output: -```sh +```json [ { "category": 3, diff --git a/raster/r.horizon/r.horizon.md b/raster/r.horizon/r.horizon.md index 39a323de854..259b908fd66 100644 --- a/raster/r.horizon/r.horizon.md +++ b/raster/r.horizon/r.horizon.md @@ -188,14 +188,14 @@ r.horizon elevation=elevation direction=0 step=5 bufferzone=200 \ ``` ![](rhorizon_shaded_dem_point.png) -Test point near high way intersection (North Carolina sample dataset) +*Test point near high way intersection (North Carolina sample dataset)* ![](rhorizon_singlepoint_plot.png) -Horizon angles for test point (CCW from East) +*Horizon angles for test point (CCW from East)* We can plot horizon in polar coordinates using Matplotlib in Python: -```sh +```python import numpy as np import matplotlib.pyplot as plt @@ -212,7 +212,7 @@ plt.show() ``` ![](rhorizon_polar_plot.png) -Horizon plot in polar coordinates. +*Horizon plot in polar coordinates.* ### Raster map mode diff --git a/raster/r.in.lidar/r.in.lidar.md b/raster/r.in.lidar/r.in.lidar.md index 9d276ba2373..62a9b042f88 100644 --- a/raster/r.in.lidar/r.in.lidar.md +++ b/raster/r.in.lidar/r.in.lidar.md @@ -430,8 +430,7 @@ r.in.lidar input="Serpent Mound Model LAS Data.laz" \ output=Serpent_Mound_Model_LAS_Data method=mean ``` -![](r_in_lidar.png) - +![](r_in_lidar.png) *Figure: Elevation for the whole area of Serpent Mound dataset* ### Height above ground @@ -492,7 +491,7 @@ r.in.lidar file=/home/user/data/filelist.txt output=mean_height_above_ground bas In Python, the list of files can be created using the *glob* Python module: -```sh +```python import glob import grass.script as gs diff --git a/raster/r.info/r.info.md b/raster/r.info/r.info.md index 6f8fc7d8532..3949021e49d 100644 --- a/raster/r.info/r.info.md +++ b/raster/r.info/r.info.md @@ -126,7 +126,7 @@ Finally, the output from *r.info* can be output in JSON by passing the r.info slope format=json ``` -```sh +```json { "north": 228500, "south": 215000, diff --git a/raster/r.mask.status/r.mask.status.md b/raster/r.mask.status/r.mask.status.md index 7bf5bb96203..bc9bb3d8cd0 100644 --- a/raster/r.mask.status/r.mask.status.md +++ b/raster/r.mask.status/r.mask.status.md @@ -30,7 +30,7 @@ r.mask.status format=json In Python, use: -```sh +```python import grass.script as gs gs.parse_command("r.mask.status", format="json") ``` diff --git a/raster/r.object.geometry/r.object.geometry.md b/raster/r.object.geometry/r.object.geometry.md index 606b32eb3d9..3920699206e 100644 --- a/raster/r.object.geometry/r.object.geometry.md +++ b/raster/r.object.geometry/r.object.geometry.md @@ -40,7 +40,7 @@ JSON: r.object.geometry input=zipcodes format=json ``` -```sh +```json [ { "category": 1, diff --git a/raster/r.profile/r.profile.md b/raster/r.profile/r.profile.md index d62ece79517..074cff6ca9f 100644 --- a/raster/r.profile/r.profile.md +++ b/raster/r.profile/r.profile.md @@ -127,7 +127,7 @@ r.profile -g input=elevation coordinates=641712,226095,641546,224138,641546,2220 The output looks as follows: -```sh +```json [ { "easting": 641712, @@ -192,7 +192,7 @@ The JSON output makes for ease of integration with popular python data science libraries. For instance, here is an example of creating a scatterplot of distance vs elevation with color coding. -```sh +```python import grass.script as gs import pandas as pd import matplotlib.pyplot as plt diff --git a/raster/r.report/r.report.md b/raster/r.report/r.report.md index a64cff7db41..3c1a0ee5f06 100644 --- a/raster/r.report/r.report.md +++ b/raster/r.report/r.report.md @@ -127,7 +127,7 @@ The output from *r.report* can be output in JSON by passing the r.report -n -a map=towns,elevation units=miles,meters,kilometers,acres,hectares,cells,percent nsteps=2 format=json ``` -```sh +```json { "location": "nc_spm_08_grass7", "created": "2024-07-24T14:59:09+0530", diff --git a/raster/r.solute.transport/r.solute.transport.md b/raster/r.solute.transport/r.solute.transport.md index dd93ad0cb1a..15fa5fd5e38 100644 --- a/raster/r.solute.transport/r.solute.transport.md +++ b/raster/r.solute.transport/r.solute.transport.md @@ -83,7 +83,7 @@ Use this small python script to create a working groundwater flow / solute transport area and data. Make sure you are not in a lat/lon projection. -```sh +```python #!/usr/bin/env python3 # This is an example script how groundwater flow and solute transport are # computed within GRASS GIS diff --git a/raster/r.sun/r.sun.md b/raster/r.sun/r.sun.md index d80e347b91d..ebc0e5255ce 100644 --- a/raster/r.sun/r.sun.md +++ b/raster/r.sun/r.sun.md @@ -290,7 +290,7 @@ d.rast.leg it172 We can compute the day of year from a specific date in Python: -```sh +```python >>> import datetime >>> datetime.datetime(2014, 6, 21).timetuple().tm_yday 172 diff --git a/raster/r.univar/r.univar.md b/raster/r.univar/r.univar.md index 775d19561ab..188ef718dcc 100644 --- a/raster/r.univar/r.univar.md +++ b/raster/r.univar/r.univar.md @@ -226,7 +226,7 @@ r.univar -e elevation percentile=98 format=json will output the results in JSON format: -```sh +```json [ { "n": 2025000, diff --git a/scripts/i.band.library/i.band.library.md b/scripts/i.band.library/i.band.library.md index 2fe6f490fa4..cd8dde02115 100644 --- a/scripts/i.band.library/i.band.library.md +++ b/scripts/i.band.library/i.band.library.md @@ -108,7 +108,7 @@ designed in order to support image collections in GRASS GIS. Band reference information is stored in JSON files with a pre-defined internal data structure. A minimalistic example is shown below. -```sh +```json { "Sentinel2": { "description": "The Sentinel-2 A/B bands", diff --git a/temporal/t.rast.list/t.rast.list.md b/temporal/t.rast.list/t.rast.list.md index 4222626b31d..a05f79cde40 100644 --- a/temporal/t.rast.list/t.rast.list.md +++ b/temporal/t.rast.list/t.rast.list.md @@ -194,7 +194,7 @@ dataset [t.vect.list](t.vect.list.md#using-method-option) ### Reading raster names in Python -```sh +```python result = json.loads( gs.read_command( "t.rast.list", input="tempmean_monthly", format="json" diff --git a/vector/v.db.select/v.db.select.md b/vector/v.db.select/v.db.select.md index 5e27eeeb6fb..310803f8c30 100644 --- a/vector/v.db.select/v.db.select.md +++ b/vector/v.db.select/v.db.select.md @@ -56,7 +56,7 @@ to parse this format when configured to the above specification. Example with default settings: -```sh +```csv cat,road_name,multilane,year,length 1,"NC-50","no",2001,4825.369405 2,"NC-50","no",2002,14392.589058 @@ -106,7 +106,7 @@ the SQL types. The definition of `is_number` may change in the future. Example with added indentation: -```sh +```json { "info": { "columns": [ @@ -319,7 +319,7 @@ The *json* package in the standard Python library can load a JSON string obtained as output from the *v.db.select* module through the *read_command* function: -```sh +```python import json import grass.script as gs diff --git a/vector/v.distance/v.distance.md b/vector/v.distance/v.distance.md index 42ca31138ed..7d3b0ad4e1e 100644 --- a/vector/v.distance/v.distance.md +++ b/vector/v.distance/v.distance.md @@ -217,7 +217,7 @@ from_cat to_cat dist v.distance -p from=busroute_a to=busstopsall upload=dist,to_attr to_column=routes format=json ``` -```sh +```json [ { "from_cat": 1, diff --git a/vector/v.info/v.info.md b/vector/v.info/v.info.md index bb996ef5291..e9ceb3cdff3 100644 --- a/vector/v.info/v.info.md +++ b/vector/v.info/v.info.md @@ -136,7 +136,7 @@ bottom=0.000000 ### Output in JSON format -```sh +```json { "name": "geology", "mapset": "PERMANENT", @@ -187,17 +187,17 @@ more info. Note: The Python tab in the *wxGUI* can be used for entering the following code: -```sh -import grass.script as gcore +```python +import grass.script as gs -gcore.vector_columns('geology') # for `v.info -c` -gcore.vector_info_topo('geology') # for `v.info shell=topo` +gs.vector_columns('geology') # for `v.info -c` +gs.vector_info_topo('geology') # for `v.info shell=topo` ``` Here is an example of how the JSON output format can be used to integrate Grass with other python libraries easily. -```sh +```python import grass.script as gs import pandas as pd diff --git a/vector/v.univar/v.univar.md b/vector/v.univar/v.univar.md index 226c621c6f3..c63d11fc40c 100644 --- a/vector/v.univar/v.univar.md +++ b/vector/v.univar/v.univar.md @@ -127,7 +127,7 @@ v.univar -e samples column=heights type=point format=json will output the results in JSON format: -```sh +```json { "n": 1832, "missing": 0,