OpenGauss database PostGIS installation and use

Table of contents

 

overview

1. PostGIS installation

1.1 GCC-7.3 compiler installation

1.2PostGIS dependent library installation

1.3. Install Postgis

2. Use Extensions

2.1 Create PostGIS Extension

2.2 Using Extensions

2.3 Delete Extension


 

overview

PostGIS Extension is the spatial database extension of PostgreSQL, which provides the following spatial information service functions: spatial objects, spatial indexes, spatial operation functions and spatial operators. PostGIS Extension fully follows the OpenGIS specification. openGauss provides PostGIS Extension (version PostGIS-2.4.2) , which needs to be installed separately.

1. PostGIS installation

Environmental information: Centos 7.6 + openGauss 3.1.0 Minimal Edition

The environment needs to be connected to the Internet to download some dependent packages.

1.1 GCC-7.3 compiler installation

PostGIS installation depends on the GCC-7.3 compiler ( GNU Compiler Suite ) . If the GCC-7.3 compiler has already been installed in the database instance, you can directly skip this step. My local environment is 4.8.5 and needs to be upgraded.

 

The GCC-7.3 compiler is recommended to use the source code to upgrade and install from the lower version of the gcc and g++ compilers. If there are no low-version gcc and g++ compilers in the database instance, they can be installed by mounting the operating system image, etc., and will not be described here.

 

wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz 

[omm@openGhostxx gcc-7.3.0]$ tar -zxvf gcc-7.3.0.tar.gz

[omm@openGhostxx packages]$ cd gcc-7.3.0

[omm@openGhostxx gcc-7.3.0]$ ./contrib/download_prerequisites

This step will download some dependencies, and you need to ensure that you are connected to the Internet.

./configure --prefix=/usr/local/gcc-7.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib  --disable-libsanitizer --disable-libcilkrts

 

Then make, the time will be relatively long, very long.

make   

make install

After completion, the installation directory will be prompted, which will be used later.

 

Set the environment variable, otherwise gcc -v is still the old version.

Open the ~/.bashrc file in the vim editor.

vi ~/.bashrc

Add the following content , and replace the actual path with the path of the previous make install according to the situation.

export CC=/usr/local/gcc-7.3.0/bin/gcc

export CXX=/usr/local/gcc-7.3.0/bin/g++

export LD_LIBRARY_PATH=/usr/local/gcc-7.3.0/lib/../lib64:$LD_LIBRARY_PATH

export PATH=/usr/local/gcc-7.3.0/bin:$PATH

Then source takes effect

source ~/.bashrc

Last check

 

 

1.2PostGIS dependent library installation

  1. Download the postgis plugin package and decompress and rename it.
​
[omm@openGhostxx ~]$ cd $GAUSSHOME/

[omm@openGhostxx openGauss]$ wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/dependency/postgis-xc-master-2020-09-17.tar.gz

[omm@openGhostxx openGauss]$ tar -zxvf postgis-xc-master-2020-09-17.tar.gz

[omm@openGhostxx openGauss]$ mv postgis-xc-master postgis-xc/

​

 

2. Download the patch file to the $GAUSSHOME/postgis-xc/ directory, and enter the patch.

Download path: gpl_dependency/postgis/postgis_2.4.2-2.patch · openGauss/openGauss-third_party - Gitee.com

cd $GAUSSHOME/postgis-xc/

[omm@openGhostxx postgis-xc]$ patch -p1 < $GAUSSHOME/postgis_2.4.2-2.patch

patching file gdal-1.11.0/frmts/postgisraster/postgisraster.h

patching file gdal-1.11.0/ogr/ogrsf_frmts/pg/ogr_pg.h

patching file gdal-1.11.0/ogr/ogrsf_frmts/pg/ogrpgutility.h

patching file postgis-2.4.2/configure

patching file postgis-2.4.2/postgis--2.4.2.sql

patching file postgis-2.4.2/postgis_svn_revision.h

patching file postgis-2.4.2/raster/rt_pg/rtpostgis.c

patching file postgis-2.4.2/topology/Makefile.in

patching file postgis-2.4.2/topology/postgis_topology.c

patching file postgis-2.4.2/topology/sql/topogeometry/totopogeom.sql.in

patching file postgis-2.4.2/topology/sql/topogeometry/type.sql.in

patching file postgis-2.4.2/topology/topology.sql.in

3. Download the postgis dependency header file from the website https://gitee.com/opengauss/openGauss-third_party/blob/master/gpl_dependency/postgis/extension_dependency.h to $GAUSSHOME/include/postgresql/server/.

 

4. Compile proj

When the PROJ framework is doing projection and coordinate system conversion, its operation style is similar to Linux Shell commands.

cd $GAUSSHOME/postgis-xc/proj-4.9.2

chmod +x ./configure

./configure --prefix=$GAUSSHOME/install/proj

make -sj

make install -sj

 

5. Compile Geos

 

The predecessor of GEOS is JTS , which provides full-featured and powerful spatial operation and spatial judgment.

cd $GAUSSHOME/postgis-xc/geos-3.6.2

chmod +x ./configure

./configure --prefix=$GAUSSHOME/install/geos

make -sj

make install -sj

6. Compile libxml

libxml is a library for parsing xml files , which can be used on all platforms and supports multiple languages .

cd $GAUSSHOME/postgis-xc/libxml2-2.7.1

chmod +x ./configure

./configure --prefix=$GAUSSHOME/install/libxml2

