Shapfile is an ESRI file storage format and is widely supported by the industry. The Shapfile format is a simple format that stores the attribute information of geometric locations and geographical features in the form of non-topological relationships. Although GeoServer uses Shapfile to quickly create an online map service, its disadvantages are obvious:
1. Shapefile only supports one layer, which is meaningless in practice.
2. It is not safe to directly use the SHP file, and the Shapfile is easily deleted by virus or by mistake for other reasons.
3. The efficiency of using Shapfile as the data source in GeoServer is very low.
4. The Chinese Character GeoServer in the Shapfile cannot be parsed and garbled characters may occur.
5. Databases can easily query Geographical information.
Use PostGIS to manage spatial data
PostGIS supports GIST spatial indexes (Appendix 1) and standard forms, which greatly improves processing efficiency.
The OGC format only provides two-dimensional ry, and the associated SRID is never used for input and output requests in depth. PostGIS supports OpenGIS to organize all GIS objects and functions specified by the "Simple Features for SQL" Specification, the format is EWKB and EWKT, with support for 3DZ, 3DM, and 4D coordinate systems added (of course, the OGC standards for three-dimensional and Four-Dimensional Data are not yet fully developed ), in-depth introduction of SRID information.
Spatial data table structure: PostGIS contains two required metadata tables: SPATIAL_REF_SYS (spatial reference table) and GEOMETRY_COLUMNS (ry attribute column ), the two tables are used to store the coordinate system numerical ID and text description used by the space database.
The shp2pgsql command of PostGIS can directly import the Shapfile to the database or export it as an SQL file. We recommend that you export it as an SQL file first and then execute this file in the SQL run window to import data to the database. The Code is as follows:
Shapfile to SQL statement:
Shp2pgsql path \ shp data file name new data table name> path \ SQL file name. SQL
Direct storage of Shapfile:
Shp2pgsql-c path \ shp data file name new data table name database name | psql-d database name
Example:
For example, import the Shapfile "c: \ road. shp" to the data table "road", and the database is "sjzmap ".
1. Run "command prompt ".
2. Switch to the bin directory in the PostgreSQL database installation directory.
3. Run the shp2pgsql command in this directory: "shp2pgsql c: \ road. shp road> c: \ road. SQL ".
4. If this file is directly imported into the database (not recommended): "shp2pgsql-c: \ road. shp road sjzmap | psql-d sjzmap ".
5. Use pgAdmin3 to select a database and then import the table.
Note:
-
-D
-
Drops the database table before creating a new table with the data in the Shape file.
-
-
-
Appends data from the Shape file into the database table. Note that to use this option to load multiple files, the files must have the same attributes and same data types.
-
-C
-
Creates a new table and populates it from the Shape file.This is the default mode.
-
-P
-
Only produces the table creation SQL code, without adding any actual data. This can be used if you need to completely separate the table creation and data loading steps.
-
-D
-
Use the PostgreSQL "dump" format for the output data. this can be combined with-a,-c and-d. it is much faster to load than the default "insert" SQL format. use this for very large data sets.
-
-S <SRID>
-
Creates and populates the geometry tables with the specified SRID.
-
-K
-
Keep identifiers 'case (column, schema and attributes). Note that attributes in Shapefile are all UPPERCASE.
-
-I
-
Coerce all integers to standard 32-bit integers, do not create 64-bit bigints, even if the DBF header signature appears to warrant it.
-
-I
-
Create a GiST index on the geometry column.
-
-W
-
Output WKT format, for use with older (0.x) versions of PostGIS. Note that this will introduce coordinate drifts and will drop M values from shapefiles.
-
-W <encoding>
-
Specify encoding of the input data (dbf file). When used, all attributes of the dbf are converted from the specified encoding to UTF8. The resulting SQL output will contain inSET CLIENT_ENCODING to UTF8Command, so that the backend will be able to reconvert from UTF8 to whatever encoding the database is configured to use internally.