shp2pgsql gsid conversion issues - postgresql

I'm fairly new to PostGIS. I've imported a shp file countless times in different ways. Here's my latest attempt.
shp2pgsql -d -s 4269 /var/www/Shape/Hamilton_City/Election_Poll_Boundaries.shp city_hamilton | psql -U postgres -d shape
I'm importing to srid 4269 because the .prj file says:
GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
When I do any type of search on the geometry of the polygons as in:
select ST_Astext(geom) AS coordinates FROM city_hamilton limit 1;
I get odd coordinates like:
MULTIPOLYGON(((574380.4001 4808575.0399,574434.7803 4808545.44,574496.2521 4808512.3351,.....
What am I doing wrong here?

Related

Unable to import raster data to postgis

I have been trying to import my SRTM raster data into my postgis using the command, but has generated the following error (tried multiple times). Is there any thing missing? I appreciate for any help
Error message:
ERROR: relation "test" already exists
ERROR: current transaction is aborted, commands ignored until end of transaction block
Welcome to SO.
The error message says you're trying to create a relation that already exists. Either drop it in your database ..
DROP TABLE test;
.. or tell raster2pgsql to do it for your by adding the parameter -d to your command.
-d Drops the table, then recreates it and populates
Something like
raster2pgsql -I -z 10x10 -C -F -s 4326 file.hgt -d public.test | psql ...
An alterative is to use -a to append the data to an existing table
-a Appends raster into current table, must be exactly the same table schema.

raster2pgsql: "Could not allocate memory for INSERT statement"

I'm very new to raster2pgsql so please bear with me. I'm trying to load a 60mb .tif (from the High-Resolution Settlements Layer project) to my postgis-enabled database with the following code:
raster2pgsql -s 5235 -C -F [path to the .tif] public.hrsl_lka | psql
-h localhost -U postgres -p 5432 -d project
However, I get the following error:
ERROR: insert_records: Could not allocate memory for INSERT statement
ERROR: process_rasters: Could not convert raster tiles into INSERT or
COPY statements ERROR: Unable to process rasters
Loading smaller .tifs of around 3mb to the same database but from other sources works fine, however.
Is there a size limit with raster2pgsql? I'm on PostgreSQL 12.4.
With many thanks,
Gregor
Have you tried setting the tile size -t?
According to the documentation:
-t: Tile size - expressed as width x height. If not provided, a default is worked out automatically in the range of 32-100 so it best
matches the raster dimensions. It is worth remembering that when
importing multiple files, tiles will be computed for the first raster
and then applied to others.
Alternatively you can let the script compute it for you by means of setting -t to auto e.g.
raster2pgsql -s 5235 -t auto -C -F file.tif public.hrsl_lka | psql -d db
Related answer: Are there limitations using a PostGIS out-db raster?

error "illegal option --t" occus when import OSM map into postgis [windows environment]

I want to import OSM map into postgis, so used the following command in windows cmd console:
osm2pgsql -U postgres -d osm -hstore -s _S ./default.style ./xxxx.osm
But "illegal option --t" error occus:
osm2pgsql illegal option --t
Usage error.
I don't know what's the meaning of "illegal option --t" and don't know how to handle it.
I've looked at several articles but haven't find any answer.
thanks.
p.s I've installed postgis 2.1.7 and postgresql 9.4 and hstore.
There are at least 2 mistakes in your command -hstore instead of --hstore and _S instead of -S .
So:
osm2pgsql -U postgres -d osm --hstore -s -S ./default.style ./xxxx.osm

No geometry values when importing rasters to PostGIS using raster2pgsql

System software...
RHEL 6.6, PostgreSQL 9.3.5, POSTGIS 2.1.5, GEOS 3.4.2, GDAL 1.9.2
I'm trying to get my first PostGIS database setup, but am having an issues getting rasters imported to the db with any geometry values. The database does have the PostGIS and adminpack extension enabled. Issuing the to following to import the raster (raster.tif) to my database (testdb) with superuser role (benh)...
$ raster2pgsql -I -C -F -t 100x100 -s 4326 raster.tif public.raster > raster.sql
$ psql -d testdb -U benh -f raster.sql
... which does seem to successfully create the table (EPSG value verified with gdalinfo), but I can't get either QGIS or GeoServer to recognize the table as a raster. Issuing...
$ gdalinfo PG":host=localhost port=5432 dbname=testdb user=benh schema='public' table='raster'"
... returns ...
...
SUBDATASET_1253_NAME=PG:host=localhost port=5432 dbname=testdb user=benh schema=
public table=raster column=rast where='rid = 1253'
SUBDATASET_1253_DESC=PostGIS Raster at
public.raster (rast), rid = 1253
SUBDATASET_1254_NAME=PG:host=localhost port=5432 dbname=testdb user=benh schema=
public table=raster column=rast where='rid = 1254'
SUBDATASET_1254_DESC=PostGIS Raster at
public.raster (rast), rid = 1254
Corner Coordinates:
Upper Left ( 0.0000000, 0.0000000)
Lower Left ( 0.0000000, 0.0000000)
Upper Right ( 0.0000000, 0.0000000)
Lower Right ( 0.0000000, 0.0000000)
Center ( 0.0000000, 0.0000000)
... which would explain why QGIS and GeoServer are having trouble. Can somebody offer a suggestion here? I've already completely uninstalled and reinstalled PostgreSQL, PostGIS, and GDAL without success. I'm at the bottom of my shallow bag of tricks so any tips would be great. Thanks.

importing osm file into a postgres/postgis database

Im using the tool osm2pgsql to import an osm file into a postgres database using phppgadmin as the administrative tool. i have only downloaded a small town from osm in xml format and im having trouble importing it using the terminal on mac. Im a bit of a noob at this so any help would be greatly appreciated. Ive looked at several articles but none provide the clarity i need in order to fulfill my needs.
Thanks
im getting this error could be something small not sure..
Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
NOTICE: table "planet_osm_point" does not exist, skipping
NOTICE: table "planet_osm_point_tmp" does not exist, skipping
SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, 'POINT', 2 );
failed: ERROR: function addgeometrycolumn(unknown, unknown, integer, unknown, integer) does not exist
LINE 1: SELECT AddGeometryColumn('planet_osm_point', 'way', 900913, ...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
You need to install the postgis extensions into your postgres database. Assuming that you have postgis installed on your machine you need to do something like:
psql <database> < /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
The exact path to postgis.sql will depend on the distribution you are using and how it has packaged postgis. You may also want/need to install the spatial reference systems table with a command like this:
psql <database> < /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql
This is an example command:
osm2pgsql -c -d your_country -U postgres -W -H localhost -P 5432 -s -k -x -p osm -S default.style ..\your_country.osm.bz2
Here are some useful weblinks:
http://wiki.openstreetmap.org/wiki/Osm2pgsql
http://www.gis.hsr.ch/wiki/Osm2pgsql
-S.