1.建表
CREATE TABLE postgis3d (
id SERIAL PRIMARY KEY,
name VARCHAR(128),
geom GEOMETRY
);
2.添加GIST索引
CREATE INDEX postgis3d_gix ON postgis3d USING GIST (geom);
3.插入数据
3.1 点(POINTM)
INSERT INTO postgis3d (name, geom) VALUES ('p1',
GeomFromEWKT('SRID=312;POINTM(0 0 0)')
);
INSERT INTO postgis3d (name,geom) VALUES ('p2',
GeomFromEWKT('SRID=312;POINTM(5 0 1)')
);
INSERT INTO postgis3d (name,geom) VALUES ('p3',
GeomFromEWKT('SRID=312;POINTM(0 10 1)')
);
或使用多点(MULTIPOINTM)
INSERT INTO postgis3d (name, geom) VALUES ('p1',
GeomFromEWKT('SRID=312;MULTIPOINTM(0 0 0,5 0 1,0 10 1)')
);
QGIS中显示几何数据如下:
3.2 线(LINESTRING)
INSERT INTO postgis3d (name, geom) VALUES ('L1',
ST_GeomFromEWKT('SRID=4312;LINESTRING(0 0 0,1 1 0,1 2 1)')
);
INSERT INTO postgis3d (name, geom) VALUES ('L1',
ST_GeomFromEWKT('SRID=4312;LINESTRING(2 3 1,3 2 1,5 4 1)')
);
或使用多线(MULTILINESTRING)
INSERT INTO postgis3d (name, geom) VALUES ('L1',
ST_GeomFromEWKT('SRID=4312;MULTILINESTRING((0 0 0,1 1 0,1 2 1),(2 3 1,3 2 1,5 4 1))')
);
QGIS中显示几何数据如下:
3.3 多边形(POLYGON)
INSERT INTO postgis3d (name, geom) VALUES ('p1',
ST_GeomFromEWKT('SRID=4312;POLYGON((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2 0,1 2 0,1 1 0))')
);
INSERT INTO postgis3d (name, geom) VALUES ('p1',
ST_GeomFromEWKT('SRID=4312;POLYGON((-1 -1 0,-1 -2 0,-2 -2 0,-2 -1 0,-1 -1 0))')
);
或者使用多边形集合(MULTIPOLYGON)
INSERT INTO postgis3d (name, geom) VALUES ('L1',
ST_GeomFromEWKT('SRID=4312;MULTIPOLYGON(((0 0 0,4 0 0,4 4 0,0 4 0,0 0 0),(1 1 0,2 1 0,2 2 0,1 2 0,1 1 0)),((-1 -1 0,-1 -2 0,-2 -2 0,-2 -1 0,-1 -1 0)))')
);
QGIS中显示几何数据如下:
3.4 三角形(TRIANGLE )
INSERT INTO postgis3d (name, geom) VALUES ('g1',
ST_GeomFromEWKT('SRID=4312;TRIANGLE ((0 0, 0 9, 9 0, 0 0))')
);
INSERT INTO postgis3d (name, geom) VALUES ('g1',
ST_GeomFromEWKT('SRID=4312;TRIANGLE ((10 3, 12.5 8, 15 3, 10 3))')
);
QGIS中显示几何数据如下:
3.5 TIN
INSERT INTO postgis3d (name, geom) VALUES ('t1',
ST_GeomFromEWKT('SRID=4312;TIN( ((0 2 0, 10 4 0, 12 0 0, 0 2 0)),
((0 2 0, -2 -6 0, 12 0 0, 0 2 0)),
((0 2 0, 10 4 0, 5 8 0, 0 2 0)) )')
);
QGIS中显示几何数据如下:
3.6 MULTICURVE
INSERT INTO postgis3d (name, geom) VALUES ('c1',
ST_GeomFromEWKT('SRID=4312; MULTICURVE( (0 0, 5 5), CIRCULARSTRING(4 0, 4 4, 8 4) )')
);
QGIS中显示几何数据如下:
3.7 GEOMETRYCOLLECTIONM
INSERT INTO postgis3d (name, geom) VALUES ('g1',
ST_GeomFromEWKT('SRID=4326;GEOMETRYCOLLECTIONM( POINTM(2 3 9), LINESTRINGM(2 3 4, 3 4 5) )')
);
3.8 POLYHEDRALSURFACE
INSERT INTO postgis3d (name, geom) VALUES ('s1',
ST_GeomFromEWKT('SRID=4326;POLYHEDRALSURFACE(((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)),
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),
((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 0, 1 1 1, 1 0 1, 1 0 0, 1 1 0)),
((0 1 0, 0 1 1, 1 1 1, 1 1 0, 0 1 0)),
((0 0 1, 1 0 1, 1 1 1, 0 1 1, 0 0 1)))'));