Edit: QGIS only way , without CSV
In QGIS, import table from DB, select Processing Toolbox, Qgis Geoalgorithms -> Vector Creation Tools ->points layer from table -> select x and y
MS SQL Server way
one easy way is to create view in SQL where you add computed column. something like this STGeomFromText('POINT(' +x +' ' +y+')')
CREATE VIEW [dbo].[point_geom_text] as
SELECT
row_number() over ( order by k.id) as gid
, k.id as oid
, ('POINT('+convert(nvarchar(24),convert(decimal(18,4), p.y)) + ' ' + convert(nvarchar(24),convert(decimal(18,4), p.x))+ ' '+convert(nvarchar(24),convert(decimal(18,4), p.z))+ ')') as geomtext
FROM dbo.points k
For xy point use
('POINT('+convert(nvarchar(24),convert(decimal(18,4), p.y)) + ' ' + convert(nvarchar(24),convert(decimal(18,4), p.x))+')') as geomtext
Simple WKT for POINT is 'POINT(1 2)'
convert code is there to convert float to decimal and then to text
That will create table with geometry text column , row_number() creates unique row number.
CREATE VIEW geoms as
SELECT *, geom::STGeomFromText(geomtext, 4326) as geom FROM points_geom_text
Creates view which has geometry in your srid (4326? in your case?)
You have to set None instead '' for geometry column:
uri = QgsDataSourceURI()
uri.setConnection("IP_addr", "5432", "gis", "user", "pass")
uri.setDataSource("public", "typy_vykopu", None, "")
table = QgsVectorLayer(uri.uri(), "typy_vykopu_stazene", "postgres")
if not table.isValid():
print "Table %s did not load" % table.name()
QgsMapLayerRegistry.instance().addMapLayers([table])
Best Answer
Sure thing. Just load it via the Add Vector Layer button. It's not really a vector layer I know but that's just how it's coded at the moment.