GDAL/OGR tools This approach allows simultaneous conversion of coordinate systems, but is less flexible with respect to generation of new tables in PostGIS.
ogr2ogr -f "PostgreSQL" PG:'dbname=ssurgo_combined user=xxxx password=xxxx host=postgis.server.edu' input_file.shp
ogr2ogr output_file.shp PG:'dbname=ssurgo_combined user=xxxx password=xxxx host=postgis.server.edu' tablename
Note that tables must be correctly 'registered' in the geometry_columns table for this to work:
INSERT INTO geometry_columns VALUES ('','public','tablename','wkb_geometry',2,SRID,'geomtype');
PostGIS Loader/Dumper This approach is the simplest, but does not allow on-the-fly conversion of coordinate systems.
shp2pgsql -s SRID -c -g wkb_geometry -I shapefile.shp schema.table | psql -U username -h host database
Note that SRID is the PostGIS 'spatial ref. sys. id' (see the spatial_ref_sys table). See the manual page for shp2pgsql for a complete list of arguments and their meanings.
pgsql2shp -f shapefile.shp -h host -u username -P password -k -g wkb_geometry database schema.table
See the manual page for pgsql2shp for a complete list of arguments and their meanings.
Where tablename is your newly created table, SRID is the SRID (spatial reference ID) for the geometry in this table, and geomtype is the type of geometry: POINT, LINE, POLYGON, etc.
CSV format, from within the psql client
\copy tablename TO 'filename.csv' CSV HEADER
CSV format, via psql client
echo "select column_list from table_list " | psql --tuples --no-align -F "," database > file.csv
Tabular data to HTML format, via psql client See output below:
echo "select column_list from table_list " | psql --html database > file.html
HTML output from psql
| area | compname |
|---|---|
| 132472.230854819 | Hilmar variant |
| 322819.967391312 | Oneil |
| 362729.418301135 | Carranza |
| 431948.171760353 | Tuff rockland |
| 448784.927049035 | Gravel pits |
| 500763.225267798 | Snelling variant |
| 518860.954990617 | Foster |
| 571640.132661382 | Alamo |
| 648973.748756059 | Toomes |
| 924327.631201791 | Dumps |
(10 rows)