五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動(dòng)態(tài)

springboot + mongodb 通過經(jīng)緯度坐標(biāo)匹配平面區(qū)域的方法

發(fā)布日期:2022-01-28 11:34 | 文章來源:源碼之家

java api 自帶的mongodb實(shí)體無法滿足環(huán)狀多邊形的區(qū)域匹配(大概是我沒用對方法可能)所以我們要自定義一個(gè)空間坐標(biāo)類型

廢話不多說 上代碼

/**
 *
 * @author cy
 */
@Configuration
@ReadingConverter
public class CustomReadGeoJsonConverter implements Converter<Document, CustomGeoJson> {
    @Override
    public CustomGeoJson convert(Document document) {
        CustomGeoJson geoJson = new CustomGeoJson();
        geoJson.setType(document.get(GeoJsonConstant.TYPE, String.class));
        geoJson.setCoordinates(document.get(GeoJsonConstant.COORDINATES, Iterable.class));
        return geoJson;
    }
}
@Configuration
public class Config {
    @Autowired
    private CustomReadGeoJsonConverter customReadGeoJsonConverter;
    @Bean
    public MongoCustomConversions customConversions() {
        List<Converter<?, ?>> converterList = new ArrayList<>();
        converterList.add(customReadGeoJsonConverter);
        return new MongoCustomConversions(converterList);
    }
}

自定義的空間坐標(biāo)類型插入實(shí)體
其中的coordinates 可自定義插入point

/**
 * @author cy
 */
@Data
public class CustomGeoJson implements GeoJson, Serializable {
    private String type;
    private Iterable<?> coordinates;
}

在我們定義的mongodb實(shí)體中加入我們自定義的類型

/**
 * @author cy
 * @since 2021-10-20
 */
@Data
@Document(collection = "demo_mdb")
public class DemoMdb implements Serializable {
    private String id;
    @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
    private CustomGeoJson customGeoJson;
}

插入數(shù)據(jù)

public void saveData() {
 	//這里自定義point點(diǎn)集合(這里不固定格式參照mongdb官方文檔)
  	List<List<Point>> pointList = new ArrayList<>();
  	DemoMdb db=new DemoMdb();
  	//自行查看需要的類型
  	db.setType("***");
  	db.setCoordinates(pointList);
  	//mongoTemplate自行引入不做贅述
 	mongoTemplate.insert(db, DemoMdb .class);
}

查詢數(shù)據(jù)

 /**
 ** 經(jīng)度x緯度y
 **/
public List<DemoMdb> findData(String x, String y) {
        Query query = new Query(Criteria.where("customGeoJson").
        intersects(new GeoJsonPoint(Double.valueOf(x), Double.valueOf(y))));
        List<DemoMdb> dbList = mongoTemplate.find(query, DemoMdb.class);
        return dbList;
}

只是一種方法,還不完美歡迎評論指教

到此這篇關(guān)于springboot + mongodb 通過經(jīng)緯度坐標(biāo)匹配平面區(qū)域的方法的文章就介紹到這了,更多相關(guān)springboot mongodb 經(jīng)緯度內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

香港服務(wù)器租用

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部