2015-10-19 75 views
4

我在PostGIS中创建了一个表itapp_cities,用于存储城市的数据。我添加了一列location,数据类型为geometry,用于存储城市的longitudelatitude。当我运行以下INSERT查询时,出现如下所示的错误。如何将POINTS(LANG,LAT)存储到PostGIS中的几何类型列中?

INSERT查询:

INSERT INTO itapp_cities(city_id, city_name, city_code, state_id, location) 
    VALUES (DEFAULT,'Ada', 'ada-ok',37,POINT(34.774531000000003, -96.678344899999999)); 

表定义:

CREATE TABLE itapp_cities 
(
    city_id bigserial NOT NULL, 
    city_name character varying(100) NOT NULL, 
    city_code character varying(5) NOT NULL DEFAULT ''::character varying, 
    state_id bigint NOT NULL, 
    location geometry, 
    CONSTRAINT itapp_cities_pkey PRIMARY KEY (city_id), 
    CONSTRAINT fk_states FOREIGN KEY (city_id) 
     REFERENCES itapp_states (id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE CASCADE 
) 

错误:

ERROR: column "location" is of type geometry but expression is of type point 
LINE 2: VALUES (DEFAULT,'Ada', 'ada-ok',37,POINT(34.77453100000000... 
              ^
HINT: You will need to rewrite or cast the expression. 
********** Error ********** 

ERROR: column "location" is of type geometry but expression is of type point 
SQL state: 42804 

如何将点值存储在此列中?我是新来的Pos​​tGIS所以请原谅我这个愚蠢的问题

回答

2

试试这个SQL,并与您插入SQL查询

INSERT INTO itapp_cities(city_id, city_name, slug, state_id, location) 
    VALUES (DEFAULT,'Ada', 'ada-ok',37,st_GeomFromText('POINT(34.774531000000003 -96.678344899999999)', 312)); 

更多详情,请通过这个link

相关问题