居委经纬度优化

This commit is contained in:
沈健
2021-07-22 17:05:10 +08:00
parent 469f9a22f9
commit 2c24a623a7
2 changed files with 68 additions and 3 deletions
@@ -0,0 +1,44 @@
package com.fangjia.script.temp.shenjian.poi
import com.fangjia.script.temp.shenjian.util.GaoDeUtils
import com.fangjia.script.temp.shenjian.util.SeaweedUtils
import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
import com.mongodb.DBObject
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
/**
* 国家标准居委会经纬度geohash化
*
* @author shenjian
* @since 2021/7/22
*/
class CommitteeGeoHash {
static DBCollection villagesConn = MongoUtils.getCollectionByName("fangjia", "villages", "192.168.0.43", 28017)
static ExecutorService executorService = Executors.newFixedThreadPool(30)
static void main(String[] args) {
dealPoi(new BasicDBObject("status_location", 0).append("lng", new BasicDBObject('$ne', null)))
executorService.shutdown()
}
static dealPoi(DBObject query) {
villagesConn.find(query).batchSize(5000).each {objTemp ->
final def obj = objTemp
executorService.submit(new Runnable() {
@Override
void run() {
double lng = Double.valueOf(obj.lng)
double lat = Double.valueOf(obj.lat)
def geohash = SeaweedUtils.encodeByGeoHash(lng, lat, 8);
villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("geohash", geohash)))
println("已处理小区:" + obj)
}
})
}
}
}
@@ -22,6 +22,7 @@ class CommitteeLatLng {
static void main(String[] args) {
dealPoi(new BasicDBObject("status_location", new BasicDBObject('$ne', 0)))
//dealLocation()
executorService.shutdown()
}
@@ -32,13 +33,16 @@ class CommitteeLatLng {
@Override
void run() {
def city = obj.city_name
if (city == "市辖区") {
city = obj.province_name
}
def address = obj.province_name + city + obj.area_name + obj.street_name + obj.name;
def location = GaoDeUtils.parserByGaode(city, address);
if (location && location.lng) {
def lng = location.lng
def lat = location.lat
def lng = Double.valueOf(location.lng)
def lat = Double.valueOf(location.lat)
villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 0)
.append("lng", lng).append("lat", lat).append("flag_location", "已获取经纬度")))
.append("location", new BasicDBObject("lat", lat).append("lon", lng)).append("flag_location", "已获取经纬度")))
} else {
villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 2).append("flag_location", "经纬度为空")))
}
@@ -47,4 +51,21 @@ class CommitteeLatLng {
})
}
}
static dealLocation() {
villagesConn.find(new BasicDBObject("status_location", 0)).batchSize(5000).each {objTemp ->
final def obj = objTemp
executorService.submit(new Runnable() {
@Override
void run() {
if (obj.lng && obj.lat) {
def lng = Double.valueOf(obj.lng)
def lat = Double.valueOf(obj.lat)
villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("location", new BasicDBObject("lat", lat).append("lon", lng))))
}
println("已处理小区:" + obj)
}
})
}
}
}