This topic describes how to load a vector data file into Ganos by using shp2pgsql, ogr2ogr, or QGIS.
Preparations
Before you load a vector data file, run the following command on your AnalyticDB for PostgreSQL instance to create the ganos_geometry extension:
CREATE EXTENSION ganos_geometry CASCADE
Load vector data by using shp2pgsql
The shp2pgsql command line tool is used to convert Esri shapefiles into SQL files. For more information, visit shp2pgsql. Then, you can load the SQL files into Ganos.
- Syntax
shp2pgsql -s <srid> -c -W <charset> <path_to_shpfile> <schema>.<table_name> | psql -d <dbname> -h <host> -U <user_name> -p <port>
- Parameters
Parameter Description Example -s <srid> The spatial reference system identifier (SRID) of the vector data file. 4490 -c Specifies to create a table. You can also use the following parameters:- -a: appends data to a table.
- -d: deletes a table before data is loaded.
- -p: creates a schema in SQL without writing spatial data.
None -W <charset> The character set that is used by the shapefile. GBK or UTF8 <path_to_shpfile> The storage path of the shapefile. The storage path must be accessible to the shp2pgsql command line tool. /home/roads.shp <schema>.<table_name> The name of the geometry table that you created. public.roads -d <dbname> The name of the database. mydb -h <host> The endpoint of the instance on which to create the database. pgm-xxxxxxx.pg.rds.aliyuncs.com -U <user_name> The username that is used to connect to the database. my_name -p <port> The port number that is used to connect to the database. 3433 - Example
shp2pgsql -s 4490 -c -W "GBK" /home/roads.shp public.roads | psql -d mydb -h pgm-xxxxxxx.pg.rds.aliyuncs.com -U my_name -p 3433
Note If you want to import more than one vector data file at a time by using a script, run theexport PGPASSWORD=my_pass
command to set the PGPASSWORD environment variable to my_pass.
Load vector data by using ogr2ogr
The ogr2ogr command line tool is provided by GDAL/OGR to convert data. It supports common vector data types, such as Esri ShapFile, MapInfo, and FileGDB. For more information about ogr2ogr, visit ogr2ogr. For more information anout vector data types, visit Vector drivers.
- Syntax
ogr2ogr -nln <table_name> -f PostgreSQL PG:"dbname='<dbname>' host='<host>' port='<port>' user='<user_name>' password='<password>'" -lco SPATIAL_INDEX=GIST -lco FID=<FID_NAME> -overwrite "<PATH_TO_FILE>" -nlt GEOMETRY
- Parameters
Parameter Description Example -nln <table_name> The name of the vector data file. roads -f PostgreSQL PG:"dbname='<dbname>' host='<host>' port='<port>' user='<user_name>' password='<password>'" The information that is used to connect to the AnalyticDB for PostgreSQL instance. dbname='mydb' host='pgm-xxxxxxx.pg.rds.aliyuncs.com' port='3433' user='my_name' password='my_pass' -lco SPATIAL_INDEX=GIST The GiST spatial index that you want to create. None -lco FID=<FID_NAME> The ID of the specified feature. fid -overwrite The rewrite mode that you want to use. You can also select the -append mode.
None <PATH_TO_FILE> The storage path of the vector data file. Make sure that the storage path is accessible to the ogr2ogr command line tool. /home/roads.shp /home/land.tab
-nlt GEOMETRY Specifies the geometry data type. If the vector data file contains polygon data, we recommend that you specify this parameter. This allows you to avoid errors that occur if the vector data file contains not only data of the MultiPolygon type but also data of other types. None - Example
ogr2ogr -nln roads -f PostgreSQL PG:"dbname='mydb' host='pgm-xxxxxxx.pg.rds.aliyuncs.com' port='3433' user='my_name' password='my_pass'" -lco SPATIAL_INDEX=GIST -lco FID=fid -overwrite "/home/roads.shp" -nlt GEOMETRY
Load vector data by using QGIS
QGIS was known as Quantum GIS. It is a user-friendly, open-source desktop tool that supports various vector and raster formats. It allows you to use databases as data sources. In addition, it allows you to visualize, manage, and analyze data and to prepare maps. For more information, see QGIS.
- Establish a connection to Ganos.
- Load the vector data file.
- In the menu bar, choose .
- In the dialog box that appears, select the data source from which you want to import the vector data file, and click Import Layer/File....
- In the dialog box that appears, click the vector data file, configure the required parameters, and then click OK.