I have a table in my data base. This table was created with differents fields as 'x','y' and 'z'.
Now I need to make a view to generate a geometry column, but I found problems, because the created geometry field is not correctly named. I need to force my column "geom geometry" to "geom geometry(PointZ, 25830)".
I did this:
st_force_3dz(st_setsrid(st_makepoint(table.x, table.y, table.z), 25830))
Any solutions?
1 Answer 1
I think the problem is your view does not have any primary key.
This is how I test:
Create a test table with x, y, z fields as you described and insert some data:
create table test.tbl
(id serial primary key,
x double precision,
y double precision,
z double precision);insert into test.tbl (x, y, z) values (0, 0, 0);
insert into test.tbl (x, y, z) values (0, 2, 2);
insert into test.tbl (x, y, z) values (2, 0, 0);
insert into test.tbl (x, y, z) values (2, 2, 5);Create two views, one with primary key and one without:
create view test.view_with_id
as
select id, st_force_3dz(st_setsrid(st_makepoint(x, y, z), 25830))
from test.tbl;create view test.view_without_id
as
select st_force_3dz(st_setsrid(st_makepoint(x, y, z), 25830))
from test.tbl;Load the two views into Qgis: enter image description here There will be error and details in PostGIS tab of the Log Messages for the view with no id column: enter image description here The view with id column can be viewed as normal layer.
-
Thanks Cao Minh Tu. But I must to say I thought my problem was in relation with primary key of my view, but my all my views have primary keys.Acicate– Acicate2013年11月14日 08:04:54 +00:00Commented Nov 14, 2013 at 8:04
SELECT ST_Zmflag(ST_SetSRID(ST_MakePoint(50,100,5), 25830))
it returns 2 which signifies the geometry is 3dz.