標籤:
建立帶有postgis功能的資料庫的方法1.安裝時勾選預設建立的gis庫 2.建立一個資料庫 執行create extension postgis 建立一個帶有地理類型列的表1.先建立一個不包含地理列的表
CREATE TABLE public."STATION_ADDRESS"
(
"ID" character(36) NOT NULL,
"CREATE_STATION_CODE" character varying(50),
"COORDINATE_VALUE" character varying(200),
"POINT" text,
"REMARK" character varying(200),
CONSTRAINT "STATION_ADDRESS_pkey" PRIMARY KEY ("ID")
)
用copy命令向資料表"STATION_ADDRESS" 匯入資料(http://blog.csdn.net/namelb/article/details/7909910)
copy "STATION_ADDRESS" from ‘d:/test/testdata.csv‘ delimiter as‘,‘ csv quote as ‘"‘
--添加一個地理類型列
SELECT ADDGEOMETRYCOLUMN(‘STATION_ADDRESS‘,‘POINT_COORDINATE‘,4326, ‘POINT‘,2)
--查詢兩點的距離小於100的
SELECT * FROM public."STATION_ADDRESS" WHERE ST_Distance("POINT_COORDINATE",ST_GeomFromText(‘POINT(112.308407 22.192877)‘,4326))=0;
--把字串類型的欄位轉化為多邊形列
UPDATE "EXPRESS_RANGE" SET "SHAPE"=ST_MakePolygon(ST_GeomFromText(‘LINESTRING(select "REMARK" from "EXPRESS_RANGE" t where t."ID"= "EXPRESS_RANGE"."ID")‘,4326))
--查看某一個點是否在某個多邊形內 返回f表示不在範圍內 返回T表示在多邊形內
SELECT ST_Contains( ST_MakePolygon(ST_GeomFromText(‘LINESTRING ( 121.312350 30.971457 , 121.156783 31.092221 , 121.353250 31.278195 , 121.509125 31.157431 , 121.312350 30.971457 ) ‘)) ,st_point(121.632378,31.07106) )
--把geom列以文本形式顯示
select ST_AsText("SHAPE") FROM "EXPRESS_RANGE"
Postgresql PostGIS使用總結