Cannot get ST_DIFFERENCE to provide required outcome in PostGIS - postgis

Im used to using PostGIS to undertake a variety of functions, but for some reason am struggling to return the difference between two geometry columns [from different tables]. Assume it's me doing something wrong, but can't quite figure it......
I ostensibly have two polygons test and tc. tc is contained within test, but when I use the below code it returns test without the relevant tc removed....
I can't really mock up data as the issue seems to be specific to the geometry columns of the actual data - in lieu of such I have copied the data from the geometry column:
test = "0103000020346C000001000000ED010000458D3253ECCC204166CCE1DCD1DA0641B037D3BDEFCC2041CD37A88D29DB0641AD5067CBF0CC2041F16B72DC43DB0641E0839AFEF1CC2041249FA50F61DB0641BB75B037F4CC20417E1658D896DB06414559E25EF6CC2041EA3A587FC8DB0641DB700DB8F8CC2041D0940C02FADB0641B5910B43FBCC20416172505D2BDC06414067B3FFFDCC2041CFA2018E5CDC0641BC75D8ED00CD20413EA900918DDC0641111D4B0D04CD204183EF3063BEDC0641D69BD85D07CD2041B8F87801EFDC064186124BDF0ACD20419D93C2681FDD0641EF8669910ECD2041C20CFB954FDD0641CEE7F77312CD20417B6013867FDD0641A110B78616CD2041936C0036AFDD0641A9CD64C91ACD2041C821BBA2DEDD06411CE0BB3B1FCD2041FBB440C90DDE06418D0274DD23CD204124D092A63CDE064180ED41AE28CD2041F5C2B7376BDE0641365CD7AD2DCD20413CB3BA7999DE06419E11E3DB32CD2041E7CCAB69C7DE064186DD103838CD2041C971A004F5DE0641EBA109C23DCD2041FA68B34722DF06418758737943CD2041EA0D05304FDF06418418F15D49CD2041137FBBBA7BDF0641661C236F4FCD20414FCC02E5A7DF06411DC8A6AC55CD2041D4240DACD3DF064146AF16165CCD2041BF04130DFFDF0641A19B0AAB62CD2041436253052AE00641A993176B69CD204171DA139254E0064162E1CF5570CD204185DDA0B07EE006415019C36A77CD2041D8DA4D5EA8E0064196217EA97ECD2041506C7598D1E006414C398B1186CD20416281795CFAE00641F4FF71A28DCD20419F89C3A722E106411D7DB75B95CD2041C69EC4774AE106413728DE3C9DCD204152AEF5C971E1064186F06545A5CD204195A2D79B98E106414945CC74ADCD2041478BF3EABEE10641FC1D8CCAB5CD204198C5DAB4E4E10641D5021E46BECD2041B42327F709E206415215F8E6C6CD2041C4137BAF2EE2064103198EACCFCD204161C681DB52E20641EC570075D3CD20413AF734F961E206418D0C494ED8CD20417FB4DD837FE2064133A4A957DFCD2041A88822F5A8E206414E3C578AE6CD20414A804DF4D1E206419537DEE5EDCD2041EC1CCC7EFAE20641A068C869F5CD20411532139222E306414E199D15FDCD20412E0E9F2B4AE306415E12E1E804CE2041E5A2F34871E3064128A316E30CCE204110AD9CE797E306417EA9BD0315CE20411DDC2D05BEE30641B799534A1DCE2041FCF8429FE3E30641E28653B625CE20418A0C80B308E406411B2B36472ECE20417185913F2DE4064106F071FC36CE20418E5D2C4151E4064176F77AD53FCE2041BE3E0EB674E406413024C3D148CE20412CA7FD9B97E40641D322BAF051CE20410B0DCAF0B9E40641EF72CD315BCE2041C2014CB2DBE406412C70689464CE2041865465DEFCE40641A45BF4176ECE20415A3401731DE506415765D8BB77CE20418451146E3DE50641BFB5797F81CE20415FFE9CCD5CE506418A773B628BCE2041934FA38F7BE5064171E17E6395CE2041B93B39B299E506412C40A3829FCE204156BA7A33B7E506418A0006BFA9CE20413BE28D11D4E50641A0B90218B4CE20414007A34AF0E506412137F38CBECE20415ED7F4DC0BE60641C5832F1DC9CE20411C77C8C626E60641D4F30DC8D3CE20415F9D6D0641E60641CF2FE38CDECE204180AE3E9A5AE606412B3F026BE9CE2041CAD6A08073E606412F93BC61F4CE2041392404B88BE60641E7116270FFCE2041959FE33EA3E606412F2141960ACF2041DC64C513BAE60641D9B1A6D215CF2041F2BA3A35D0E60641E94ADE2421CF2041A92AE0A1E5E60641E814328C2CCF20410A955D58FAE606414BE5EA0738CF2041F04866570EE70641F349509743CF2041E617B99D21E70641C094A8394FCF20414D6A202A34E7064134E738EE5ACF2041CA5272FB45E70641313E45B466CF2041F8A0901057E70641C37D108B72CF20415BF3686867E70641FB7CDC717ECF204197C8F40177E70641E111EA678ACF2041EC8F39DC85E70641711D796C96CF2041E9B848F693E70641A997C87EA2CF204168C23F4FA1E70641A59B169EAECF2041C34848E6ADE70641CA73A0C9BACF2041481398BAB9E70641FFA5A200C7CF2041E82071CBC4E70641EBFF5842D3CF204124B42118CFE706414CA3FE8DDFCF2041315E04A0D8E706414D12CEE2EBCF20415F098062E1E70641E83B0140F8CF2041AE02085FE9E706415988D1A404D02041A4021C95F0E706418FE5771011D020415D354804F7E70641ABD32C821DD02041C74125ACFCE70641877128F929D020412950588C01E806413C89A27436D02041CB0F93A405E80641B49CD2F342D02041E8BB93F408E806413EF2EF754FD02041CC1F257C0BE8064129A131FA5BD02041299A1E3B0DE80641599ECE7F68D02041A41F64310EE80641EAC8FD0575D020419A3CE65E0EE80641CBF6F58B81D020411516A2C30DE806415D01EE108ED02041FE69A15F0CE8064115D21C949AD02041798EFA320AE80641186FB914A7D020418870D03D07E80641D607FB91B3D02041D191528003E80641A501190BC0D02041AA05BDFAFEE7064157044B7FCCD02041506D58ADF9E70641CC06C9EDD8D0204158F37998F3E7064198D395BAF0D02041F28C1332E7E706412682F886F7D02041E54F68A1E3E706416652846EF8D02041A0466727E3E70641665284EE18D120416D1334F4D1E70641290D981B1FD12041F1D85D96CEE70641BD3195193ED1204133A59733BDE706416D56E13042D12041220F91FBBAE70641D360974745D120413F9D6D48B9E7064112E3D98B84D120419E9AC0F695E70641FD5EA1BB9ED12041C7F6615D87E706414BFFE01EABD120416881171080E70641A4BC6C7AB7D12041D4167EFC77E7064141307ECDC3D12041616217236FE706417C7B4F17D0D120411A77718465E7064131541B57DCD12041D6C626215BE706411F111D8CE8D120418E18DEF94FE7064142B690B5F4D12041DD7D4A0F44E706411801B3D200D22041D1472B6237E70641E374C1E20CD22041E1FA4BF329E70641D966FAE418D22041314284C31BE706414E0A9DD824D2204107E2B7D30CE70641C57CE9BC30D2204185A9D624FDE60641FED120913CD220419A63DCB7ECE60641EE1F855448D2204140C7D08DDBE60641A58A590654D22041EB66C7A7C9E606412A50E2A55FD22041409FDF06B7E6064141D464326BD22041168544ACA3E606411BAC27AB76D22041B0D22C998FE60641FDA9720F82D220413ED4DACE7AE60641C9E88E5E8DD22041AB539C4E65E6064175D7C69798D22041AD83CA194FE60641754466BAA3D220411CEAC93138E60641FD68BAC5AED220419A490A9820E6064144F411B9B9D22041808A064E08E606419916BD93C4D2204119A34455EFE506416C8C0D55CFD22041337F55AFD5E506413FA956FCD9D22041F6E6D45DBBE506417962ED88E4D220410F656962A0E506411B5A28FAEED22041352CC4BE84E5064169E95F4FF9D22041FAFBA07468E50641622BEE8703D32041FA04C6854BE5064134072FA30DD320415BCC03F42DE506417A3A80A017D32041B00E35C10FE506417263417F21D320412DA23EEFF0E406410B0BD43E2BD3204146580F80D1E40641CEAE9BDE34D320419FDE9F75B1E40641BACAFD5D3ED320416E9FF2D190E40641E9E261BC47D320412FA113976FE406412B8D31F950D32041CE6518C74DE406416C7AD8135AD320412EC91F642BE406410780C40B63D320411EDF517008E40641EDA065E06BD32041BAD0DFEDE4E30641B0162E9174D3204138B903DFC0E30641655A921D7DD320412B8200469CE30641642D098585D320412DBF212577E30641E4A10BC78DD320410D89BB7E51E30641722315E395D320416A582A552BE30641417FA3D89DD32041C9DFD2AA04E3064155EC36A7A5D3204129E52182DDE206418313524EADD32041141B8CDDB5E2064154177ACDB4D3204133F98DBF8DE20641B49B3624BCD320416294AB2A65E206417ECD1152C3D320414B7670213CE20641E7699856CAD320418A746FA612E20641AFC55931D1D320415D8742BCE8E1064138D4E7E1D7D32041DC9F8A65BEE106416B2ED767DED32041C97DEFA493E106417419BFC2E4D32041ED841F7D68E10641568D39F2EAD320410B92CFF03CE106414C3BE3F5F0D320416DCFBA0211E1064107945BCDF6D320410B89A2B5E4E00641BFCD4478FCD3204150004E0CB8E006410DEA43F601D420417D3F8A098BE00641A8BB004707D42041B3EC29B05DE00641E6EB256A0CD420419F1C050330E006411B00615F11D42041D424F90402E00641C45E622616D42041C66DE8B8D3DF06418254DDBE1AD420418544BA21A5DF0641EE1888281FD4204116AC5A4276DF064136D31B6323D42041902EBA1D47DF0641909E546E27D42041E6ADCDB617DF06417E8EF1492BD4204174348E10E8DE0641DAB2B4F52ED420413CC5F82DB8DE0641BF1B637132D42041F62B0E1288DE06413BDDC4BC35D42041D2CCD2BF57DE0641CB12A5D738D420410A744E3A27DE0641B1E2D1C13BD4204138258C84F6DD064113811C7B3ED420417FEA99A1C5DD0641ED32590341D420417CA3889494DD0641CA505F5A43D420410FD46B6063DD06415349098045D42041F472590832DD0641ADA3347447D420413EB8698F00DD06419D01C23649D42041A1EBB6F8CEDC0641842195C74AD42041A8325D479DDC064124E094264CD42041C25E7A7E6BDC0641323AAB534DD420413DBB2DA139DC0641B74DC54E4ED4204122DB97B207DC0641425BD3174FD420410367DAB5D5DB0641E4C6C8AE4FD42041AFEA17AEA3DB0641F6189C1350D42041E5A2739E71DB0641B9FE464650D42041EE4A118A3FDB0641B34AC64650D4204135EA14740DDB0641EAF4191550D42041DEA1A25FDBDA0641DE1A45B14FD42041577ADE4FA9DA06415CFF4D1B4FD42041E830EC4777DA0641130A3E534ED420414C05EF4A45DA064107C721594DD420415687095C13DA0641BCE5082D4CD4204192645D7EE1D90641433806CF4AD4204109360BB5AFD9064109B22F3F49D42041044E32037ED9064175669E7D47D42041EB85F06B4CD9064156876E8A45D42041410C62F21AD906412163BF6543D42041B032A199E9D80641F862B30F41D420413A3CC664B8D80641800870883ED420418A2BE75687D806418CEB1DD03BD420416691177356D80641C9F5F4733BD420418FEDA63550D806412020A1BC3AD42041B94E5BE843D806413BFFB7BE37D42041CC4DB8F710D80641373905CB34D4204127E77796DED70641EA0C6FBD31D42041D6648081AAD7064170576C992ED420411B6CB0F273D7064173CF8FA62DD42041437DAEA963D7064196CCEF242BD42041B24C2E2439D706410980ADD427D420417BD497D3FFD60641F72A378D27D420412139D203FBD60641BBD33F4724D42041691385CAC2D60641F948B09A21D42041A122669194D606413F4CDA8020D42041D787A1CB81D606411BC3D15B1DD4204121FD20E44CD6064113BDD3821AD42041E185BE631CD60641BE6375E119D42041F4E53EBC11D60641DD7035A017D420413D8858E9EBD506411F15BAB715D42041C044888FCAD5064172B8440415D420419D9A9548BED50641F38CCA8314D4204145EBEB8CB5D5064159F3306A11D42041AB5152F37FD506418506162B10D4204110B73CBA6AD50641F8A59BC20ED420419D3C4C1D53D5064104FB13300DD42041C5B2352937D50641088704330BD42041795A2DB314D506416FED6A1908D4204112F4C64CE0D406414C3AFB3607D420411EF57681D1D406414F57C8F904D420419A620972ACD40641566B740403D42041CA69E6008BD406418BC5941400D420413B142B8D5AD406416FDA7CF4FCD32041F418CC492AD40641E1615EA4F9D32041CB3CC939FAD30641B90F6E24F6D3204190131F60CAD306418890E374F2D3204185D0C6BF9AD306411F86F995EED320411717B65B6BD30641ED83ED87EAD32041C6CBDE363CD30641290B004BE6D320414CE52E540DD30641D28674DFE1D32041043E90B6DED206417C479145DDD320418F65E860B0D20641F47E9F7DD8D32041C172185682D20641B13BEB87D3D32041D6D5FC9854D206411D64C364CED32041E62A6D2C27D20641ACB17914C9D32041B80C3C13FAD10641C9AB6297C3D32041D5E73650CDD1064192A2D5EDBDD32041F4CD25E6A0D1064172A92C18B8D32041BB49CBD774D106417F91C416B2D32041D932E42749D10641BFE3FCE9ABD32041778227D91DD106412FDB3792A5D32041062846EEF2D00641B05EDA0F9FD3204177DEEA69C8D00641BEFA4B6398D32041C701BA4E9ED00641FFDAF68C91D32041F964519F74D00641B1C3478D8AD320417828485E4BD00641E00AAE6483D32041E3902E8E22D006417E919B137CD3204142DE8D31FACF064150BC849A74D32041B023E84AD2CF0641B46CE0F96CD32041721FB8DCAACF064138F9273265D320418C1371E983CF06411726D7435DD32041BE9E7E735DCF0641831D6C2F55D320410996447D37CF0641CF6767F54CD32041AADE1E0912CF064175E34B9644D320418E486119EDCE0641F0BC9E123CD32041546957B0C8CE06417866E76A33D32041C17744D0A4CE0641988FAF9F2AD32041C827637B81CE06419E1C83B121D320411287E5B35ECE0641EA1DF0A018D3204110DAF47B3CCE06411AC7866E0FD320419779B1D51ACE06411566D91A06D3204115B132C3F9CD0641F3597CA6FCD22041429D8646D9CD0641C2090612F3D22041780BB261B9CD064134DB0E5EE9D220419359B0169ACD06412129318BDFD22041665673677BCD0641EF39099AD5D22041D322E3555DCD0641E235358BCBD220416D13DEE33FCD0641E235350BC4D22041D379444A2ACD0641AC023E20BED22041A784D46819CD06418CFEF68FB0D2204154180A17F3CC064185380E5AABD220418A51754CE4CC06410C04280BA6D22041A696A406D5CC0641E93E2F859ED22041CA96A668BFCC064195CF61CA9CD220413BBDF073BACC0641D66B78D396D2204163E95569A9CC06417C148EF58ED22041871380C892CC0641336E1E3F89D2204164F6B98082CC06419EF3247A82D22041DE329F636FCC0641B25CDA0C5AD22041F1A75665F9CB06412919FE4B53D22041B6F74CE6E5CB06410FF56A5634D22041010B0B808DCB0641BD1072601CD2204135529BB548CB064155CC071412D2204189D4B9A12BCB06410CBB9EAA07D2204136E5EE340FCB0641AA47E024FDD120411C0A0971F3CA064102AA7783F2D12041E20CCC57D8CA06410DDC11C7E7D1204143DEF0EABDCA0641EC8E5DF0DCD12041077A252CA4CA0641D01F0B00D2D12041AFCB0C1D8BCA0641BF8CCCF6C6D12041D1933EBF72CA0641496955D5BBD12041334E47145BCA06411BD35A9CB0D120419118A81D44CA06417C66934CA5D12041269AD6DC2DCA0641B432B7E699D12041EFEB3C5318CA064156AE7F6B8ED120419F81398203CA064177ABA7DB82D1204161131F6BEFC90641D24BEB3777D120414A88340FDCC90641CBF407816BD1204197E1B46FC9C906416C43BCB75FD12041A326CF8DB7C906414600C8DC53D12041A651A66AA6C906413E13ECF047D12041383D510796C906414A77EAF43BD120419492DA6486C90641222E86E92FD12041A8B8408477C90641D33383CF23D12041E8C3756669C906415172A6A717D12041EA665F0C5CC90641EEB4B5720BD12041D0E3D6764FC90641CB9B7731FFD0204174FEA8A643C90641348FB3E4F2D0204169EF959C38C90641F8B2318DE6D02041C05751592EC90641AED9BA2BDAD020419C3582DD24C90641F17718C1CDD0204199D9C2291CC906419097144EC1D02041FCDCA03E14C90641BECA79D3B4D02041AD189D1C0DC90641281F1352A8D02041109D2BC406C906411411ACCA9BD020419DAAB33501C906416E7E103E8FD0204153AB8F71FCC80641D7990CAD82D02041F82C0D78F8C80641A5DD6C1876D020412DDC6C49F5C80641E8FEFD8069D020414D80E2E5F2C8064165E08CE75CD0204128F8944DF1C806419085E64C50D0204188379E80F0C806418705D8B143D0204189450B7FF0C80641057E2E1737D02041C73BDC48F1C806415A06B77D2AD020415E4604DEF2C8064162A23EE61DD02041B7A4693EF5C806417C35925111D020412DABE569F8C8064188757EC004D0204183C54460FCC80641DFDDCF33F8CF20412A7A462101C9064154A252ACEBCF2041596E9DAC06C906413EA2D22ADFCF2041FC6AEF010DC906417F5B1BB0D2CF20416A62D52014C9064195DDF73CC6CF2041F976DB081CC90641B2BC32D2B9CF2041520281B924C90641DD049670ADCF2041A99D38322EC90641182DEB18A1CF2041B12A687238C90641960AFBCB94CF20416CDD687943C90641F1C38D8A88CF2041C54687464FC9064177C46A557CCF2041F75F03D95BC906417AAF582D70CF2041C296103069C90641B0531D1364CF20416ADAD54A77C90641A19E7D0758CF204185A96D2886C9064124903D0B4CCF20419220E6C795C90641E52D201F40CF204155094128A6C906410777E74334CF204106EB7348B7C90641C757547A28CF20413B1B6827C9C90641409D26C31CCF2041A0CFFAC3DBC9064136E91C1F11CF20417530FD1CEFC90641F9A5F48E05CF2041CA6B343103CA06415CFA6913FACE204186C959FF17CA0641BEBD37ADEECE204127C01A862DCA06412B6C175DE3CE2041490A19C443CA0641901AC123D8CE2041E9BCEAB75ACA0641086BEB01CDCE2041675E1A6072CA064145814BF8C1CE204141FE26BB8ACA064104F79407B7CE20418D4D84C7A3CA0641AAD07930ACCE204126B89A83BDCA0641F071AA73A1CE2041997EC7EDD7CA0641AE92D5D196CE2041BFD05C04F3CA0641BD33A84B8CCE20410FE9A1C50ECB0641FF93CDE181CE2041A528D32F2BCB06417225EF9477CE2041F233224148CB06417682B4656DCE20412610B6F765CB06411E63C35463CE20413741AB5184CB0641AB92BF6259CE2041A6E8134DA3CB064121E54A904FCE2041DCE4F7E7C2CB0641FE2C05DE45CE204138F15420E3CB064115318C4C3CCE2041BFC61EF403CC064182A27BDC32CE20416C3D3F6125CC0641C4126D8E29CE20412A6E966547CC064101EAF76220CE20415FD5FAFE69CC06415F5DB15A17CE20412076392B8DCC06418B652C760ECE2041F5FD15E8B0CC064164B5F9B505CE204140E94A33D5CC0641C3B0A71AFDCD20412DA8890AFACC06417463C2A4F4CD20413EC47A6B1FCD06414978D354ECCD20416606BE5345CD06416130622BE4CD2041B19DEAC06BCD0641895AF328DCCD204179468FB092CD0641CF4A094ED4CD204122723220BACD064135D2239BCCCD2041636F520DE2CD06419836C010C5CD20410C9365750ACE0641B22A59AFBDCD20415461DA5533CE064154C66677B6CD20419EB717AC5CCE0641BE7E5E69AFCD2041C9F67C7586CE06412D1FB385A8CD2041E72D62AFB0CE06418DC1D4CCA1CD20417C451857DBCE064156C7303F9BCD2041272BE96906CF06419ED231DD94CD2041BEFD17E531CF06414EBF3FA78ECD2041DF39E1C55DCF0641879CBF9D88CD2041E6E67A098ACF06413AA613C182CD20414DC414ADB6CF0641E63E9B117DCD20417777D8ADE3CF064188E9B28F77CD2041D9B9E90811D00641BC43B43B72CD2041858766BB3ED006410A00F6156DCD2041144E67C26CD0064160E0CB1E68CD2041E91BFF1A9BD00641C5B0865663CD2041CBCF3BC2C9D00641304274BD5ECD2041D44826B5F8D006419C65DF535ACD2041B396C2F027D1064141E70F1A56CD2041382A107257D10641088A4A1052CD20412F060A3687D106412A03D1364ECD204182F0A639B7D1064102F6E18D4ACD20419FA3D979E7D1064115F0B81547CD2041240091F317D2064145658ECE43CD2041BF3EB8A348D206413EAC97B840CD20415A22378779D2064110FB06D43DCD20416F2AF29AAAD20641FD630B213BCD20419AC5CADBDBD20641018299023BCD20413CA17034DED20641AA32C92C38CD2041248605ECF3D206416BA14B8532CD20410C993DF220D306415DC45A0B2DCD204130AC31524ED30641F3954FBF27CD2041FB8100097CD30641E32680A122CD2041A359C313AAD30641B3983FB21DCD2041521E8E6FD8D306417318DEF118CD2041A0966F1907D40641A2D9A86014CD20415D94710E36D406414E11EAFE0FCD2041B624994B65D4064158F1E8CC0BCD20419DC0E6CD94D40641F3A3E9CA07CD2041817D5692C4D4064150472DF903CD20414C3EE095F4D406417BE9F15700CD2041A5E477D524D506416B8472E7FCCC204173820D4E55D5064145FAE6A7F9CC20419D8B8DFC85D50641CE118499F6CC20410A08E1DDB6D5064113737BBCF3CC2041CFC5EDEEE7D5064141A4FB10F1CC20419B8B962C19D60641B4063097EECC20414E4BBB934AD6064131D4404FECCC2041C15439217CD606415D1C5339EACC2041B988EBD1ADD6064162C28855E8CC2041FD8BAAA2DFD60641C57A00A4E6CC204197FA4C9011D7064179C9D524E5CC2041329BA79743D706411B0021D8E3CC204197928DB575D70641683CF7BDE2CC20414297D0E6A7D70641E7666AD6E1CC204113254128DAD70641C7318921E1CC20410FB1AE760CD80641EC175F9FE0CC204131DDE7CE3ED80641385CF44FE0CC204151ACBA2D71D8064107094E33E0CC204106B6F48FA3D80641D5EF6D49E0CC20419E5A63F2D5D806412AA95292E0CC204110F7D35108D90641A994F70DE1CC2041EF1814AB3AD9064160D954BCE1CC204162B2F1FA6CD9064148665F9DE2CC2041094E3B3E9FD90641F2F208B1E3CC2041E242C071D1D90641790040F7E4CC20411FE8509203DA064195DAEF6FE6CC2041EAC8BE9C35DA0641F398001BE8CC204111D8DC8D67DA0641B32057F8E9CC2041ABA37F6299DA06412526D507ECCC20418D887D17CBDA0641458D3253ECCC204166CCE1DCD1DA0641"
tc = "0106000020346C00000100000001030000000100000008000000A0C36C35F4CF2041C0FFD4E8DFDD0641B0447216F3CF2041401F245D7CDD0641808B4A9BBCCF2041C0E14CEB88DD0641C8A30F2DBECF204180F4925CEDDD0641C85CCB39B7CF204140272842EEDD0641007590CBB8CF2041809B82FA58DE064100DC31C7F5CF204100742FA14ADE0641A0C36C35F4CF2041C0FFD4E8DFDD0641"
SELECT ST_DIFFERENCE(t1.geom, t2.geom)
FROM test AS t1, tc AS t2
Both are in the same SRID/CRS.
I have further tried linking the two polygons using:
SELECT ST_DIFFERENCE(t1.geom, t2.geom)
FROM test AS t1
INNER JOIN tc AS t2
ON ST_INTERSECTS(t1.geom, t2.geom)
Neither approach returns test with the the section of tc removed

Related

Using SQL Server spatial queries, how to select a shape that is produced by intersecting two other shapes and calculate its area?

Consider the following query:
SELECT b.*
FROM dbo.BndPrimarySchoolZone b
WHERE b.ncessch IN ( 250315000417, 250315000421 );
It produces two rows, returning some descriptive data along with two shapes (Shape column is of data type geometry):
In the "Spatial results" tab you can see that these two shapes overlap:
Question: how can I isolate just the overlapping area into a separate shape and calculate its area?
I have looked at STIntersects, but that seems to only be useful for determining if the shapes intersect, and not for finding the actual intersection. I understand that once I have the intersection, finding its area is trivial with STArea.
Actually, after discovering the STIntersection function, I think this works:
WITH cte_school1
AS (SELECT b.*
FROM dbo.BndPrimarySchoolZone b
WHERE b.ncessch = 250315000417),
cte_school2
AS (SELECT b.*
FROM dbo.BndPrimarySchoolZone b
WHERE b.ncessch = 250315000421)
SELECT s1.Shape.STIntersection(s2.Shape),
s1.Shape.STIntersection(s2.Shape).STArea()
FROM cte_school1 s1
JOIN cte_school2 s2
ON s1.Shape.STIntersects(s2.Shape) = 1;
If there is a better way to do it, please post in comments.

