-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from orbisgis/groovy_exemple
Add groovy example page
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Groovy script with SQL | ||
======== | ||
|
||
Below is an example of how to use SQL instructions into Groovy script. | ||
|
||
.. code-block:: groovy | ||
import groovy.sql.Sql; | ||
def sql = Sql.newInstance(grv_ds); | ||
// Execute SQL request | ||
sql.execute("DROP TABLE IF EXISTS TEST") | ||
sql.execute("CREATE TABLE TEST AS SELECT 'POINT(1 3 10)'::geometry THE_GEOM") | ||
// Fetch results and print point coordinates | ||
// row["THE_GEOM"] is an instance of | ||
// http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Point.html | ||
sql.eachRow("SELECT * FROM TEST") { row -> | ||
pt = row["THE_GEOM"].getCoordinate() | ||
print(pt.x+" "+pt.y+" "+pt.z) | ||
} | ||
To see more, you can consult this tutorial_ from the Groovy documentation. | ||
|
||
|
||
.. _tutorial: http://docs.groovy-lang.org/latest/html/documentation/#_interacting_with_a_sql_database |