在PostgreSQL / PostGIS中的多边形相交内查找点太慢

时间:2019-07-07 05:30:11

标签: postgresql postgis psycopg2 postgresql-9.4

我在psycopg2中编写了一些代码,用于计算PostgreSQL / PostGIS中两个多边形的交点内的点。

我正在使用的代码:

    for i in range(len(linesreplace) - 1):
        intersect = """select 
                   ST_Contains(
                       ST_Intersection(
                           ST_GeometryFromText('SRID=4326; POLYGON((10.9204102 40.2292182,10.5688477 36.4389612,14.3041992 36.4389612,13.4033203 40.2627607,10.9204102 40.2292182))'),
                           ST_MakeValid(
                               ST_GeometryFromText('SRID=4326; POLYGON((8.503418 39.1300602,8.2177734 36.8620427,15.4467773 36.9323301,15.1391602 39.1811753,8.503418 39.1300602))')
                           )
                       ),
                       the_geom
                   ),
                   vessel_hash,
                   the_geom
               from samplecol as col WHERE col.timestamp > """ + linesreplace[i] + """ and col.timestamp < """ + \
                    linesreplace[i + 1]

        cursor.execute(intersect)
        pointsINtw = cursor.fetchall()

代码工作正常,但是执行时间太慢。有谁知道如何加快查询速度?

0 个答案:

没有答案