• netcore使用mongodb实现地理围栏--多边形


    (一)先使用mongodb查询

    1.使用百度地图坐标提取工具,获取经纬度http://api.map.baidu.com/lbsapi/getpoint/

    地理围栏坐标 

    智恒:113.914586,22.556025
     街心公园:113.935355,22.549283
     创新大厦:113.932264,22.555157
     爱普生大厦:113.941751,22.560898
     君翔达大厦:113.926803,22.566505
     深圳艺术学校:113.931402,22.560497

    测试坐标

    中山公园--之内:
    113.9263,22.553622
    博伦学校--之内:
    113.932085,22.562667

    沁园--之外:
    113.916598,22.560314
    海滨中学-之外
    113.905315,22.563651


    2.进入mongodb库后,创建索引

    db.geo.ensureIndex(  
        {  
            test1: "2dsphere"  
        }  
    );

    3.插入地理围栏图形:第一个坐标与最后一个坐标要一致,以保持图形闭合。

    db.geo.insert(
        {
            test1:
            {
                type:"Polygon",
                coordinates:[[
                    [113.914586,22.556025],
                    
                    [113.935355,22.549283],
                    [113.932264,22.555157],
                    [113.941751,22.560898],
                    [113.926803,22.566505],
                    [113.931402,22.560497],
                    
                    [113.914586,22.556025]
                ]]
            }
        }
    );

    4.坐标测试

    中山公园--之内:如果在范围之内,会有返回数据提示

    db.geo.find(
        {
            test1:
            {
                $geoIntersects:
                {
                    $geometry:{ 
                        "type" : "Point",
                        "coordinates" : [113.9263,22.553622] }
                    }
                }
            }
    );

    博伦学校--之内:如果在范围之内,会有返回数据提示

    db.geo.find(
        {
            test1:
            {
                $geoIntersects:
                {
                    $geometry:{ 
                        "type" : "Point",
                        "coordinates" : [113.932085,22.562667] }
                    }
                }
            }
    );

    沁园--之外:如果在范围之内,无返回数据

    db.geo.find(
        {
            test1:
            {
                $geoIntersects:
                {
                    $geometry:{ 
                        "type" : "Point",
                        "coordinates" : [113.916598,22.560314] }
                    }
                }
            }
    );

    海滨中学-之外:如果在范围之内,无返回数据

    db.geo.find(
        {
            test1:
            {
                $geoIntersects:
                {
                    $geometry:{ 
                        "type" : "Point",
                        "coordinates" : [113.905315,22.563651] }
                    }
                }
            }
    );

    (二)使用netcore对外提供接口

  • 相关阅读:
    百度关键词搜索量查询,百度,谷歌关键词查询工具
    推荐免费服务免费空间服务器检测
    如何成为能让大家尊重的程序员
    四天玩转windows phone开发视频之第二天总结
    用三张图片详解Asp.Net 全生命周期
    程序员该如何规划自己的人生
    博客正式开通啦!
    技术与创业不矛盾(两者是先后关系)
    工作五年的感悟
    委托与事件以及应用
  • 原文地址:https://www.cnblogs.com/tangyan/p/13679881.html
Copyright © 2020-2023  润新知