ArcGIS的屬性表里的shape字段內容(geometry)轉換成WKT字符串的方法


shape字段保存着geometry對象,它是以十六進制形式的二進制wkb數據,常規思路是把數據讀到取出來,然后把它轉回二進制,例如:
十六進制字符串:
2A0000000200000004000C00E9930400120300000100000080C7A0EAA50393959DD2FA05C3F8018AE805
轉成二進制:
1010100000000000000000000000000000001000000000000000000000000000000100000000000000110000000000111010011001001100000100000000000001001000000011000000000000000000000001000000000000000000000000100000001100011110100000111010101010010100000011100100111001010110011101110100101111101000000101110000111111100000000001100010101110100000000101
然后就可以解析成wkt了————解析方法需要安裝環境
——————————————————————————————————————————
其實,有另外一種更方便的方法:
如果數據保存在postgis空間數據庫中,可以使用postgis的st_astext()函數來直接獲取
todo:了解PostGIS常用函數
python示例:
`import psycopg2

"""
postgis 方法
st_astext
"""

def get_data():
"""從空間數據庫獲取shape字段(Geometry)
在sql語句中使用postgis方法st_astext()將shape轉為
"""
conn = psycopg2.connect(host='192.168.1.88', user='sde', password='123456', dbname='sde', port=5432)
cursor = conn.cursor()
# shape_sql = "select shape from bridge" # 獲取shape字段的原始內容的sql
# cursor.execute(shape_sql)
shape_astext_sql = "select st_astext(shape) from bridge" # 獲取shape字段的轉換后的內容的sql
cursor.execute(shape_astext_sql)
res = cursor.fetchall()
conn.close()
return res

if name == 'main':
res = get_data()
for i in res[3]:
print(i)`


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM