Database 如何将点(LANG、LAT)存储到PostGIS中的几何类型列中?
我在PostGIS中创建了一个表Database 如何将点(LANG、LAT)存储到PostGIS中的几何类型列中?,database,postgresql,types,postgis,Database,Postgresql,Types,Postgis,我在PostGIS中创建了一个表itapp_cities,用于存储城市数据。我添加了一个数据类型为“几何体”的列“位置”,用于存储城市的经度和纬度。当我运行以下INSERT查询时,我得到如下所示的错误 插入查询: INSERT INTO itapp_cities(city_id, city_name, city_code, state_id, location) VALUES (DEFAULT,'Ada', 'ada-ok',37,POINT(34.774531000000003, -96
itapp_cities
,用于存储城市数据。我添加了一个数据类型为“几何体”的列“位置”,用于存储城市的经度和纬度。当我运行以下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
)
表格定义:
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
)
错误:
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
)
如何在此列中存储点值?我是PostGIS的新手,所以请原谅我这个愚蠢的问题试试这个SQL,并将它与您的insert 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));
有关更多详细信息,请参阅此您可以使用该功能并设置:
或者,在输入文字值时,将字符串表示形式输入到:
有关dba.SE的回答,包括更多详细信息和链接:
INSERT INTO itapp_cities(city_id, city_name, city_code, state_id, location)
VALUES (DEFAULT,'Ada', 'ada-ok',37,'POINT(34.774531000000003, -96.678344899999999)');