Importing and Exporting
Submitted by dylan on Wed, 2006-08-02 05:50.
Tips
- Attribute data stored with a shapefile (the .dbf file) can only use column names shorter than 14 characters. If you try and export a postGIS table that has column names longer than 14 characters, they will be truncated when converted to a shapefile.
- If column is postGIS is defined as numeric, ogr2ogr will not correctly interpret the values in this column: i.e. floating point values less than 1 will be truncated to 0. In order to avoid this problem always define your colums as double precision or float. For dynamically generated tables, cast affected columns to a defined numeric precision: select colum_a::numeric(7,3) where '7' refers to the total number of digits in the column, and '3' refers to the number of decimal places.
Geometry and attribute data to GIS file format
GDAL/OGR tools
- Import
ogr2ogr -f "PostgreSQL" PG:'dbname=ssurgo_combined user=xxxx password=xxxx host=postgis.server.edu' input_file.shp
- Export
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');
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.
Attribute data to text format
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)
|