Importing SHP files into PostgreSQL
1, first, you need to make Shp2pgsql command available, Baidu Download, add environment variables can.
: https://download.osgeo.org/postgis/windows/pg96/
, open the URL, download the target file, extract the following directory:
Add the directory to the environment variable, and then cmd to run Shp2pgsql.
2. The command is as follows:
Shp2pgsql-s 3857-a-W GBK file name. shp namespace name. Table Name | Psql-h localhost-u postgres-d database name-P 5432
3, the import failure may occur, because the imported database to increase the space expansion feature:
Create extension postgis;create extension postgis_topology;create extension fuzzystrmatch;create extension postgis_ Tiger_geocoder;
4. Command Prompt to enter password
In order to avoid password entry in the program, we added the pgpass.conf file. This file is available under PostgreSQL's installation directory.
The contents of the file are as follows:
Copy the file to the following directory: C:\Users\ your computer name \appdata\roaming\postgresql
OK, you are done!
5. Precautions
A, table name all lowercase, PostgreSQL cannot recognize capital table name
b, file name path can not be too long, preferably do not include Chinese
C, encoding format using GBK not garbled, if garbled can try UTF-8
Developer Notes Import a shape file into PostgreSQL using Shp2pgsql