1. ST_Buffer(geometry, double, [integer])
buffer操作一個很有用函數,
這個函數的第一個參數是要操作的空間幾何數據,第二個參數長度(距離),第三個參數為一個整型,
這個函數返回一個空間數據類型,以當前第一個參數空間幾何數據為參考點,返回小於等於距離的空間
幾何數據點,最后由這些點組成一個多邊形空間數據,最后一個參數表示
在組成一個1/4圓的有幾個點分隔。也就是說如果最好一個參數為8那么這個最后組成的多邊形就是32邊
的多邊形,如果不指定這個參數,系統默認的是8
注意:第二個參數,距離它的單位為空間數據單位(度),在運算時需要進行單位換算,最后轉換成度
,單位的換算關系如下:
1英里= 63360 米
1米=1/1852 海里
1海里= 1/60度
如果要進行具體的運算,需要進行一下單位換算,比如要求一個500米的范圍,那么應該是500*1/1852*1/60(度)
2.獲取字段類型
QString sql2 = QStringLiteral("select format_type(a.atttypid, a.atttypmod) as fldType, " "a.attname as fldName from pg_attribute a, pg_stat_user_tables b " "where b.relname = '%1' and b.schemaname = '%2' " " and a.attrelid = b.relid and a.attnum > 0" ).arg(tbName, schemaName);
3.獲取字段長度精度等
QString sql1 = QStringLiteral("select ordinal_position as fldIndex, column_name as fldName, " " coalesce(character_maximum_length, numeric_precision, -1) as fldLen," " numeric_scale as decimalLen, is_nullable as nullable from information_schema.columns a " " where a.table_schema = '%1' and a.table_name = '%2' " ).arg(schemaName, tbName);
4.更改字段類型
比如說char的值為1.1 想更改為int 那需要強制轉換,這時候可以用到using
alter table 表 alter 字段 type int using 字段::int;
5.獲取表的tableoid
"SELECT regclass(public."TblName")::oid as clsid";
6.更改表的srid
ALTER TABLE table ALTER COLUMN geom TYPE geometry(Point,4326) UPDATE table SET geom=ST_SetSRID(geom,4326);