Beispiel #1
0
 public Point(CoordinatePoint point)
     : base(GeoShapeTypeEnum.Point)
 {
     if (point == null)
         throw new ArgumentNullException("point", "Point requires a coordinate point.");
     
     Coordinate = point;
 }
Beispiel #2
0
 internal static List<Double> BuildCoordinate(CoordinatePoint point)
 {
     return new List<Double>()
     {
         point.Longitude,
         point.Latitude
     };
 }
        /// <summary>
        /// Create a geohash_cell filter.
        /// </summary>
        /// <param name="field">The geo_point field to search against.</param>
        /// <param name="geoHash">A coordinate point object defining the geo hash.</param>
        /// <param name="distancePrecision">The allowed distance from the specified geo hash.</param>
        /// <param name="allowNeighbors">Allow the neighbors of the geo hash to be considered.</param>
        public GeoHashCellFilter(string field, CoordinatePoint geoHash, DistanceValue distancePrecision, bool allowNeighbors)
            : this(field, geoHash, allowNeighbors)
        {
            if (distancePrecision == null)
                throw new ArgumentNullException("distancePrecision", "GeoHashCellFilter requires a distance precision for this constructor.");

            DistancePrecision = distancePrecision;
        }
        /// <summary>
        /// Create a geohash_cell filter.
        /// </summary>
        /// <param name="field">The geo_point field to search against.</param>
        /// <param name="geoHash">A coordinate point object defining the geo hash.</param>
        /// <param name="geoHashPrecision">The size of the geo hash prefix that will be considered for the search.</param>
        /// <param name="allowNeighbors">Allow the neighbors of the geo hash to be considered.</param>
        public GeoHashCellFilter(string field, CoordinatePoint geoHash, int geoHashPrecision, bool allowNeighbors)
            : this(field, geoHash, allowNeighbors)
        {
            if (geoHashPrecision <= 0)
                throw new ArgumentOutOfRangeException("geoHashPrecision", "GeoHashCellFilter requires the precision of the geo hash to be greater than zero.");

            GeoHashPrecision = geoHashPrecision;
        }
