当前位置: 首页>>代码示例>>C#>>正文


C# DbGeography.Intersects方法代码示例

本文整理汇总了C#中System.Data.Entity.Spatial.DbGeography.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# DbGeography.Intersects方法的具体用法?C# DbGeography.Intersects怎么用?C# DbGeography.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.Entity.Spatial.DbGeography的用法示例。


在下文中一共展示了DbGeography.Intersects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetByGeoPoint

        /// <summary>
        /// Gets a list of groups surrounding the specified geopoint of the specified GroupTypeid
        /// If geofenceGroupTypeId is specified, the list of GeoFence groups will be returned with the groups as child groups of that geofence group.
        /// </summary>
        /// <param name="groupTypeId">The group type identifier.</param>
        /// <param name="geoPoint">The geo point.</param>
        /// <param name="sortByDistance">if set to <c>true</c> [sort by distance].</param>
        /// <param name="maxDistanceMiles">The maximum distance miles.</param>
        /// <param name="geofenceGroupTypeId">The geofence group type identifier.</param>
        /// <param name="queryOptions">The query options.</param>
        /// <returns></returns>
        private IQueryable GetByGeoPoint( int groupTypeId, DbGeography geoPoint, bool? sortByDistance, double? maxDistanceMiles, int? geofenceGroupTypeId, System.Web.Http.OData.Query.ODataQueryOptions<Group> queryOptions )
        {
            var rockContext = (RockContext)Service.Context;
            IEnumerable<Group> resultGroups = new List<Group>();

            if ( geoPoint != null )
            {
                if ( geofenceGroupTypeId.HasValue && geofenceGroupTypeId.Value > 0 )
                {
                    var fenceGroups = new List<Group>();

                    // Find all the groupLocation records ( belonging to groups of the "geofenceGroupType" )
                    // where the geofence surrounds the location
                    var groupLocationService = new GroupLocationService( rockContext );
                    foreach ( var fenceGroupLocation in groupLocationService
                        .Queryable( "Group,Location" ).AsNoTracking()
                        .Where( gl =>
                            gl.Group.GroupTypeId == geofenceGroupTypeId &&
                            gl.Location.GeoFence != null &&
                            geoPoint.Intersects( gl.Location.GeoFence ) )
                        .ToList() )
                    {
                        var fenceGroup = fenceGroups.FirstOrDefault( g => g.Id == fenceGroupLocation.GroupId );
                        if ( fenceGroup == null )
                        {
                            fenceGroup = fenceGroupLocation.Group;
                            fenceGroups.Add( fenceGroup );
                        }

                        fenceGroupLocation.Group = null;

                        // Find all the group groupLocation records ( with group of the "groupTypeId" ) that have a location
                        // within the fence
                        foreach ( var group in Service
                            .Queryable( "Schedule,GroupLocations.Location" ).AsNoTracking()
                            .Where( g =>
                                g.GroupTypeId == groupTypeId &&
                                g.GroupLocations.Any( gl =>
                                    gl.Location.GeoPoint != null &&
                                    gl.Location.GeoPoint.Intersects( fenceGroupLocation.Location.GeoFence ) ) ) )
                        {
                            // Remove any other group locations that do not belong to fence
                            foreach ( var gl in group.GroupLocations.ToList() )
                            {
                                if ( gl.Location.GeoPoint == null ||
                                    !gl.Location.GeoPoint.Intersects( fenceGroupLocation.Location.GeoFence ) )
                                {
                                    group.GroupLocations.Remove( gl );
                                }
                            }

                            fenceGroup.Groups.Add( group );
                        }
                    }

                    resultGroups = fenceGroups;
                }
                else
                {
                    // if a geoFence is not specified, just get all groups of this group type
                    resultGroups = Service.Queryable( "Schedule,GroupLocations.Location" ).AsNoTracking().Where( a => a.GroupTypeId == groupTypeId ).Include( a => a.GroupLocations ).ToList();
                }
            }

            // calculate the distance of each of the groups locations from the specified geoFence
            foreach ( var group in resultGroups )
            {
                foreach ( var gl in group.GroupLocations )
                {
                    // Calculate distance
                    if ( gl.Location.GeoPoint != null )
                    {
                        double meters = gl.Location.GeoPoint.Distance( geoPoint ) ?? 0.0D;
                        gl.Location.SetDistance( meters * Location.MilesPerMeter );
                    }
                }
            }

            // remove groups that don't have a GeoPoint
            resultGroups = resultGroups.Where( a => a.GroupLocations.Any( x => x.Location.GeoPoint != null ) );

            // remove groups that don't have a location within the specified radius
            if ( maxDistanceMiles.HasValue )
            {
                resultGroups = resultGroups.Where( a => a.GroupLocations.Any( x => x.Location.Distance <= maxDistanceMiles.Value ) );
            }

            var querySettings = new System.Web.Http.OData.Query.ODataQuerySettings();
            if ( sortByDistance.HasValue && sortByDistance.Value )
//.........这里部分代码省略.........
开发者ID:NewSpring,项目名称:Rock,代码行数:101,代码来源:GroupsController.Partial.cs


注:本文中的System.Data.Entity.Spatial.DbGeography.Intersects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。