Skip to content

Commit

Permalink
feat: pgsql出来的真就是3857的,但是我们拿到的实际上是4326的,yuheng一直处理的都是4326的
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoshuBaby committed Feb 23, 2024
1 parent d787fb2 commit 89c1288
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/yuheng/plugin/driver_db_postgresql/__main__.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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]:
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 89c1288

Please sign in to comment.