Exemple #1
0
        /// <summary>
        /// Gets all data series that match the
        /// specified criteria and are within the geographic polygon
        /// </summary>
        /// <param name="polygons">one or multiple polygons</param>
        /// <param name="keywords">array of keywords. If set to null,
        /// results will not be filtered by keyword.</param>
        /// <param name="startDate">start date. If set to null, results will not be filtered by start date.</param>
        /// <param name="endDate">end date. If set to null, results will not be filtered by end date.</param>
        /// <param name="serviceIDs">array of serviceIDs provided by GetServicesInBox.
        /// <param name="bgWorker">The background worker (may be null) for reporting progress</param>
        /// <param name="e">The results of the search (convert to DataTable)</param>
        /// If set to null, results will not be filtered by web service.</param>
        /// <returns>A list of data series matching the specified criteria</returns>
        public void GetSeriesCatalogInPolygon(IList <IFeature> polygons, string[] keywords, DateTime startDate,
                                              DateTime endDate, int[] serviceIDs, IProgressHandler bgWorker, DoWorkEventArgs e)
        {
            double tileWidth  = 1.0; //the initial tile width is set to 1 degree
            double tileHeight = 1.0; //the initial tile height is set to 1 degree

            //(1): Get the union of the polygons
            if (polygons.Count == 0)
            {
                throw new ArgumentException("The number of polygons must be greater than zero.");
            }

            // Check for cancel
            bgWorker.CheckForCancel();

            if (polygons.Count > 1)
            {
                bgWorker.ReportProgress(0, "Processing Polygons");
            }

            //get the list of series
            var fullSeriesList = new List <SeriesDataCart>();

            foreach (IFeature polygon in polygons)
            {
                //Split the polygon area bounding box into 1x1 decimal degree tiles
                IEnvelope   env       = polygon.Envelope;
                Box         extentBox = new Box(env.Left(), env.Right(), env.Bottom(), env.Top());
                IList <Box> tiles     = SearchHelper.CreateTiles(extentBox, tileWidth, tileHeight);
                int         numTiles  = tiles.Count;


                for (int i = 0; i < numTiles; i++)
                {
                    Box tile = tiles[i];

                    bgWorker.CheckForCancel();

                    // Do the web service call
                    IEnumerable <SeriesDataCart> tileSeriesList = GetSeriesCatalogForBox(tile.XMin, tile.XMax, tile.YMin, tile.YMax, keywords, startDate, endDate, serviceIDs);

                    // Clip the points by polygon
                    IEnumerable <SeriesDataCart> seriesInPolygon = SearchHelper.ClipByPolygon(tileSeriesList, polygon);

                    fullSeriesList.AddRange(seriesInPolygon);

                    // Report progress
                    {
                        string message         = fullSeriesList.Count.ToString();
                        int    percentProgress = (i * 100) / numTiles + 1;
                        bgWorker.ReportProgress(percentProgress, message);
                    }
                }
            }

            //(4) Create the Feature Set
            SearchResult resultFs = null;

            if (fullSeriesList.Count > 0)
            {
                bgWorker.ReportProgress(0, "Calculating Points");
                resultFs = SearchHelper.ToFeatureSetsByDataSource(fullSeriesList);
            }

            // (5) Final Background worker updates
            if (e != null)
            {
                bgWorker.CheckForCancel();

                // Report progress
                bgWorker.ReportProgress(100, "Search Finished");
                e.Result = resultFs;
            }
        }
        protected override IEnumerable <SeriesDataCart> GetSeriesCatalogForBox(double xMin, double xMax, double yMin,
                                                                               double yMax, string keyword,
                                                                               DateTime startDate, DateTime endDate,
                                                                               int[] networkIDs,
                                                                               IProgressHandler bgWorker, long currentTile, long totalTilesCount)
        {
            var url = new StringBuilder();

            url.Append(_hisCentralUrl);
            url.Append("/GetSeriesCatalogForBox2");
            url.Append("?xmin=");
            url.Append(Uri.EscapeDataString(xMin.ToString(_invariantCulture)));
            url.Append("&xmax=");
            url.Append(Uri.EscapeDataString(xMax.ToString(_invariantCulture)));
            url.Append("&ymin=");
            url.Append(Uri.EscapeDataString(yMin.ToString(_invariantCulture)));
            url.Append("&ymax=");
            url.Append(Uri.EscapeDataString(yMax.ToString(_invariantCulture)));

            //to append the keyword
            url.Append("&conceptKeyword=");
            if (!String.IsNullOrEmpty(keyword))
            {
                url.Append(Uri.EscapeDataString(keyword));
            }

            //to append the list of networkIDs separated by comma
            url.Append("&networkIDs=");
            if (networkIDs != null)
            {
                var serviceParam = new StringBuilder();
                for (int i = 0; i < networkIDs.Length - 1; i++)
                {
                    serviceParam.Append(networkIDs[i]);
                    serviceParam.Append(",");
                }
                if (networkIDs.Length > 0)
                {
                    serviceParam.Append(networkIDs[networkIDs.Length - 1]);
                }
                url.Append(Uri.EscapeDataString(serviceParam.ToString()));
            }

            //to append the start and end date
            url.Append("&beginDate=");
            url.Append(Uri.EscapeDataString(startDate.ToString("MM/dd/yyyy")));
            url.Append("&endDate=");
            url.Append(Uri.EscapeDataString(endDate.ToString("MM/dd/yyyy")));

            var keywordDesc = string.Format("[{0}. Tile {1}/{2}]",
                                            String.IsNullOrEmpty(keyword) ? "All" : keyword, currentTile,
                                            totalTilesCount);

            // Try to send request several times (in case, when server returns timeout)
            const int tryCount = 5;

            for (int i = 0; i < tryCount; i++)
            {
                try
                {
                    bgWorker.CheckForCancel();
                    bgWorker.ReportMessage(i == 0
                                               ? string.Format("Sent request: {0}", keywordDesc)
                                               : string.Format("Timeout has occurred for {0}. New Attempt ({1} of {2})...",
                                                               keywordDesc, i + 1, tryCount));

                    var request = WebRequest.Create(url.ToString());
                    request.Timeout = 30 * 1000;
                    using (var response = request.GetResponse())
                        using (var reader = XmlReader.Create(response.GetResponseStream()))
                        {
                            bgWorker.ReportMessage(string.Format("Data received for {0}", keywordDesc));
                            return(ParseSeries(reader, startDate, endDate));
                        }
                }
                catch (WebException ex)
                {
                    if (ex.Status == WebExceptionStatus.Timeout)
                    {
                        continue;
                    }
                    throw;
                }
            }
            throw new WebException("Timeout. Try to decrease Search Area, or Select another Keywords.", WebExceptionStatus.Timeout);
        }