Beispiel #5
0
        public Envelope(CoordinatePoint topLeft, CoordinatePoint bottomRight)
            : base(GeoShapeTypeEnum.Envelope)
        {
            if (topLeft == null)
                throw new ArgumentNullException("topLeft", "Envelope requires a top left coordinate point.");
            if (bottomRight == null)
                throw new ArgumentNullException("bottomRight", "Envelope requires a bottom right coordinate point.");

            TopLeft = topLeft;
            BottomRight = bottomRight;
        }
        private GeoHashCellFilter(string field, CoordinatePoint geoHash, bool allowNeighbors)
        {
            if (string.IsNullOrEmpty(field))
                throw new ArgumentNullException("field", "GeoHashCellFilter requires a geo_point field.");
            if (geoHash == null)
                throw new ArgumentNullException("geoHash", "GeoHashCellFilter requires a coordinate point defining a geo hash.");

            Field = field;
            GeoHash = geoHash;
            AllowNeighbors = allowNeighbors;
            Cache = GeoHashCellSerializer._CACHE_DEFAULT;
        }
        /// <summary>
        /// Create a geo_distance filter that searches from a central coordinate point.
        /// </summary>
        /// <param name="field">The document geo_point field.</param>
        /// <param name="distance">The length of the radius.</param>
        /// <param name="centerPoint">The central latitude and longitude of the search.</param>
        public GeoDistanceFilter(string field, DistanceValue distance, CoordinatePoint centerPoint)
        {
            if (string.IsNullOrWhiteSpace(field))
                throw new ArgumentNullException("field", "GeoDistanceFilter requires a field.");
            if (distance == null)
                throw new ArgumentNullException("distance", "GeoDistanceFilter requires a distance.");
            if(centerPoint == null)
                throw new ArgumentNullException("centerPoint", "GeoDistanceFilter requires a central coordinate point.");

            Field = field;
            Distance = distance;
            CenterPoint = centerPoint;
            DistanceComputeMethod = GeoDistanceSerializer._DISTANCE_TYPE_DEFAULT;
            OptimizeBoundingBox = GeoDistanceSerializer._OPTIMIZE_BBOX_DEFAULT;
            Cache = GeoDistanceSerializer._CACHE_DEFAULT;
        }
        /// <summary>
        /// Creates a geo distance facet.
        /// </summary>
        /// <param name="facetName">Sets the facet name.</param>
        /// <param name="field">Sets the geo_point field that will be used to calculate distance.</param>
        /// <param name="centerPoint">Sets the central point to calculate distance with.</param>
        /// <param name="rangeBuckets">Sets the distance range buckets.</param>
        public GeoDistanceFacet(string facetName, string field, CoordinatePoint centerPoint, IEnumerable<DistanceBucket> rangeBuckets)
        {
            if (string.IsNullOrWhiteSpace(facetName))
                throw new ArgumentNullException("facetName", "GeoDistanceFacet requires a facet name.");
            if (string.IsNullOrWhiteSpace(field))
                throw new ArgumentNullException("field", "GeoDistanceFacet requires a field.");
            if (centerPoint == null)
                throw new ArgumentNullException("centerPoint", "GeoDistanceFacet requires a center point.");
            if (rangeBuckets == null || rangeBuckets.All(x => x == null))
                throw new ArgumentNullException("rangeBuckets", "GeoDistanceFacet requires at least one distance range bucket.");

            FacetName = facetName;
            Field = field;
            CenterPoint = centerPoint;
            RangeBuckets = rangeBuckets.Where(x => x != null);
        }
        /// <summary>
        /// Creates a geo distance aggregation.
        /// </summary>
        /// <param name="name">Sets the name of the aggregation.</param>
        /// <param name="field">Sets the geo_point field to calculate distances with.</param>
        /// <param name="originPoint">Sets the origin point to calculate distances from.</param>
        public GeoDistanceAggregate(string name, string field, CoordinatePoint originPoint, IEnumerable<DistanceRangeBucket> ranges)
            : base(name)
        {
            if (string.IsNullOrWhiteSpace(field))
                throw new ArgumentNullException("field", "GeoDistanceAggregate requires a field.");
            if (originPoint == null)
                throw new ArgumentNullException("field", "GeoDistanceAggregate requires an origin point.");
            if (ranges == null || ranges.All(x => x == null))
                throw new ArgumentNullException("ranges", "GeoDistanceAggregate requires at least one range bucket.");

            Field = field;
            OriginPoint = originPoint;
            Ranges = ranges.Where(x => x != null);

            Unit = GeoDistanceSerializer._UNIT_DEFAULT;
            DistanceComputeType = GeoDistanceSerializer._DISTANCE_TYPE_DEFAULT;
        }
        private GeoBoundingBoxFilter RetrieveBox(string fieldName, Dictionary<string, object> boxDict)
        {
            // maybe are are dealing with the vertices
            if (boxDict.Count() == 4)
                return GetBoxFromVertices(fieldName, boxDict);

            CoordinatePoint topLeft;
            CoordinatePoint bottomRight;
            if (boxDict.ContainsKey(_TOP_LEFT))
            {
                topLeft = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_TOP_LEFT));
                bottomRight = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_BOTTOM_RIGHT));
            }
            else if (boxDict.ContainsKey(_TOP_RIGHT))
            {
                CoordinatePoint topRight = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_TOP_RIGHT));
                CoordinatePoint bottomLeft = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_BOTTOM_LEFT));

                topLeft = new CoordinatePoint(topRight.Latitude, bottomLeft.Longitude);
                bottomRight = new CoordinatePoint(bottomLeft.Latitude, topRight.Longitude);
            }
            else
            {
                throw new Exception("No bounding box formed by current properties.");
            }

            return new GeoBoundingBoxFilter(fieldName, topLeft, bottomRight);
        }
        // "prop1":{ "top": lat, "left":lon, "bottom": lat, "right": lon } - vertices
        private GeoBoundingBoxFilter GetBoxFromVertices(string fieldName, Dictionary<string, object> boxDict)
        {
            CoordinatePoint topLeft = new CoordinatePoint(boxDict.GetDouble(_TOP), boxDict.GetDouble(_LEFT));
            CoordinatePoint bottomRight = new CoordinatePoint(boxDict.GetDouble(_BOTTOM), boxDict.GetDouble(_RIGHT));

            return new GeoBoundingBoxFilter(fieldName, topLeft, bottomRight);
        }        
        /// <summary>
        /// Create a geo_distance_range filter.
        /// </summary>
        /// <param name="field">The geo_point field in the document.</param>
        /// <param name="point">The central point to search from.</param>
        public GeoDistanceRangeFilter(string field, CoordinatePoint centerPoint)
        {
            if (string.IsNullOrWhiteSpace(field))
                throw new ArgumentNullException("field", "GeoDistanceRangeFilter requires a field.");
            if (centerPoint == null)
                throw new ArgumentNullException("centerPoint", "GeoDistanceRangeFilter requires a central point.");

            Field = field;
            CenterPoint = centerPoint;
            Cache = GeoDistanceRangeSerializer._CACHE_DEFAULT;
        }