Install PostGIS in the source code of RedHat7

Source: Internet
Author: User
Tags psql postgis

Install PostGIS in the source code of RedHat7

This article describes how to install and use PostGIS in RedHat7 environment.

1. PostgreSQL1.1 install PostgreSQL in yum

This is relatively simple and can be directly installed using yum.

$ sudo yum install -y postgresql-server postgresql-devel libxml2 libxml2-devel

By the way, install postgresql-devel and libxml2-devel, which will be used for post compilation and installation of PostGIS.

postgresql.x86_64               9.2.13-1.1postgresql-devel.x86_64         9.2.13-1.1postgresql-libs.x86_64          9.2.13-1.1postgresql-server.x86_64        9.2.13-1.1libxml2                         2.9.1-6libxml2-devel.x86_64            2.9.1-6

Switch to the S s account.

$ sudo su postgrespostgres $ 
1.2 initialize PostgreSQL

Confirm the PostgreSQL data directory.

postgres $ cat /var/lib/pgsql/.bash_profile[ -f /etc/profile ] && source /etc/profilePGDATA=/var/lib/pgsql/dataexport PGDATA

Perform initialization.

postgres $ initdb

All data files and configurations of PostgreSQL are stored in the/var/lib/pgsql/data directory.

1.3 start PostgreSQL

Start PostgreSQL with pg_ctl.

postgres $ pg_ctl start

Use the psql client to connect.

Postgres $ psqlpsql (9.2.13) Input "help" to obtain help information. postgres = # \ l database list name | Owner | character encoding | verification rules | Ctype | access permissions ------------------ + ---------- + ------------- + ----------- + ----------------------- postgres | UTs | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | template0 | postgres | UTF8 | zh_CN.UTF-8 | = c/postgres + | postgres = CTc/postgres template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | = c/ postgres + | postgres = CTc/postgres
2. Prepare the source code package PostGIS2.1

Prepare source code packages for gdal, proj, geos, and postgis. Ensure that the postgis version is compatible with postgresql.

Compatibility information can be viewed: http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS

$ wget http://download.osgeo.org/gdal/2.2.3/gdal-2.2.3.tar.gz$ wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz$ wget http://download.osgeo.org/geos/geos-3.3.3.tar.bz2$ wget http://download.osgeo.org/postgis/source/postgis-2.2.6.tar.gz
2.2 decompress, compile, and install gdal, proj, geos, and postgis

Decompress, compile, and install the software package in sequence.

$ tar xf gdal-2.2.3.tar.gz && cd gdal-2.2.3 && ./configure --prefix=/usr/local/gdal && make && sudo make install$ tar xf proj-4.8.0.tar.gz && cd proj-4.8.0 && ./configure --prefix=/usr/local/proj && make && sudo make install$ tar xf geos-3.3.3.tar.bz2 && cd geos-3.3.3 && ./configure --prefix=/usr/local/geos && make && sudo make install$ tar xf postgis-2.2.6.tar.gz && cd postgis-2.2.6 && ./configure -prefix=/usr/local/postgis --with-geosconfig=/usr/local/geos/bin/geos-config --with-projdir=/usr/local/proj --with-gdalconfig=/usr/local/gdal/bin/gdal-config && make && sudo make install
2.3 configure ldconfig

Add the lib directories of gdal, proj, and geos to ldconfig.

$ sudo cat /etc/ld.so.confinclude ld.so.conf.d/*.conf/usr/local/gdal/lib//usr/local/proj/lib//usr/local/geos/lib/$ sudo ldconfig
2.4 create a spatial database template

# Creating a non-spatial feature database
Postgres $ createdb template_postgis
# Create functions, types, and operators related to the spatial database
Postgres $ psql-f/usr/share/pgsql/contrib/postgis-2.2/postgis. SQL-d template_postgis
Postgres $ psql-f/usr/share/pgsql/contrib/postgis-2.2/rtpostgis. SQL-d template_postgis
# Verify the spatial database version
Postgres $ psql template_postgis
Psql (9.2.13)
Enter "help" to obtain help information.
Template_postgis = # select postgis_full_version ();
Postgis_full_version
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------
POSTGIS = "2.2.6 r16006" GEOS = "3.3.3-CAPI-1.7.4" PROJ = "Rel. 4.8.0, 6 March 2012" GDAL = "GDAL 2.2.3, released" LIBXML = "2.9.1" RASTER
(1 line record)
Template_postgis = # \ d

Association list
Schema mode | Name | type | Owner
---------- + ------------------- + -------- + ----------
Public | geography_columns | View table | postgres
Public | geometry_columns | View table | postgres
Public | raster_columns | View table | postgres
Public | raster_overviews | View table | postgres
Public | spatial_ref_sys | data table | postgres
(5 rows of Records)

2.5 create a new spatial database based on the spatial database template
postgres $ createdb -T template_postgis new_database
3. Simple Test

Whether the test point (0, 0) is within the specified polygon.

New_database = # select ST_Within (ST_GeomFromText ('point (0 0) ', 4326), ST_GeomFromText ('polygon (1 1, 1-1,-1-1, -1 1, 1 1) ', 4326); st_within ----------- t (1 row record)

For detailed syntax rules, see PostGis User Manual: http://www.postgres.cn/docs/PostGis-2.2.0dev_Manual.pdf

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.