From ea56f1fd1c9dc530cc956470c9b3cadbe7a6b025 Mon Sep 17 00:00:00 2001 From: gaojuan1 Date: Tue, 22 Oct 2024 15:23:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=A1=E9=95=87=E8=A1=97=E9=81=93=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E7=82=B9=E6=A3=80=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gj/data_handle/TownCenterBatch.groovy | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/TownCenterBatch.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/TownCenterBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/TownCenterBatch.groovy new file mode 100644 index 000000000..e1bfa8969 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/TownCenterBatch.groovy @@ -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() + } +}