我是postgreSQL的新手。我在postgreSQL数据库中导入了一个表。导入的表有一个' geom'字段(加密形式的坐标)。我正在使用以下查询
select ST_AsGeoJSON(geom) from dataTab where objectid='3'
我的坐标如下
"{"type":"MultiPolygon","coordinates":[[[[979999.082000002,196493.280000001],[979897.966399997,196147.8204],[979718.105800003,196197.441599995],[979823.056799993,196549.6884],[979999.082000002,196493.280000001]]]]}"
但是我要将这些数据绘制成地图,我需要将坐标作为下面的表格
[-73.9284914226121,40.5578463559797]
- 具有WK ID的谷歌地图中的此坐标为4326
有人请帮我解决这个问题吗?
答案 0 :(得分:0)
我很高兴地说我得到了上述问题的答案。
首先,我们需要找出表格的SRID。对于代码
下面的用法 override func viewDidLoad() {
super.viewDidLoad()
self.getAllUsers()
self.fetchData()
}
func getAllUsers(){
ref = Database.database().reference()
ref.child("users").observe(.value, with: { (snapshot) in
if let result = snapshot.children.allObjects as? [DataSnapshot] {
for child in result {
var userid = child.key
print(userid)
self.uuid.append(userid)
}
}
if self.uuid.contains((Auth.auth().currentUser?.uid)!) {
print("Id matched")
}
})
let array = ["Frodo", "sam", "wise", "gamgee"]
let randomIndex = Int(arc4random_uniform(UInt32(array.count)))
print(array[randomIndex])
}
func fetchData() {
let randomIndex = Int(arc4random_uniform(UInt32(uuid.count)))
print(uuid[randomIndex])
print(randomIndex)
randomI = randomIndex
Message.downloadAllMessages(forUserID: uuid[randomIndex], completion: {[weak weakSelf = self] (message) in
weakSelf?.items.append(message)
weakSelf?.items.sort{ $0.timestamp < $1.timestamp }
DispatchQueue.main.async {
if let state = weakSelf?.items.isEmpty, state == false {
weakSelf?.tableView.reloadData()
weakSelf?.tableView.scrollToRow(at: IndexPath.init(row: self.items.count - 1, section: 0), at: .bottom, animated: false)
}
}
})
Message.markMessagesRead(forUserID: uuid[randomIndex])
}
如果是'0',那就没问题了。 在我的情况下,我的桌子的WELL-KNOWN IDENTIFIER是2263.
要获取与WELL-KNOWN IDENTIFIER 4326相对应的geom数据,请运行以下查询
SELECT ST_SRID(geom) FROM dataTab LIMIT 1;
以上查询的结果是
select st_asgeojson(st_transform(ST_SetSRID(geom, 2263), 4326)) AS geojson
FROM dataTab
where objectid='3'