Exemple #3
0
        /// <summary>
        /// Gets all search result that match the
        /// specified criteria and are within the specific rectangle
        /// </summary>
        /// <param name="keywords">array of keywords. If set to null,
        /// results will not be filtered by keyword.</param>
        /// <param name="startDate">start date. If set to null, results will not be filtered by start date.</param>
        /// <param name="endDate">end date. If set to null, results will not be filtered by end date.</param>
        /// <param name="e">The results of the search (convert to DataTable)</param>
        /// <returns>A list of data series matching the specified criteria</returns>
        public void GetSeriesCatalogInRectangle(double xMin, double XMax, double YMin, double YMax, string[] keywords,
                                                DateTime startDate, DateTime endDate, int[] serviceIDs, IProgressHandler bgWorker, DoWorkEventArgs e)
        {
            if (bgWorker == null)
            {
                throw new ArgumentNullException("bgWorker");
            }

            double tileWidth  = 1.0; //the initial tile width is set to 1 degree
            double tileHeight = 1.0; //the initial tile height is set to 1 degree

            bgWorker.CheckForCancel();

            //get the list of series
            var fullSeriesList = new List <SeriesDataCart>();

            //Split the polygon area bounding box into 1x1 decimal degree tiles

            Box         extentBox = new Box(xMin, XMax, YMin, YMax);
            IList <Box> tiles     = SearchHelper.CreateTiles(extentBox, tileWidth, tileHeight);
            int         numTiles  = tiles.Count;

            for (int i = 0; i < numTiles; i++)
            {
                Box tile = tiles[i];

                bgWorker.CheckForCancel();

                // Do the web service call
                //IList<SeriesDataCart> tileSeriesList = new List<SeriesMetadata>();
                IEnumerable <SeriesDataCart> tileSeriesList = GetSeriesCatalogForBox(tile.XMin, tile.XMax, tile.YMin, tile.YMax, keywords, startDate, endDate, serviceIDs);

                fullSeriesList.AddRange(tileSeriesList);

                // Report progress
                {
                    string message         = fullSeriesList.Count.ToString();
                    int    percentProgress = (i * 100) / numTiles + 1;
                    bgWorker.ReportProgress(percentProgress, message);
                }
            }


            //(4) Create the Feature Set
            SearchResult resultFs = null;

            if (fullSeriesList.Count > 0)
            {
                bgWorker.ReportProgress(0, "Calculating Points");
                resultFs = SearchHelper.ToFeatureSetsByDataSource(fullSeriesList);
            }

            // (5) Final Background worker updates
            if (e != null)
            {
                bgWorker.CheckForCancel();

                // Report progress
                bgWorker.ReportProgress(100, "Search Finished");
                e.Result = resultFs;
            }
        }
        protected override IEnumerable<SeriesDataCart> GetSeriesCatalogForBox(double xMin, double xMax, double yMin,
            double yMax, string keyword,
            DateTime startDate, DateTime endDate,
            int[] networkIDs,
            IProgressHandler bgWorker, long currentTile, long totalTilesCount)
        {
            var url = new StringBuilder();
            url.Append(_hisCentralUrl);
            url.Append("/GetSeriesCatalogForBox2");
            url.Append("?xmin=");
            url.Append(Uri.EscapeDataString(xMin.ToString(_invariantCulture)));
            url.Append("&xmax=");
            url.Append(Uri.EscapeDataString(xMax.ToString(_invariantCulture)));
            url.Append("&ymin=");
            url.Append(Uri.EscapeDataString(yMin.ToString(_invariantCulture)));
            url.Append("&ymax=");
            url.Append(Uri.EscapeDataString(yMax.ToString(_invariantCulture)));

            //to append the keyword
            url.Append("&conceptKeyword=");
            if (!String.IsNullOrEmpty(keyword))
            {
                url.Append(Uri.EscapeDataString(keyword));
            }

            //to append the list of networkIDs separated by comma
            url.Append("&networkIDs=");
            if (networkIDs != null)
            {
                var serviceParam = new StringBuilder();
                for (int i = 0; i < networkIDs.Length - 1; i++)
                {
                    serviceParam.Append(networkIDs[i]);
                    serviceParam.Append(",");
                }
                if (networkIDs.Length > 0)
                {
                    serviceParam.Append(networkIDs[networkIDs.Length - 1]);
                }
                url.Append(Uri.EscapeDataString(serviceParam.ToString()));
            }

            //to append the start and end date
            url.Append("&beginDate=");
            url.Append(Uri.EscapeDataString(startDate.ToString("MM/dd/yyyy")));
            url.Append("&endDate=");
            url.Append(Uri.EscapeDataString(endDate.ToString("MM/dd/yyyy")));

            var keywordDesc = string.Format("[{0}. Tile {1}/{2}]",
                                            String.IsNullOrEmpty(keyword) ? "All" : keyword, currentTile,
                                            totalTilesCount);

            // Try to send request several times (in case, when server returns timeout)
            const int tryCount = 5;
            for (int i = 0; i < tryCount; i++)
            {
                try
                {
                    bgWorker.CheckForCancel();
                    bgWorker.ReportMessage(i == 0
                                               ? string.Format("Sent request: {0}", keywordDesc)
                                               : string.Format("Timeout has occurred for {0}. New Attempt ({1} of {2})...",
                                                   keywordDesc, i + 1, tryCount));

                    var request = WebRequest.Create(url.ToString());
                    request.Timeout = 30 * 1000;
                    using (var response = request.GetResponse())
                    using (var reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        bgWorker.ReportMessage(string.Format("Data received for {0}", keywordDesc));
                        return ParseSeries(reader, startDate, endDate);
                    }
                }
                catch (WebException ex)
                {
                    if (ex.Status == WebExceptionStatus.Timeout)
                    {
                        continue;
                    }
                    throw;
                }
            }
            throw new WebException("Timeout. Try to decrease Search Area, or Select another Keywords.", WebExceptionStatus.Timeout);
        }