[GIS] Add SRID to Point

postgisshapelysrid

When inserting a point into a PostGIS database I do it using

ST_GeomFromText('POINT(0 1 2)',26918).

in PgAdmin III I can  see the SRID

Note that this was done on a tutorial database where the SRID was set manually as explained here

Now I try to do it in python, creating my own table points, but I don't know how to create it with the SRID that I want, so right now it hasn't any SRID set.
Using the Shapely Point library, I create many points into a file and then COPY points FROM file

I create the points as point = Point(0,1,2) and then write the wkb_hex of this point into the file using point.wkb_hex. However, this doesn't contain any information on the SRID. so I tried using geoalchemy2 library as shown here

point = Point(0,1,2)
wkb_element = from_shape(point, srid = 26918)

and then repeat the COPY FROM with the wkb_element from the file I stored it.
Unfortunately in my table I don't see any information on the SRID

enter image description here

Any hint on how to Add an SRID to my Shapely Point?

Best Answer

the geoalchemy2 wkb_element is just an object that contains the srid, accessible as wkb_element.srid. The SRID information should be updated in the column of the table by doing

SELECT UpdateGeometrySRID('points','geom',26918);

after you imported the data from the file. If you do it before you import the data, you would get an error

Geometry SRID (0) does not match column SRID (26918)

since the imported Point doesn't contain the correct SRID, but only a default 0 value

However make sure that your geom column in the table was created as a 3 dimensional.

CREATE TABLE points (id INT PRIMARY KEY DEFAULT NULL,
                     geom GEOMETRY(PointZ) DEFAULT NULL)