0
我有一個簡單的SQL我從python運行,從表中獲取所有這些項目(主要是我很好奇的mpoly)。這是一個幾何。Python和postgis,試圖找出數據類型
cur = self.db.cursor()
cur.execute('select St_AsText(ST_Centroid(mpoly)) from swsite_cesiumentity')
allEntities = cur.fetchall()
然後,我可以得到信息出來:
print ' ***'
print allEntities[0]
print '----'
,它會給我:
Row(st_astext='POINT(-87.266150008217 30.0857181963441)')
這是很好,但我嘗試使用這個數據然後得到所有遠離上述點的點,並且我不知道如何使用我想要使用的sql查詢中的類型。
嘗試這樣:
for currentEntity in allEntities:
print currentEntity
cur2 = self.db.cursor()
cur2.execute ('SELECT * FROM swsite_cesiumentity WHERE ST_Distance_Sphere(mpoly, ST_GeomFromText(' + currentEntity.st_astext + ')) <= radius_mi * 1609.34)) from swsite_cesiumentity')
list = cur2.fetchall()
print list
它不喜歡什麼,我喂第二個SQL語句:
pg.ProgrammingError: ERROR: syntax error at or near "30.0857181963441"
LINE 1: ...ere(mpoly, ST_GeomFromText(POINT(-87.266150008217 30.0857181...
^
C02RH2U9G8WM:ingest sth$
請勿[cross-post](http://gis.stackexchange.com/q/226860/1872) –