php - I have two tables, 1st country 2nd is state queried using ST_contains the state lies within the country or not -


i new postgis , breaking head across these queries ....... need help

i have 2 tables, 1st country(cid int,countryname text,coutrycoordinates geometry) , other state(sid int,statename text,statecoordinates geometry) wherein have write query using st_contains state within country query not working

now suppose have inserted

insert country  values ( 1,'country1', 'polygon ((1 5,4 5,4 7,1 7,1 5))');  insert state  values ( 1,'state1', 'polygon ((2 5,3 5,3 6,2 6,2 5))'); 

works , gets inserted value stored geomertry coloumn of sort

01030000000100000005000000000000000000f03f000000000000f03f000000000000f03f0000000000001040000000000000104000000000000010400000000000001040000000000000f03f000000000000f03f000000000000f03f country ,   010300000001000000050000000000000000000040000000000000004000000000000000400000000000000840000000000000084000000000000008400000000000000840000000000000004000000000000000400000000000000040  state in postresql db  

i have web page 2 text fields , drop down st_contains , st_intersects , submit button on click should display state lies in country or not.

select c.cid  country c, state s  st_contains('polygon ((1 1,1 4,4 4,4 1,1 1))', 'polygon ((2 2,2 3, 3 3, 3 2, 2 2))')  

the above works selects rows cross join in both table , not 1 c.cid.

select c.cid country c, state s  st_contains( 01030000000100000005000000000000000000f03f000000000000f03f000000000000f03f0000000000001040000000000000104000000000000010400000000000001040000000000000f03f000000000000f03f000000000000f03f, 010300000001000000050000000000000000000040000000000000004000000000000000400000000000000840000000000000084000000000000008400000000000000840000000000000004000000000000000400000000000000040) 

if query error returned

notice:  identifier "f03f000000000000f03f000000000000f03f0000000000001040000000000000104000000000000010400000000000001040000000000000f03f000000000000f03f000000000000f03f" truncated "f03f000000000000f03f000000000000f03f000000000000104000000000000" error:  syntax error @ or near "f03f000000000000f03f000000000000f03f0000000000001040000000000000104000000000000010400000000000001040000000000000f03f000000000000f03f000000000000f03f" line 2: 01030000000100000005000000000000000000f03f000000000000f03f00...                                               ^ 

this 1 being executed in php page wherein have written code

may know going wrong.

you there, missing quotes:

select c.cid country c, state s  st_contains( '01030000000100000005000000000000000000f03f000000000000f03f000000000000f03f0000000000001040000000000000104000000000000010400000000000001040000000000000f03f000000000000f03f000000000000f03f', '010300000001000000050000000000000000000040000000000000004000000000000000400000000000000840000000000000084000000000000008400000000000000840000000000000004000000000000000400000000000000040') 

the 'weird' geometry because postgres transforms polygon geometry. can transform them text again using st_astext()

select st_astext( state1 ) state; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -