Skip to content

4.4 Use H2GIS with Python

Bocher edited this page Mar 9, 2018 · 15 revisions

Introduction

The following example demonstrates how to use H2GIS with the Python scripting language. The advantage is the ability to run it on dedicated server without X11.

Requirements:

  • To use H2GIS, you have to install Java from version 7.

Install H2GIS

To install H2GIS, follow this steps:

  • Download the latest H2GIS version on the home page, unzip it.
  • On Linux you can execute the following commands:
~ $ wget https://github.com/orbisgis/h2gis/releases/download/v1.3.2/h2gis-dist-1.3.2-bin.zip -O h2gis.zip
~ $ unzip h2gis.zip

Install psycopg2

http://initd.org/psycopg/docs/install.html#installation

Run H2GIS as a PosgreSQL sever mode

On Windows

java -cp "bin/org.osgi.compendium-4.3.1.jar;bin/cts-1.4.0.jar;bin/slf4j-simple-1.6.0.jar;bin/h2gis-ext-1.3.2.jar;bin/commons-compress-1.9.jar;bin/jts-io-1.14.0.jar;bin/h2gis-api-1.3.2.jar;bin/org.osgi.core-4.3.1.jar;bin/postgis-jts-osgi-5.0.1.jar;bin/jackson-core-2.3.1.jar;bin/h2gis-dist-1.3.2.jar;bin/h2gis-network-1.3.2.jar;bin/h2gis-utilities-1.3.2.jar;bin/h2-1.4.196.jar;bin/poly2tri-core-0.1.2.jar;bin/jts-core-1.14.0.jar;bin/slf4j-api-1.6.0.jar;bin/json-simple-1.1.jar;bin/java-network-analyzer-0.1.6.jar;bin/jgrapht-core-0.9.0.jar;bin/h2gis-functions-1.3.2.jar" org.h2.tools.Server -pg

On Linux

java -cp  bin/org.osgi.compendium-4.3.1.jar:bin/cts-1.4.0.jar:bin/slf4j-simple-1.6.0.jar:bin/h2gis-ext-1.3.2.jar:bin/commons-compress-1.9.jar:bin/jts-io-1.14.0.jar:bin/h2gis-api-1.3.2.jar:bin/org.osgi.core-4.3.1.jar:bin/postgis-jts-osgi-5.0.1.jar:bin/jackson-core-2.3.1.jar:bin/h2gis-dist-1.3.2.jar:bin/h2gis-network-1.3.2.jar:bin/h2gis-utilities-1.3.2.jar:bin/h2-1.4.196.jar:bin/poly2tri-core-0.1.2.jar:bin/jts-core-1.14.0.jar:bin/slf4j-api-1.6.0.jar:bin/json-simple-1.1.jar:bin/java-network-analyzer-0.1.6.jar:bin/jgrapht-core-0.9.0.jar:bin/h2gis-functions-1.3.2.jar org.h2.tools.Server -pg

Initialize the H2GIS extension

Execute the following SQL syntax:

CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load";
CALL H2GIS_SPATIAL();