Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我有两个表,第一个是国家,第二个是使用ST_查询的州,该州是否在该国境内_Php_Postgresql_Postgis_Pgadmin - Fatal编程技术网

Php 我有两个表,第一个是国家,第二个是使用ST_查询的州,该州是否在该国境内

Php 我有两个表,第一个是国家,第二个是使用ST_查询的州,该州是否在该国境内,php,postgresql,postgis,pgadmin,Php,Postgresql,Postgis,Pgadmin,我是波斯吉斯的新手,在这些问题上我的头都碎了。。。。。。。我需要一些帮助 我有两个表,第一个是country(cid int,countryname text,coutrycoordinates geometry),另一个是state(sid int,statename text,statecordinates geometry),其中我必须使用ST\u编写一个查询,该查询包含国家/地区内的状态,但我的查询不起作用 现在假设我插入了 INSERT into country VALUES ( 1

我是波斯吉斯的新手,在这些问题上我的头都碎了。。。。。。。我需要一些帮助

我有两个表,第一个是
country(cid int,countryname text,coutrycoordinates geometry)
,另一个是
state(sid int,statename text,statecordinates geometry)
,其中我必须使用
ST\u编写一个查询,该查询包含国家/地区内的状态,但我的查询不起作用

现在假设我插入了

INSERT into country  VALUES (
1,'country1',
'POLYGON ((1 5,4 5,4 7,1 7,1 5))');

INSERT into state  VALUES (
1,'state1',
'POLYGON ((2 5,3 5,3 6,2 6,2 5))');
工作并被插入,但是为geomertry column存储的值就是这种类型的

01030000000100000005000000000000000000F03F000000000000F03F000000000000F03F0000000000001040000000000000104000000000000010400000000000001040000000000000F03F000000000000F03F000000000000F03F for country and 

010300000001000000050000000000000000000040000000000000004000000000000000400000000000000840000000000000084000000000000008400000000000000840000000000000004000000000000000400000000000000040  for state in the postreSQL db 
我有一个包含两个文本字段的网页和一个带有
ST_Contains
ST_Intersects
的下拉列表,单击提交按钮应显示国家/地区是否为国家/地区

select c.cid  from country as c, state as s  where ST_Contains('POLYGON ((1 1,1 4,4 4,4 1,1 1))', 'POLYGON ((2 2,2 3, 3 3, 3 2, 2 2))') 
上述方法有效,但选择了两个表中交叉连接的所有行,而不仅仅是该行
c.cid.

select c.cid from country as c, state as s  where ST_Contains(
01030000000100000005000000000000000000F03F000000000000F03F000000000000F03F0000000000001040000000000000104000000000000010400000000000001040000000000000F03F000000000000F03F000000000000F03F, 010300000001000000050000000000000000000040000000000000004000000000000000400000000000000840000000000000084000000000000008400000000000000840000000000000004000000000000000400000000000000040)
如果这是查询,则返回错误

NOTICE:  identifier "f03f000000000000f03f000000000000f03f0000000000001040000000000000104000000000000010400000000000001040000000000000f03f000000000000f03f000000000000f03f" will be truncated to "f03f000000000000f03f000000000000f03f000000000000104000000000000"
ERROR:  syntax error at or near "F03F000000000000F03F000000000000F03F0000000000001040000000000000104000000000000010400000000000001040000000000000F03F000000000000F03F000000000000F03F"
LINE 2: 01030000000100000005000000000000000000F03F000000000000F03F00...
                                              ^
这是在php页面中执行的代码,我在其中编写了这段代码


我能知道我错在哪里吗。

你就快到了,只是少了几句话:

select c.cid from country as c, state as s  where ST_Contains(
'01030000000100000005000000000000000000F03F000000000000F03F000000000000F03F0000000000001040000000000000104000000000000010400000000000001040000000000000F03F000000000000F03F000000000000F03F', '010300000001000000050000000000000000000040000000000000004000000000000000400000000000000840000000000000084000000000000008400000000000000840000000000000004000000000000000400000000000000040')
“奇怪”的几何体是因为Postgres将多边形转换为一个多边形。您可以使用将它们再次转换为文本


您看到的十六进制代码被称为
SELECT ST_AsText( state1 ) FROM state;