make -sj

make install -sj

7. Install JSON -C

 

JSON-C implements a reference-counted object model that allows you to easily use C to build JSON objects, output them as JSON-formatted strings, and parse JSON-formatted strings back into C-language representations of JSON objects.

 

cd $GAUSSHOME/postgis-xc/json-c-json-c-0.12.1-20160607

chmod +x ./configure

./configure --prefix=$GAUSSHOME/install/json

make -sj

make install -sj

1.3. Install Postgis

cd $GAUSSHOME/postgis-xc/postgis-2.4.2

chmod +x ./configure

./configure --prefix=$GAUSSHOME/install/postgis2.4.2 --with-pgconfig=$GAUSSHOME/bin/pg_config --with-projdir=$GAUSSHOME/install/proj --with-geosconfig=$GAUSSHOME/install/geos/bin/geos-config --with-jsondir=$GAUSSHOME/install/json  --with-xml2config=$GAUSSHOME/install/libxml2/bin/xml2-config   --without-raster --without-topology CFLAGS='-O2 -fpermissive -DPGXC  -pthread -D_THREAD_SAFE -D__STDC_FORMAT_MACROS -DMEMORY_CONTEXT_CHECKING -w'  CC=g++

make -sj

make install -sj

 

If the compilation shows that /home/carrot/data/openGauss-server/third_party/buildtools/gcc/res/lib64/libstdc++.la cannot be found, you can create a directory by yourself, copy libstdc++.la into it, and then make -sj ( If libstdc++.so has a similar problem, handle it in the same way).

 

 

The omm user executes the following statement to complete the distribution of PostGIS-related dynamic link libraries in the database instance nodes. Because my openGauss is a stand-alone minimalist version, I use cp to copy to the node path. If the enterprise version needs to use tranfer.py, please refer to the PostGIS installation chapter of the openGauss product documentation for details.

mv $GAUSSHOME/lib/postgresql/postgis-2.4.so $GAUSSHOME/install/postgis-2.4.so


cp $GAUSSHOME/install/postgis-2.4.so $GAUSSHOME/lib/postgresql/postgis-2.4.so

cp $GAUSSHOME/install/json/lib/libjson-c.so.2 $GAUSSHOME/lib/libjson-c.so.2

cp $GAUSSHOME/install/geos/lib/libgeos_c.so.1 $GAUSSHOME/lib/libgeos_c.so.1

cp $GAUSSHOME/install/proj/lib/libproj.so.9 $GAUSSHOME/lib/libproj.so.9

cp $GAUSSHOME/install/geos/lib/libgeos-3.6.2.so $GAUSSHOME/lib/libgeos-3.6.2.so

cp $GAUSSHOME/install/postgis2.4.2/lib/liblwgeom-2.4.so.0 $GAUSSHOME/lib/liblwgeom-2.4.so.0

cp $GAUSSHOME/postgis-xc/postgis-2.4.2/postgis--2.4.2.sql $GAUSSHOME/share/postgresql/extension/postgis--2.4.2.sql

cp $GAUSSHOME/postgis-xc/postgis-2.4.2/postgis.control $GAUSSHOME/share/postgresql/extension/postgis.control

Finally restart the database instance.

gs_ctl stop -D /opt/software/openGauss/data/single_node/

gs_ctl start -D /opt/software/openGauss/data/single_node/

 

2. Use Extensions

The following SQL statements show the simple use of PostGIS. For the specific use of each function, please refer to the "PostGIS-2.4.2 User Manual".

2.1 Create PostGIS Extension

It can be created directly using the CREATE EXTENSION command:

openGauss=# CREATE EXTENSION postgis;

2.2 Using Extensions

 

Example 1: Creation of geometry table.

CREATE TABLE cities ( id integer, city_name varchar(50) );

SELECT AddGeometryColumn('cities', 'position', 4326, 'POINT', 2);

 

Example 2: Insertion of geometric data.

INSERT INTO cities (id, position, city_name) VALUES (1,ST_GeomFromText('POINT(-9.5 23)',4326),'CityA');

INSERT INTO cities (id, position, city_name) VALUES (2,ST_GeomFromText('POINT(-10.6 40.3)',4326),'CityB');

INSERT INTO cities (id, position, city_name) VALUES (3,ST_GeomFromText('POINT(20.8 30.3)',4326), 'CityC');

Example 3: Calculate the distance between any two cities among three cities.

SELECT p1.city_name,p2.city_name,ST_Distance(p1.position,p2.position) FROM cities AS p1, cities AS p2 WHERE p1.id > p2.id;v

 

 

2.3 Delete Extension

The method of deleting PostGIS Extension in openGauss is as follows:

DROP EXTENSION postgis CASCADE;

 Note: If the Extension is dependent on other objects (such as the created geometry table), you need to add the CASCADE (cascade) keyword to delete all dependent objects.

 

After confirming that the execution is OK , execute the following command to delete the $GAUSSHOME/postgis installation directory.

rm -rf $GAUSSHOME/postgis-xc

 

Finally: In addition to the above installation plug-ins supporting spatial data, there is also an openGauss-based Yukon database that expands the storage and management capabilities of geospatial data, provides professional GIS functions, and manages geospatial data. Yukon currently provides postgis, postgis_raster, postgis_sfcgal, yukon_geomodel, yukon_geogridcoder five extensions, interested students can understand.

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/gaussdb/blog/6258151