From 89c1288ec915bcbfc63e3072f3f2988a83224c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=AB=E4=B9=90=E7=9A=84=E8=80=81=E9=BC=A0=E5=AE=9D?= =?UTF-8?q?=E5=AE=9D?= Date: Fri, 23 Feb 2024 23:31:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20pgsql=E5=87=BA=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=E7=9C=9F=E5=B0=B1=E6=98=AF3857=E7=9A=84=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E6=98=AF=E6=88=91=E4=BB=AC=E6=8B=BF=E5=88=B0=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E4=B8=8A=E6=98=AF4326=E7=9A=84=EF=BC=8Cyuheng?= =?UTF-8?q?=E4=B8=80=E7=9B=B4=E5=A4=84=E7=90=86=E7=9A=84=E9=83=BD=E6=98=AF?= =?UTF-8?q?4326=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/driver_db_postgresql/__main__.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/yuheng/plugin/driver_db_postgresql/__main__.py b/src/yuheng/plugin/driver_db_postgresql/__main__.py index a0c13ed..4df878e 100644 --- a/src/yuheng/plugin/driver_db_postgresql/__main__.py +++ b/src/yuheng/plugin/driver_db_postgresql/__main__.py @@ -1,11 +1,12 @@ from typing import Optional, List import psycopg +import shapely from psycopg.types import TypeInfo from psycopg.types.shapely import register_shapely -from shapely.geometry import Point + import os import sys @@ -21,6 +22,23 @@ def check(): pass +def geoproj(): + from pyproj import Proj, transform + + # 定义原始坐标系和目标坐标系 + # 假定原坐标系为Web Mercator(EPSG:3857),目标坐标系为WGS84(EPSG:4326) + proj_from = Proj(init="epsg:3857") # 假定这个坐标是Web Mercator + proj_to = Proj(init="epsg:4326") # 转换到WGS84 + + # 原始点坐标 + x, y = 12844204.461364638, 4895775.268753434 + + # 坐标转换 + lon, lat = transform(proj_from, proj_to, x, y) + + print(f"Longitude: {lon}, Latitude: {lat}") + + def get_column( cursor: psycopg.Cursor, table_name: str, schema: str ) -> List[str]: @@ -69,6 +87,8 @@ def get_data( info = TypeInfo.fetch(connection, "geometry") register_shapely(info, connection) # 不确定 ST_AsText 和 ST_AsGeoJSON 是否可用,依照 https://www.psycopg.org/psycopg3/docs/basic/pgtypes.html#geometry-adaptation-using-shapely 为准。 + # Shapely.LineString https://shapely.readthedocs.io/en/stable/reference/shapely.LineString.html + # Shapely.Point https://shapely.readthedocs.io/en/stable/reference/shapely.Point.html with connection.cursor() as cursor: if query_mode == "full": if len(query_type) == 1 and ( @@ -129,6 +149,9 @@ def get_data( geom = attrib["way"] # print(attrib) # debug print(geom) + if isinstance(geom, shapely.geometry.Point): + print("yoo") + print(geom.x, geom.y) return result