Combine parts of different tables [duplicate]

I'm kind of new to writing sql and I have a question about joins. Here's an example select:
select bb.name from big_box bb, middle_box mb, little_box lb
where lb.color = 'green' and lb.parent_box = mb and mb.parent_box = bb;
So let's say that I'm looking for the names of all the big boxes that have nested somewhere inside them a little box that's green. If I understand correctly, the above syntax is another way of getting the same results that we could get by using the 'join' keyword.
Questions: is the above select statement efficient for the task it's doing? If not, what is a better way to do it? Is the statement syntactic sugar for a join or is it actually doing something else?
If you have links to any good material on the subject I'd gladly read it, but since I don't know exactly what this technique is called I'm having trouble googling it.
You are using implicit join syntax. This is equivalent to using the JOIN keyword but it is a good idea to avoid this syntax completely and instead use explicit joins:
SELECT bb.name
FROM big_box bb
JOIN middle_box mb ON mb.parent_box = bb.id
JOIN little_box lb ON lb.parent_box = mb.id
WHERE lb.color = 'green'
You were also missing the column name in the join condition. I have guessed that the column is called id.
This type of query should be efficient if the tables are indexed correctly. In particular there should be foreign key constraints on the join conditions and an index on little_box.color.
An issue with your query is that if there are multiple green boxes inside a single box you will get duplicate rows returned. These duplicates can be removed by addding DISTINCT after SELECT.

