新增小区geohash

This commit is contained in:
沈健
2021-05-25 18:01:23 +08:00
parent bf14e84e49
commit 387f6ec98b
4 changed files with 68 additions and 35 deletions
@@ -2,10 +2,9 @@ package com.fangjia.script.temp.shenjian
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.fangjia.script.lixue.util.DBUtils
import com.fangjia.script.statistics.poi.AmapPoi
import com.mongodb.BasicDBObject
import com.mongodb.DBObject
import com.fangjia.script.temp.shenjian.util.SeaweedUtils
import org.elasticsearch.geometry.utils.Geohash
/**
* @author shenjian* @since 2021/5/18
@@ -13,10 +12,11 @@ import com.mongodb.DBObject
class Temp {
static void main(String[] args) {
String jsonStr = "[{\"id\":\"B0FFLCY016\",\"parent\":[],\"childtype\":[],\"name\":\"杭州馨悦坊公寓\",\"type\":\"住宿服务;住宿服务相关;住宿服务相关\",\"typecode\":\"100000\",\"biz_type\":\"hotel\",\"address\":\"18号大街伊萨卡浩泽园\",\"location\":\"120.383947,30.289931\",\"tel\":[],\"pname\":\"浙江省\",\"cityname\":\"杭州市\",\"adname\":\"钱塘区\",\"importance\":[],\"shopid\":[],\"shopinfo\":\"0\",\"poiweight\":[],\"distance\":\"992\",\"biz_ext\":{\"rating\":[],\"cost\":[],\"hotel_ordering\":\"0\",\"lowest_price\":[],\"star\":[],\"open_time\":[],\"opentime2\":[]},\"photos\":[{\"title\":\"Logo\",\"url\":\"http://store.is.autonavi.com/showpic/7e9c5bdeeba929eb4742102b7c9bd47c\",\"provider\":[]},{\"title\":\"客房\",\"url\":\"http://store.is.autonavi.com/showpic/e4e5771e4de5083877931fda2e360f74\",\"provider\":[]},{\"title\":[],\"url\":\"http://store.is.autonavi.com/showpic/5401e1e105bcbacf550896c7575ee315\",\"provider\":[]}]}]"
JSONArray jsonArray = JSONObject.parseArray(jsonStr)
List<AmapPoi> ret = JSONObject.parseArray(jsonArray.toJSONString(), AmapPoi.class);
print(ret.size())
String str = SeaweedUtils.encodeByGeoHash(106.569161, 29.498502)
println(str)
str = Geohash.stringEncode(106.569161, 29.498502, 10)
println(str)
// wm5zc4131rmf
}
// 万友七季城C区 经度纬度不同106.569161 29.498502 原始106.56881 29.50058 距离231.7003米
@@ -0,0 +1,44 @@
package com.fangjia.script.temp.shenjian.seaweed
import com.fangjia.script.temp.shenjian.util.SeaweedUtils
import com.fangjia.script.util.DbUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBObject
import java.util.concurrent.CountDownLatch
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
/**
* 小区geohash导出
*
* @author shenjian
* @since 2021/5/25
*/
class SeaweedGeoHashExport {
static void main(String[] args) {
Set<String> set = new HashSet<>()
DBObject query = new BasicDBObject()
query.append("cat", "district").append("visible", 0)
DBObject filter = new BasicDBObject()
filter.put("lng", 1)
filter.put("lat", 1)
DbUtils.seaweed.find(query, filter).batchSize(20000).each {objTemp ->
final def obj = objTemp
if (obj.lng && obj.lat) {
def lon = obj.lng
def lat = obj.lat
set.add(SeaweedUtils.encodeByGeoHash(SeaweedUtils.formatLatLng(lon), SeaweedUtils.formatLatLng(lat),7))
}
}
def ret = []
ret << ['小区geohash']
for (String val : set) {
ret << [val]
}
com.fangjia.script.util.ExcelUtils.write("F:\\数据\\基础建设\\geohash.xlsx", ret, "geohash");
}
}
@@ -1,28 +0,0 @@
package com.fangjia.script.temp.shenjian.seaweed
import com.fangjia.script.util.DbUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBObject
class Temp {
static main (args){
DBObject query = new BasicDBObject()
query.append("cat", "district").append("visible", 0).append("city", "±±¾©")
DBObject filter = new BasicDBObject()
filter.append("build_structure", 1)
Set<String> set = new HashSet<>()
DbUtils.seaweed.find(query, filter).batchSize(10000).each({ dbo ->
if (dbo.build_structure) {
set.add(dbo.build_structure)
}
})
set.each {val ->
println(val)
}
}
}
@@ -5,6 +5,7 @@ import com.fangjia.script.datastore.FieldValidatorUtils
import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
import org.elasticsearch.geometry.utils.Geohash
import java.util.concurrent.ConcurrentHashMap
@@ -184,6 +185,22 @@ class SeaweedUtils {
return com.fangjia.script.common.DataHandleUtils.getDoubleRound(6, latOrLng / 10000000000d)
}
/**
* 小区经纬度geohash编码
* @param args
*/
static def encodeByGeoHash(double lon, double lat, int level=7) {
return Geohash.stringEncode(lon, lat, level)
}
/**
* 小区经纬度geohash解码
* @param args
*/
static def decodeByGeoHash(String geohash) {
return Geohash.decodeLongitude(geohash) + "," + Geohash.decodeLatitude(geohash)
}
static void main(String[] args) {
def alias = ["金杏一村","金杏一村","金杏一村","金杏一村","金杏一村", "金杏二村"]
println(formatAlias(alias))