当前位置: 首页 > 知识库问答 >
问题:

PostGIS ST_Interacts和Join不工作

劳星晖
2023-03-14

我正在尝试连接多多边形(geom)和点(拾取),以便可以找到自治市镇中的拾取器数量。我正在使用下面的代码,但它超时并且不返回任何内容。我也尝试了ST_Contains什么都不返回。想法将不胜感激。谢谢。

SELECT z.borough, count(*) "Count"
FROM public.taxi_zones z
JOIN public.trips t 
    ON (z.geom && t.pickup)
WHERE ST_Intersects(t.pickup, z.geom)
GROUP BY z.borough

以下是数据示例。拾取数据类型为“几何体(点,4326)”,而geom数据类型为几何体(多边形,4326”。geom变量是一个非常长的字符串,因此我不能在不超过字符限制的情况下为它发布多个数据点。

borough pickup  geom
EWR 0101000020E610000049A297512C7F52C02B2FF99FFC5D4440  0106000020E610000001000000010300000001000000E800000089A9F413CE8B52C0DA6C01A1F5584440315EF3AACE8B52C0684E7ADFF8584440590BB3D0CE8B52C0AAD573D2FB5844403D40F7E5CC8B52C0B100C2871259444071CFBA46CB8B52C0BB0E2A711D594440BD310400C78B52C0E9EDEBC039594440C913083BC58B52C081DDCCE847594440DDE68D93C28B52C0EA27B85851594440C11BD2A8C08B52C01AF911BF6259444071B2D47ABF8B52C0A1E908E0665944402158552FBF8B52C08B25016A6A59444079A35698BE8B52C0C2CAF6216F594440410DDFC2BA8B52C0CA20938C9C594440214223D8B88B52C06C3BC269C15944404DEFE2FDB88B52C0A9196EC0E7594440D1E7A38CB88B52C070A0DCB6EF5944400186E5CFB78B52C093724C16F75944403515A930B68B52C09A71361D015A44407195EEAEB38B52C0A97020240B5A4440E1B37570B08B52C06A060DFD135A4440F9777DE6AC8B52C03C7EFD101B5A4440E98EC536A98B52C00AE76F42215A4440D1B48B69A68B52C0437DE717255A4440C1CBD3B9A28B52C023C85D84295A444089355CE49E8B52C00804560E2D5A4440FD4465C39A8B52C0F13F4E98305A4440B9B6B75B928B52C0734E417E365A444085ED27637C8B52C0992E19C7485A4440C948BDA7728B52C0BCF10A444F5A4440B5585183698B52C03900FE29555A4440CD15A584608B52C068B471C45A5A44409D5A7D75558B52C091776341615A4440D5E940D6538B52C0313BE0BA625A444009790437528B52C02059DC7F645A4440A535CD3B4E8B52C0432B4CDF6B5A4440954C158C4A8B52C0591BB803755A44402527DA55488B52C079DEA9807B5A44406998A1F1448B52C048569A94825A4440C9D42478438B52C03A83143C855A44400164E8D8418B52C0D4550F98875A4440C5CD70033E8B52C007EC866D8B5A4440BDD53A71398B52C04B7380608E5A4440ADEC82C1358B52C0EA36FDD98F5A4440852991442F8B52C0DC637781925A4440F531E6AE258B52C0723672DD945A4440C58CF0F6208B52C0B9AEEDED965A4440496F7F2E1A8B52C05963EC84975A4440495299620E8B52C05481E849995A4440B162B83A008B52C031BDE0D39C5A44402572C119FC8A52C0D4805D4D9E5A4440C91F0C3CF78A52C029DBDC989E5A444059FAD005F58A52C0D4805D4D9E5A44409947FE60E08A52C07A355CE49E5A44406976A4FACE8A52C031CC5EB69D5A444009E36E10AD8A52C0419FE40E9B5A4440FDA204FD858A52C0F92669FE985A4440818593347F8A52C059726A67985A444049B54FC7638A52C061546EA2965A4440D164C6DB4A8A52C07827F4FA935A44406D218FE0468A52C028BEF6CC925A44400DDE57E5428A52C0D854F99E915A44402D93E1783E8A52C0F0277FF78E5A4440FDD7B969338A52C0D2550F98875A4440D12346CF2D8A52C09CBF97C2835A444089ABCABE2B8A52C04A569A94825A4440D5F7E120218A52C0DC29ABE97A5A44406150A6D1E48952C0A02D03CE525A4440711C78B5DC8952C02A1092054C5A4440F905BB61DB8952C0E29716F5495A444089E07F2BD98952C0F2791A30485A44406D15C440D78952C0D9A694D74A5A4440D52C978DCE8952C0014DA088455A4440DD1D19ABCD8952C09B1F9BE4475A4440E9FF1CE6CB8952C051B69DB6465A4440553B8A73D48952C07A135FED285A4440358600E0D88952C050420587175A4440499352D0ED8952C0C2A3A99ECC594440D192C7D3F28952C0DB4ACB48BD59444055923CD7F78952C09AB5696CAF594440E18233F8FB8952C0FBD40627A259444039E466B8018A52C0C1122BA3915944400D6ABFB5138A52C0A2CC22145B594440AD2D3C2F158A52C021CDAD10565944407D8FFAEB158A52C090DCB6EF515944402144F982168A52C0B59140834D59444051FF2092218A52C0997686A92D5944404150357A358A52C0F2300917F25844408DB932A8368A52C0604012F6ED584440A1A99ECC3F8A52C0AB7EC16ED85844406D218FE0468A52C0D1EA0088BB5844407D5A457F688A52C0E1E4D3635B58444091347F4C6B8A52C073A966D65258444085527B116D8A52C0E9A9F1D24D584440D9ACFA5C6D8A52C0EBA9F1D24D58444055B439CE6D8A52C0E9A9F1D24D584440717FF5B86F8A52C0915EF0694E584440ED86342A708A52C0E1C7ED974F58444035FFAF3A728A52C0D2E5E95C51584440D5C22CB4738A52C02D4069A8515844409D336953758A52C07B9AE8F351584440BDFE243E778A52C0C9F4673F52584440C5F65AD07B8A52C01B5E656D53584440214910AE808A52C068C7629B545844406DB20DDC818A52C06CC7629B5458444069C18BBE828A52C068B8E4B853584440D9E6C6F4848A52C0C903E6215358444071B9C150878A52C0D0E5E95C515844405DE63BF8898A52C04204711E4E584440A55EB7088C8A52C0B4137AFD49584440C12973F38D8A52C0895F066344584440394030478F8A52C0619C14E63D5844406DE525FF938A52C026E9B6442E58444005B8205B968A52C0A3E9414129584440FDC69E3D978A52C012F94A2025584440453F1A4E998A52C099DBD9571E584440316C94F59B8A52C04B55F65D11584440258A90BA9D8A52C0CB55815A0C5844405528D2FD9C8A52C00BB1169F025844402D7B12D89C8A52C0C9291DACFF574440D920938C9C8A52C0CA1BB5C2F45744402D7B12D89C8A52C08A853DEDF057444079E40F069E8A52C06CC24B70EA5744403D64CA87A08A52C001786000E157444091C5FD47A68A52C0CFA6069ACF57444085E3F90CA88A52C0F25B902DCB574440BD7971E2AB8A52C0ABD5AC33BE574440A5B5696CAF8A52C0389A3FA6B5574440712D5A80B68A52C08BC9703C9F57444015F88A6EBD8A52C0C2251C7A8B574440DD68C70DBF8A52C03926A776865744404D8E0244C18A52C06CBD3445805744406959BE2EC38A52C0DACC3D247C5744408D15FC36C48A52C051DC46037857444045B3B27DC88A52C0A319E0826C574440191C25AFCE8A52C0D9758BC058574440756EDA8CD38A52C093EFA7C64B574440E59315C3D58A52C0C177B7B244574440251B0FB6D88A52C0A4A547533D57444051CF8250DE8A52C0227A6EA12B574440C1F4BD86E08A52C0F2D478E9265744408965FA25E28A52C073B70721205744400974ED0BE88A52C0EF9AAC510F574440D5E429ABE98A52C01241B8020A574440C111A452EC8A52C0BAD8D0CDFE56444079AF5A99F08A52C0BBBBEA01F3564440B93D0801F98A52C02BA0A52BD856444009A7052FFA8A52C0E918AC38D5564440A96A82A8FB8A52C05C28B517D156444081C476F7008B52C0C138D4EFC2564440CD2D7425028B52C083B1DAFCBF564440C16856B60F8B52C042D32EA69956444071158BDF148B52C0F35BC98E8D564440E92B4833168B52C0BBC551B98956444009E8853B178B52C0724DD6A887564440653A3B191C8B52C0BAA86BED7D56444019EE23B7268B52C074F623456456444089135FED288B52C03860AC6F6056444025ED0DBE308B52C05BF84F3750564440E96CC83F338B52C0D4F8DA334B564440E582FA96398B52C0DDBDF8A23D564440C5E3A25A448B52C031DEAB5626564440798159A1488B52C01AEE3F321D5644406D9F55664A8B52C0E7484A7A1856444055DB4DF04D8B52C0CA76DA1A11564440155B0872508B52C002FFE9060A564440818FC18A538B52C038787B10025644409D5A7D75558B52C0AF78060DFD554440294B7496598B52C093A696ADF5554440E5D9ACFA5C8B52C0B35B2041F1554440217024D0608B52C0CA1F28B7ED55444085B35BCB648B52C0E3E32F2DEA554440650586AC6E8B52C0B92FBC92E4554440F5F57CCD728B52C06BC6BE64E35544405539B4C8768B52C01A6C3F19E355444015C8EC2C7A8B52C0C1203EB0E35544405D471CB2818B52C0F0C53368E8554440C57BD5CA848B52C0E3E32F2DEA5544400DF450DB868B52C0D9012CF2EB554440A1D5C9198A8B52C0216B2920ED554440519FE40E9B8B52C0C34B8C65FA554440C5D2872EA88B52C079FF740305564440A557CA32C48B52C0E257C85C19564440119337C0CC8B52C0539335EA21564440F9CE2F4AD08B52C08B29ADBF25564440FDD5E3BED58B52C052B01BB62D56444019A19FA9D78B52C0913715A930564440E111DC48D98B52C020198EE73356444011C64FE3DE8B52C05FBD6DA64256444081F23E8EE68B52C0B360376C5B56444029C423F1F28B52C0537B664980564440891D8D43FD8B52C0C2E1218C9F564440B5D100DE028C52C09A677A89B1564440BDC93670078C52C04A1B6327BC564440210D6E6B0B8C52C0591A4D2EC6564440FD6662BA108C52C079FA2477D8564440895759DB148C52C023CC09DAE4564440914F8F6D198C52C0577F677BF4564440194F04711E8C52C0A214C9570257444089743FA7208C52C0AA2231410D5744404503780B248C52C004A8FE4124574440916C7539258C52C05A10E6762F574440BD19355F258C52C0A188618731574440B528B341268C52C0DA1ED95C355744402D3F7095278C52C0FBF048BC3C574440254EEE77288C52C06A2CB64945574440A1552DE9288C52C0A8D0950854574440A1552DE9288C52C054A27A6B60574440254EEE77288C52C0045663096B57444079A86DC3288C52C02428D36872574440D1F36E2C288C52C07990BA9D7D5744407D99EFE0278C52C053F92CCF835744405DDDB1D8268C52C0A07092E68F574440BD19355F258C52C04C5F5D15A857444069BFB513258C52C014D74D29AF574440F9997ADD228C52C0C4D38041D2574440AD307DAF218C52C059E04735EC574440057C7E18218C52C06BDF313CF6574440351AC05B208C52C0C9291DACFF574440BD0303081F8C52C094B08BA207584440BD0303081F8C52C02C9204E10A584440115E82531F8C52C00ACEFC6A0E584440E9B0C22D1F8C52C091CD716E13584440EDA1444B1E8C52C0C281E50819584440A929C93A1C8C52C0C39ECBD4245844406D935165188C52C00A342DB1325844403DEE5BAD138C52C052BA10AB3F584440D19CBCC8048C52C048035B2558584440C1AC50A4FB8B52C0E8E3BD6A6558444025BD6F7CED8B52C0632D93E178584440DD3D40F7E58B52C0CB68006F81584440D1450A65E18B52C0F22BF2EB8758444089A9F413CE8B52C0DA6C01A1F5584440
Queens  0101000020E610000049A297512C7F52C02B2FF99FFC5D4440
Bronx   0101000020E610000049A297512C7F52C02B2FF99FFC5D4440
Manhattan   0101000020E610000049A297512C7F52C02B2FF99FFC5D4440
Staten Island   0101000020E610000049A297512C7F52C02B2FF99FFC5D4440

共有1个答案

鲜于子琪
2023-03-14

我没有检查过你的几何图形,但是

SELECT z.borough,
       COUNT(t.*) AS "Count"
FROM   public.taxi_zones AS z
JOIN   public.trips AS t
  ON   ST_Intersects(z.geom, t.pickup)
GROUP BY
       z.borough
;

应该返回与每个taxi_zones.pickup相交的*的次数。

请注意,我在 COUNT 中指定了 t.*

两个几何都必须有空间索引,并运行标准表维护来更新表统计数据。

没有必要添加bbox比较;< code>ST_Intersects包含完全相同的检查。

 类似资料:
  • 问题内容: 什么是SQL ?有哪些不同的类型? 问题答案: 是从两个或多个数据库表中检索数据的方法。 s有什么不同? 总共有5秒。他们是 : 1. JOIN或INNER JOIN: 在这种情况下,我们获得了两个表中都符合条件的所有记录,并且两个表中不匹配的记录均未报告。 换句话说,基于以下事实:仅应列出两个表中的匹配条目。 需要注意的是一个没有任何其他的关键字(如,,,等)是。换句话说,是的语法糖

  • 嗨,伙计们!我正在尝试开发火花流应用程序,但遇到了一些问题。一些细节:我们有Kafka主题,spark 3.2.1和Cassandra 4.0.4,带有datastax spark Cassandra连接器版本com.datastax.spark:spark-Cassandra-connector_2.12:3.1.0 我需要数据的下一条路线。 获取 kafka 消息并在 Spark 中转换为数据

  • 我正在尝试使用HQL来获取我的实体以及使用JOIN FETCH的子实体,如果我想要所有的结果,这很好工作,但如果我想要一个页面,情况就不是这样了 我的实体是 因为我有数百万次的访问,所以我需要使用Pageable,并且我希望在单个数据库查询中获取注释,比如: 该HQL调用引发以下异常:

  • 问题内容: 嗨,我正在尝试找出如何使用以下查询插入新记录的方法: 到目前为止,我的查询是: 但是,我不确定使用左联接和内联接时该怎么做。 所以我想做的是这样的: 表: 还有桌子 更新 是这样的吗? 问题答案: 您必须具体说明要选择的列。如果表有四列,则必须从查询中准确选择这四列。语法如下: 但是,似乎没有任何理由反对此处,因为该表中的任何列都不会插入。实际上,这似乎因主键唯一性冲突而失败。 MyS

  • 问题内容: 这两个连接将给我相同的结果: 与 语句之间的性能或其他方面有什么区别吗? 不同的 SQL 实现之间是否有所不同? 问题答案: 它们在功能上是等效的,但阅读起来可能更清晰,尤其是在查询中包含其他联接类型(即or或)的情况下。

  • 本文向大家介绍请你说一说inner join和left join相关面试题,主要包含被问及请你说一说inner join和left join时的应答技巧和注意事项,需要的朋友参考一下 参考回答: left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录