Transfer polygon information to point later using STContains()

I would like to build a query that will transfer information from a polygon layer (~1100 records) to a point layer (~300 points). I want Comp_Numb and Stand_Number values to be transferred to the points layer when a new point is added to the database.
I have built the following query (it is a select query but I will change it to an update query when it is working properly):
SELECT GPS.Invent_Plot_ID, stands.Comp_Numb, stands.Stand_Number
FROM FORESTRY.dbo.[GSCA #] AS stands
INNER JOIN GPS_DATA.dbo.GPS_Forest_Inventory_test AS GPS
ON stands.Geometry.STContains(stands.Geometry) = 1
When I run the query it returns >590,000 records. I have looked around at examples such as this.
Where do I go next?

Non standard join

I ran into a problem and was trying to find a general solution to it as a join.
I have 2 tables :
http://pastebin.com/q5yws5Ym (not sure how to enforce the styling)
And i want to generate something like
http://pastebin.com/GscBUrYS
(while there are more parameters i'm interested in how i would do it for something like this)
While i was able to reach a similar effect with self-joins and equi-joins it would generate a lot of unneeded rows, which i'm not sure how to delete automatically.
Try something along the lines of:
SELECT user.user_id, j1.user_param, j1.user_value, j2.user_param, j2.user_value
FROM user
JOIN Users_info j1 ON user.user_id = j1.user_id
JOIN users_info j2 on user.user_id = j2.user_id
where j1.user_param != j2.user_param
GROUP BY user.user_id
It may be possible that you will need some more "exclusion" clauses for the where to make sure that every row is only selected once but the general idea should work (for a given and limited number of different user_param`s).

PostGIS geometry database query

I have several tables that contain multipolygons. I need to find points within these polygons that I can use in my java test class. What I have been doing is sending a query to return all the multi polygons, choose a vertex to use as a point, and most times it works.
However these tables represent risk data, 1 in 100, 1 in 200 etc, and so some of the points are shared between tables (the higher risk multi polygons are encapsulated by the lower risk). what query can I use to return a point that will be within 1 multipolygon in 1 table, but not in any others that I specify?
the tables are river_100_1k, river_200_1k, and river_1000_1k
Well you could do a multiple left join:
SELECT a.gid, a.the_geom FROM pointsTable a
LEFT JOIN river_100_1k b
ON ST_Intersects(a.the_geom, b.the_geom)
LEFT JOIN
river_200_1k c
ON NOT ST_Intersects(a.the_geom, c.the_geom) -- Not Intersects
LEFT JOIN
river_1000_1k d
ON NOT ST_Intersects(a.the_geom, d.the_geom) -- Not Intersects
WHERE
AND c.gid IS NULL AND d.gid IS NULL AND b.gid=2 AND c.gid=2 AND d.gid=2 ;
I'm not sure if I understand correctly but this is the path you should take.
Use ST_PointOnSurface(polygon) to get a point within a polygon.

Resources