乡镇街道中心点检验

This commit is contained in:
2024-10-22 15:23:50 +08:00
parent a1a06d0d8f
commit ea56f1fd1c
@@ -0,0 +1,79 @@
package com.fangjia.script.gj.data_handle
import com.fangjia.script.BaseBatch
import com.fangjia.script.BatchOwner
import com.fangjia.script.Watcher
import com.fangjia.script.looplineinfo.InsidePolygon
import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
/**
* 乡镇街道 判断 中心点是否在围栏或一个围栏是否包含多个中心点
*/
@BatchOwner(Watcher.GaoJuan)
class TownCenterBatch extends BaseBatch{
DBCollection ADMINISTRATIVE_MAPPING_COLL = MongoUtils.getCollectionByName("business", "administrative_mapping", "mongo.db.fangjia.com")
static main(args) {
runBatch(new TownCenterBatch(), args)
}
@Override
void process(Object args) {
def shapes = findHasShapeTown()
def centers = findAllCenters()
checkCenter(shapes, centers)
}
def checkCenter(shapes, centers){
def map = [:]
for(def town : shapes){
def points = InsidePolygon.createPoint4(town.shape.coordinates)
//1.先判断当前镇的中心点是否在围栏中
if(town.location){
def flag = InsidePolygon.isInArea(town.location.lng, town.location.lat, points)
if(!flag){
println town.city + " "+town.district+" "+town.street+" 不在本身围栏中"
}
}
//2.判断是否有其它点在围栏中
for(def center : centers){
if(center._id.toString() != town._id.toString()){
def flag = InsidePolygon.isInArea(center.location.lng, center.location.lat, points)
if(flag){
def list = map.get(town.city + "#"+town.district+"#"+town.street)
if(!list){
list = []
map.put(town.city + "#"+town.district+"#"+town.street)
}
list << center.city + "#"+center.district+"#"+center.street
println center.city + " "+center.district+" "+center.street+" 在 "+town.city + " "+town.district+" "+town.street+" 围栏中"
}
}
}
}
return map
}
def findHasShapeTown(){
def q = new BasicDBObject()
q.put("type", "乡镇街道")
q.put("shape", new BasicDBObject('$exists', true))
return ADMINISTRATIVE_MAPPING_COLL.find(q).batchSize(2000).toList()
}
def findAllCenters(){
def q = new BasicDBObject()
q.put("type", "乡镇街道")
q.put("location", new BasicDBObject('$exists', true))
def keys = new BasicDBObject()
keys.put("location", 1)
keys.put("city", 1)
keys.put("district", 1)
keys.put("street", 1)
return ADMINISTRATIVE_MAPPING_COLL.find(q, keys).batchSize(2000).toList()
}
}