Example #1
0
 /// <summary>
 /// Returns the corresponding srid for every defined coordinate system term.
 /// </summary>
 /// <param name="coordinateSystem">The enum term for the coordinate system.</param>
 /// <returns></returns>
 public static int GetSridFromWebCoordinateSystem(WebCoordinateSystem coordinateSystem)
 {
     if (coordinateSystem.IsNotNull() && coordinateSystem.Id.ToString().Equals("RT90"))
     {
         return(3021);
     }              //4124;}
     else if (coordinateSystem.IsNotNull() && coordinateSystem.Id.ToString().Equals("GoogleMercator"))
     {
         return(3857);
     }              //900913;}
     else if (coordinateSystem.IsNotNull() && coordinateSystem.Id.ToString().Equals("Rt90_25_gon_v"))
     {
         return(3021);
     }
     else if (coordinateSystem.IsNotNull() && coordinateSystem.Id.ToString().Equals("SWEREF99_TM"))
     {
         return(3006);
     }
     else if (coordinateSystem.IsNotNull() && coordinateSystem.Id.ToString().Equals("SWEREF99"))
     {
         return(4378);
     }
     else if (coordinateSystem.IsNotNull() && coordinateSystem.Id.ToString().Equals("WGS84"))
     {
         return(4326);
     }
     else if (coordinateSystem.IsNotNull() && coordinateSystem.Id.ToString().Equals("None"))
     {
         throw new Exception("No coordinate system was supplied.");
     }
     else
     {
         throw new Exception("No coordinate system was supplied.");
     }
 }
        /// <summary>
        /// Get number of species observations
        /// that matches the search criteria.
        /// </summary>
        /// <param name="clientInformation">Information about the client that makes this web service call.</param>
        /// <param name="searchCriteria">Species observation search criteria - defined in class WebSpeciesObservationSearchCriteria.</param>
        /// <param name="coordinateSystem">Coordinate system used in search criteria.</param>
        /// <returns>Number of species observations that matches the search criteria.</returns>
        public Int64 GetSpeciesObservationCountBySpeciesObservationSearchCriteria(WebClientInformation clientInformation,
                                                                                  WebSpeciesObservationSearchCriteria searchCriteria,
                                                                                  WebCoordinateSystem coordinateSystem)
        {
            Int64 speciesObservationCount;

            using (WebServiceContext context = GetWebServiceContext(clientInformation))
            {
                try
                {
                    if (SpeciesObservationConfiguration.IsElasticsearchUsed)
                    {
                        speciesObservationCount =
                            AnalysisManager.GetSpeciesObservationCountBySearchCriteriaElasticsearch(context, searchCriteria, coordinateSystem);
                    }
                    else
                    {
                        speciesObservationCount =
                            AnalysisManager.GetSpeciesObservationCountBySearchCriteria(context, searchCriteria, coordinateSystem);
                    }

                    LogSpeciesObservationCount(speciesObservationCount);
                    return(speciesObservationCount);
                }
                catch (Exception exception)
                {
                    WebServiceData.LogManager.LogError(context, exception);
                    throw;
                }
            }
        }
        public void GetRegionsGeographyByGuids()
        {
            List <String>             guids;
            List <WebRegionGeography> regionsGeography;
            WebCoordinateSystem       coordinateSystem;

            coordinateSystem    = new WebCoordinateSystem();
            coordinateSystem.Id = CoordinateSystemId.GoogleMercator;

            guids            = null;
            regionsGeography = RegionManager.GetRegionsGeographyByGuids(GetContext(ApplicationIdentifier.ArtDatabankenSOA), guids, coordinateSystem);
            Assert.IsTrue(regionsGeography.IsEmpty());

            guids            = new List <String>();
            regionsGeography = RegionManager.GetRegionsGeographyByGuids(GetContext(), guids, coordinateSystem);
            Assert.IsTrue(regionsGeography.IsEmpty());

            guids = new List <String>();
            guids.Add(Settings.Default.ProvinceSkaneGUID);
            guids.Add(Settings.Default.ProvinceBlekingeGUID);
            regionsGeography = RegionManager.GetRegionsGeographyByGuids(GetContext(), guids, coordinateSystem);
            Assert.IsTrue(regionsGeography.IsNotEmpty());
            Assert.AreEqual(guids.Count, regionsGeography.Count);

            // Test GUID with character '.
            //guids = new List<String>();
            //guids.Add("URN:LSID:artportalen.se:area:DataSet16'Feature2");
            //regionsGeography = RegionManager.GetRegionsGeographyByGuids(GetContext(), guids, coordinateSystem);
            //Assert.IsTrue(regionsGeography.IsEmpty());
        }
        public void TestRegionGeometry()
        {
            // Test geometry for all regions in database.
            List <Int32>              regionIds;
            List <WebRegion>          regions;
            List <WebRegionCategory>  regionCategories, categories;
            List <WebRegionGeography> regionsGeography;
            WebCoordinateSystem       coordinateSystem;

            coordinateSystem    = new WebCoordinateSystem();
            coordinateSystem.Id = CoordinateSystemId.GoogleMercator;
            regionCategories    = RegionManager.GetRegionCategories(GetContext(), false, 0);
            foreach (WebRegionCategory regionCategory in regionCategories)
            {
                categories = new List <WebRegionCategory>();
                categories.Add(regionCategory);
                regions = RegionManager.GetRegionsByCategories(GetContext(), categories);
                if (regions.IsNotEmpty())
                {
                    regionIds = new List <Int32>();
                    foreach (WebRegion region in regions)
                    {
                        regionIds.Add(region.Id);
                    }
                    regionsGeography = RegionManager.GetRegionsGeographyByIds(GetContext(), regionIds, coordinateSystem);
                    Assert.IsTrue(regionsGeography.IsNotEmpty());
                    Assert.AreEqual(regions.Count, regionsGeography.Count);
                }
            }
        }
 /// <summary>
 /// Convert bounding box from one coordinate system to
 /// another coordinate system.
 /// Converted bounding box is returned as a polygon
 /// since it probably is not a rectangle any more.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="boundingBox">Bounding boxe that should be converted.</param>
 /// <param name="fromCoordinateSystem">From coordinate system.</param>
 /// <param name="toCoordinateSystem">To coordinate system.</param>
 /// <returns>Converted bounding box.</returns>
 public WebPolygon GetConvertedBoundingBox(
     WebClientInformation clientInformation,
     WebBoundingBox boundingBox,
     WebCoordinateSystem fromCoordinateSystem,
     WebCoordinateSystem toCoordinateSystem)
 {
     using (WebServiceContext context = GetWebServiceContext(clientInformation))
     {
         try
         {
             return(WebServiceData.CoordinateConversionManager.GetConvertedBoundingBox(
                        boundingBox,
                        fromCoordinateSystem,
                        toCoordinateSystem));
         }
         catch (Exception exception)
         {
             LogException(clientInformation, context, exception);
             LogParameter(context, "BoundingBox", boundingBox.WebToString());
             LogParameter(context, "FromCoordinateSystem", fromCoordinateSystem.WebToString());
             LogParameter(context, "ToCoordinateSystem", toCoordinateSystem.WebToString());
             throw;
         }
     }
 }
Example #6
0
        /// <summary>
        /// Converts the webPoint from the coordinate system given by the coordinateSystemId to all the coordinate systems listed in the <see cref="CoordinateSystemId"/> enumeration.
        /// The results are stored in the property WebPoints' dictionary
        /// </summary>
        /// <param name="webPoint"></param>
        /// <param name="coordinateSystemId"></param>
        private void ConvertCoordinates(WebPoint webPoint, CoordinateSystemId coordinateSystemId)
        {
            WebPoints = null;
            WebPoints = new Dictionary <CoordinateSystemId, WebPoint>();
            var fromWebCoordinateSystem = new WebCoordinateSystem {
                Id = coordinateSystemId
            };

            foreach (CoordinateSystemId csid in Enum.GetValues(typeof(CoordinateSystemId)))
            {
                // following coordinate systems is not used and can be skipped
                if (csid == CoordinateSystemId.None)
                {
                    continue;
                }

                //// if (csid == CoordinateSystemId.GoogleMercator) continue;
                //// todo: remove this when there is support in ProjNet to convert to LAEA
                //// http://projnet.codeplex.com/
                ////  if (csid == CoordinateSystemId.ETRS89_LAEA) continue;
                //// end
                WebPoints.Add(csid, WebServiceData.CoordinateConversionManager.GetConvertedPoint(webPoint, fromWebCoordinateSystem, new WebCoordinateSystem {
                    Id = csid
                }));
            }
        }
        public void GetGridCellSpeciesObservationCountsTest()
        {
            WebCoordinateSystem coordinateSystem;

            coordinateSystem    = new WebCoordinateSystem();
            coordinateSystem.Id = CoordinateSystemId.GoogleMercator;

            WebSpeciesObservationSearchCriteria searchCriteria = new WebSpeciesObservationSearchCriteria();

            SetDefaultSearchCriteria(searchCriteria);
            WebGridSpecification webGridSpecification = new WebGridSpecification();

            //IGridSpecification.GridCoordinateSystem = GridCoordinateSystem.RT90;
            webGridSpecification.GridCoordinateSystem    = GridCoordinateSystem.SWEREF99_TM;
            webGridSpecification.GridCellSize            = 5000;
            webGridSpecification.IsGridCellSizeSpecified = true;
            webGridSpecification.GridCellGeometryType    = GridCellGeometryType.Polygon;

            IList <WebGridCellSpeciesObservationCount> noOfGridCellObservations = WebServiceProxy.AnalysisService.GetGridSpeciesObservationCounts(GetClientInformation(), searchCriteria, webGridSpecification, coordinateSystem);

            Assert.IsTrue(noOfGridCellObservations.Count > 0);
            Assert.IsTrue(noOfGridCellObservations[0].CentreCoordinate.X > 0);
            Assert.IsTrue(noOfGridCellObservations[0].CentreCoordinate.Y > 0);
            Assert.IsTrue(noOfGridCellObservations[0].Size == 5000);
            //Assert.IsTrue(noOfGridCellObservations[0].GridCoordinateSystem.ToString().Equals(GridCoordinateSystem.RT90.ToString()));
            //Assert.IsTrue(noOfGridCellObservations[0].GridCoordinateSystem.ToString().Equals(GridCoordinateSystem.SWEREF99_TM.ToString()));
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[0].X > 0);
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[2].X > 0);
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[0].Y > 0);
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[2].Y > 0);
        }
 /// <summary>
 /// Geographic coordinate conversion of polygons.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="polygons">Polygons that should be converted.</param>
 /// <param name="fromCoordinateSystem">From coordinate system.</param>
 /// <param name="toCoordinateSystem">To coordinate system.</param>
 /// <returns>Converted points.</returns>
 public List <WebPolygon> GetConvertedPolygons(
     WebClientInformation clientInformation,
     List <WebPolygon> polygons,
     WebCoordinateSystem fromCoordinateSystem,
     WebCoordinateSystem toCoordinateSystem)
 {
     using (WebServiceContext context = GetWebServiceContext(clientInformation))
     {
         try
         {
             return(WebServiceData.CoordinateConversionManager.GetConvertedPolygons(
                        polygons,
                        fromCoordinateSystem,
                        toCoordinateSystem));
         }
         catch (Exception exception)
         {
             LogException(clientInformation, context, exception);
             LogParameter(context, "Polygons", polygons.WebToString());
             LogParameter(context, "FromCoordinateSystem", fromCoordinateSystem.WebToString());
             LogParameter(context, "ToCoordinateSystem", toCoordinateSystem.WebToString());
             throw;
         }
     }
 }
        /// <summary>
        /// Get coordinate system wkt.
        /// </summary>
        /// <param name="coordinateSystem">Coordinate system.</param>
        /// <returns>Coordinate system wkt.</returns>
        public static String GetWkt(this WebCoordinateSystem coordinateSystem)
        {
            switch (coordinateSystem.Id)
            {
            case CoordinateSystemId.None:
                return(coordinateSystem.WKT);

            case CoordinateSystemId.GoogleMercator:
                return(ArtDatabanken.Settings.Default.GoogleMercator_WKT);

            case CoordinateSystemId.Rt90_25_gon_v:
                return(ArtDatabanken.Settings.Default.Rt90_25_gon_v_WKT);

            case CoordinateSystemId.SWEREF99:
            // SWEREF99 is mapped to SWEREF99_TM in order to
            // support old definition of the enum.
            // This should be changed in the future when
            // SWEREF99 no longer is used in its old meaning.
            case CoordinateSystemId.SWEREF99_TM:
                return(ArtDatabanken.Settings.Default.SWEREF99_TM_WKT);

            case CoordinateSystemId.WGS84:
                return(ArtDatabanken.Settings.Default.WGS84_WKT);

            //case CoordinateSystemId.ETRS89_LAEA:
            //    return ArtDatabanken.Settings.Default.ETRS89_LAEA;
            default:
                throw new ArgumentException("Not handled coordinate system id " + coordinateSystem.Id.ToString());
            }
        }
        public void GetDarwinCoreBySearchCriteriaPage_Taxon_Region()
        {
            WebCoordinateSystem coordinateSystem = new WebCoordinateSystem();

            coordinateSystem.Id = CoordinateSystemId.GoogleMercator;

            WebSpeciesObservationSearchCriteria searchCriteria;


            searchCriteria = new WebSpeciesObservationSearchCriteria();
            searchCriteria.IncludePositiveObservations = true;

            searchCriteria.TaxonIds = new List <Int32>();
            searchCriteria.TaxonIds.Add(4000072); //insekter



            searchCriteria.IsNaturalOccurrence            = true;
            searchCriteria.IsIsNaturalOccurrenceSpecified = true;

            // Test one region.
            searchCriteria.RegionGuids = new List <String>();
            searchCriteria.RegionGuids.Add(ProvinceGuid.Blekinge);

            Int64 noOfObservations = WebServiceProxy.AnalysisService.GetSpeciesObservationCountBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem);

            Assert.IsTrue(noOfObservations > 0);
        }
 /// <summary>
 /// Get information about species observations that has
 /// changed.
 ///
 /// Scope is restricted to those observations that the
 /// user has access rights to. There is no access right
 /// check on deleted species observations. This means
 /// that a client can obtain information about deleted
 /// species observations that the client has not
 /// received any create or update information about.
 ///
 /// Max 25000 species observation changes can be
 /// retrieved in one web service call.
 /// Exactly one of the parameters changedFrom and
 /// changeId should be specified.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="changedFrom">Start date and time for changes that should be returned.</param>
 /// <param name="isChangedFromSpecified">Indicates if parameter changedFrom should be used.</param>
 /// <param name="changedTo">
 /// End date and time for changes that should be
 /// returned. Parameter changedTo is optional and works
 /// with either parameter changedFrom or changeId.
 /// </param>
 /// <param name="isChangedToSpecified">Indicates if parameter changedTo should be used.</param>
 /// <param name="changeId">
 /// Start id for changes that should be returned.
 /// The species observation that is changed in the
 /// specified change id may be included in returned
 /// information.
 /// </param>
 /// <param name="isChangedIdSpecified">Indicates if parameter changeId should be used. </param>
 /// <param name="maxReturnedChanges">
 /// Requested maximum number of changes that should
 /// be returned. This property is used by the client
 /// to avoid problems with resource limitations on
 /// the client side.
 /// Max 25000 changes are returned if property
 /// maxChanges has a higher value than 25000.
 /// </param>
 /// <param name="searchCriteria">
 /// Only species observations that matches the search
 /// criteria are included in the returned information.
 /// This parameter is optional and may be null.
 /// There is no check on search criteria for
 /// deleted species observations. </param>
 /// <param name="coordinateSystem">Coordinate system used in returned species observations. </param>
 /// <param name="speciesObservationSpecification">
 /// Specify which subset of the data that should be
 /// returned for each species observation.
 /// All information for each species observation is
 /// returned if this parameter is null.
 /// This parameter is currently not used.
 /// </param>
 /// <returns>
 /// Information about changed species observations.
 /// </returns>
 public WebSpeciesObservationChange GetSpeciesObservationChange(WebClientInformation clientInformation,
                                                                DateTime changedFrom,
                                                                Boolean isChangedFromSpecified,
                                                                DateTime changedTo,
                                                                Boolean isChangedToSpecified,
                                                                Int64 changeId,
                                                                Boolean isChangedIdSpecified,
                                                                Int64 maxReturnedChanges,
                                                                WebSpeciesObservationSearchCriteria searchCriteria,
                                                                WebCoordinateSystem coordinateSystem,
                                                                WebSpeciesObservationSpecification speciesObservationSpecification)
 {
     using (ClientProxy client = new ClientProxy(this, 5))
     {
         return(client.Client.GetSpeciesObservationChange(clientInformation,
                                                          changedFrom,
                                                          isChangedFromSpecified,
                                                          changedTo,
                                                          isChangedToSpecified,
                                                          changeId,
                                                          isChangedIdSpecified,
                                                          maxReturnedChanges,
                                                          searchCriteria,
                                                          coordinateSystem,
                                                          speciesObservationSpecification));
     }
 }
        public void GetConvertedPoint()
        {
            Double fromX, fromY;
            WebCoordinateSystem fromCoordinateSystem, toCoordinateSystem;
            WebPoint            fromPoint, toPoint;

            fromX                   = 1727060.905; // 1644820;
            fromY                   = 7453389.762; // 6680450;
            fromPoint               = new WebPoint(fromX, fromY);
            fromCoordinateSystem    = new WebCoordinateSystem();
            fromCoordinateSystem.Id = CoordinateSystemId.Rt90_25_gon_v;
            foreach (CoordinateSystemId coordinateSystemId in Enum.GetValues(typeof(CoordinateSystemId)))
            {
                toCoordinateSystem    = new WebCoordinateSystem();
                toCoordinateSystem.Id = coordinateSystemId;
                if (toCoordinateSystem.Id == CoordinateSystemId.None)
                {
                    toCoordinateSystem.WKT = ArtDatabanken.Settings.Default.Rt90_25_gon_v_WKT;
                }
                toPoint = GetCoordinateConversionManager(true).GetConvertedPoint(fromPoint, fromCoordinateSystem, toCoordinateSystem);
                Assert.IsNotNull(toPoint);
                if (fromCoordinateSystem.GetWkt() == toCoordinateSystem.GetWkt())
                {
                    Assert.IsTrue(Math.Abs(fromX - toPoint.X) < 2);
                    Assert.IsTrue(Math.Abs(fromY - toPoint.Y) < 2);
                }
                else
                {
                    Assert.IsTrue(Math.Abs(fromX - toPoint.X) > 1);
                    Assert.IsTrue(Math.Abs(fromY - toPoint.Y) > 1);
                }
            }
        }
 public List <WebGridCellFeatureStatistics> GetGridFeatureStatistics(WebClientInformation clientInformation,
                                                                     WebFeatureStatisticsSpecification featureStatisticsSpecification,
                                                                     String featuresUrl,
                                                                     String featureCollectionJson,
                                                                     WebGridSpecification gridSpecification,
                                                                     WebCoordinateSystem coordinateSystem)
 {
     using (WebServiceContext context = GetWebServiceContext(clientInformation))
     {
         try
         {
             var featuresUri = string.IsNullOrEmpty(featuresUrl) ? null : new Uri(featuresUrl);
             return(AnalysisManager.GetGridCellFeatureStatistics(context,
                                                                 featuresUri,
                                                                 featureCollectionJson,
                                                                 gridSpecification,
                                                                 coordinateSystem));
         }
         catch (Exception exception)
         {
             WebServiceData.LogManager.LogError(context, exception);
             throw;
         }
     }
 }
        public void GetGridCellSpeciesCountsTest()
        {
            WebCoordinateSystem coordinateSystem;

            coordinateSystem    = new WebCoordinateSystem();
            coordinateSystem.Id = CoordinateSystemId.GoogleMercator;

            WebSpeciesObservationSearchCriteria searchCriteria = new WebSpeciesObservationSearchCriteria();

            SetDefaultSearchCriteria(searchCriteria);
            searchCriteria.TaxonIds.Add(Convert.ToInt32(TaxonId.Grasshoppers));
            WebGridSpecification webGridSpecification = new WebGridSpecification();

            webGridSpecification.GridCoordinateSystem    = GridCoordinateSystem.Rt90_25_gon_v;
            webGridSpecification.GridCellSize            = 5000;
            webGridSpecification.IsGridCellSizeSpecified = true;
            webGridSpecification.GridCellGeometryType    = GridCellGeometryType.Polygon;

            IList <WebGridCellSpeciesCount> noOfGridCellObservations = WebServiceProxy.AnalysisService.GetGridSpeciesCounts(GetClientInformation(), searchCriteria, webGridSpecification, coordinateSystem);

            Assert.IsTrue(noOfGridCellObservations.Count > 0);
            Assert.IsTrue(noOfGridCellObservations[0].CentreCoordinate.X.IsNotNull());
            Assert.IsTrue(noOfGridCellObservations[0].CentreCoordinate.Y.IsNotNull());
            Assert.IsTrue(noOfGridCellObservations[0].Size == 5000);
            //Assert.IsTrue(noOfGridCellObservations[0].GridCoordinateSystem.ToString().Equals(GridCoordinateSystem.RT90.ToString()));
            Assert.IsTrue(noOfGridCellObservations[0].GridCoordinateSystem.ToString().Equals(GridCoordinateSystem.Rt90_25_gon_v.ToString()));
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[0].X.IsNotNull());
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[2].X.IsNotNull());
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[0].Y.IsNotNull());
            Assert.IsTrue(noOfGridCellObservations[0].BoundingBox.LinearRings[0].Points[2].Y.IsNotNull());
            Assert.IsTrue(noOfGridCellObservations[0].SpeciesObservationCount > 0);
            Assert.IsTrue(noOfGridCellObservations[0].SpeciesCount > 0);
            Assert.IsTrue(noOfGridCellObservations[0].SpeciesObservationCount >= noOfGridCellObservations[0].SpeciesCount);
        }
        /// <summary>
        /// This method get species (Taxa of category species) and observations per grid cell that matches
        /// species observation search criteria, grid cell specifications and specified coordinate
        /// system to getting results in.
        /// </summary>
        /// <param name="clientInformation">Information about the client that makes this web service call.</param>
        /// <param name="searchCriteria">Species observation search criteria - defined in class WebSpeciesObservationSearchCriteria.</param>
        /// <param name="gridSpecification">Grid specifications i.e settings for result grid. These settings are defined in class
        /// WebGridSpecifications. Note! GridCellSize and GridCoordinateSystem classes are the
        /// only properties that is used in this method. If Bounding Box is set then WebSpeciesObservationSearchCriteria property
        /// BoundingBox is override with WebGridSpecifications property BoundingBox.</param>
        /// <param name="coordinateSystem">Coordinate systen whch is used for performing grid caluculations defined in
        /// WebCoordinateSystem</param>
        /// <returns> A list of grid cells is returned that matches. Grid cell results is presented in WebGridCellSpeciesCount class showing number of species, no of observations.</returns>
        public List <WebGridCellSpeciesCount> GetGridSpeciesCountsBySpeciesObservationSearchCriteria(
            WebClientInformation clientInformation,
            WebSpeciesObservationSearchCriteria searchCriteria,
            WebGridSpecification gridSpecification,
            WebCoordinateSystem coordinateSystem)
        {
            List <WebGridCellSpeciesCount> grid;

            using (WebServiceContext context = GetWebServiceContext(clientInformation))
            {
                try
                {
                    if (SpeciesObservationConfiguration.IsElasticsearchUsed)
                    {
                        grid = AnalysisManager.GetGridSpeciesCountsElasticsearch(context, searchCriteria, gridSpecification, coordinateSystem);
                    }
                    else
                    {
                        grid = AnalysisManager.GetGridSpeciesCounts(context, searchCriteria, gridSpecification, coordinateSystem);
                    }

                    LogSpeciesObservationCount(grid);
                    return(grid);
                }
                catch (Exception exception)
                {
                    WebServiceData.LogManager.LogError(context, exception);
                    throw;
                }
            }
        }
Example #16
0
        /// <summary>
        /// Get number of species observations that matches
        /// provided species observation search criteria.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="searchCriteria">Species observation search criteria.</param>
        /// <param name="coordinateSystem">Coordinate system used in geometry search criteria.</param>
        /// <returns>
        /// Number of species observations that matches
        /// provided species observation search criteria.
        /// </returns>
        public Int64 GetSpeciesObservationCountBySearchCriteriaElasticsearch(WebServiceContext context,
                                                                             WebSpeciesObservationSearchCriteria searchCriteria,
                                                                             WebCoordinateSystem coordinateSystem)
        {
            DocumentCountResponse speciesObservationCountResponse;
            StringBuilder         filter;

            // Check users access rights.
            WebServiceData.AuthorizationManager.CheckAuthorization(context, AuthorityIdentifier.Sighting);

            // Check that data is valid.
            CheckData(context, searchCriteria, coordinateSystem);

            // Get species observation filter.
            filter = new StringBuilder();
            filter.Append("{");
            filter.Append(searchCriteria.GetFilter(context, false));
            filter.Append("}");

            // Get species observation count.
            using (ElasticsearchSpeciesObservationProxy elastisearch = WebServiceData.DatabaseManager.GetElastisearchSpeciesObservationProxy())
            {
                speciesObservationCountResponse = elastisearch.GetSpeciesObservationCount(filter.ToString());
            }

            return(speciesObservationCountResponse.DocumentCount);
        }
        /// <summary>
        /// Load data into the WebGridCellSpeciesCount instance.
        /// </summary>
        /// <param name="gridCellObservationCount"> Information on species counts.</param>
        /// <param name="uniqueValue">A KeyValuePair with coordinate and count information</param>
        /// <param name="gridSpecification">The grid specification: bounding box, grid cell size, etc.</param>
        /// <param name="coordinateSystem"></param>
        public static void LoadData(this WebGridCellSpeciesCount gridCellObservationCount,
                                    KeyValuePair <string, long> uniqueValue,
                                    WebGridSpecification gridSpecification,
                                    WebCoordinateSystem coordinateSystem)
        {
            if (gridCellObservationCount != null)
            {
                // Returning int 32, no problem for gridcells.
                gridCellObservationCount.SpeciesObservationCount = uniqueValue.Value;
                gridCellObservationCount.GridCoordinateSystem    = gridSpecification.GridCoordinateSystem;
                gridCellObservationCount.CoordinateSystem        = coordinateSystem;
                gridCellObservationCount.Size = gridSpecification.GridCellSize;

                // Calculate grid points
                double centreCoordinateX = uniqueValue.Key.Split(':')[0].WebParseDouble();
                double centreCoordinateY = uniqueValue.Key.Split(':')[1].WebParseDouble();
                //TODO Create method:
                double halfGridSize = gridCellObservationCount.Size / 2.0;

                double upperCoordinateY = centreCoordinateY + halfGridSize;
                double upperCoordinateX = centreCoordinateX + halfGridSize;
                double lowerCoordinateY = centreCoordinateY - halfGridSize;
                double lowerCoordinateX = centreCoordinateX - halfGridSize;

                // Create Point and BoundingBox
                WebPoint centrePoint = new WebPoint(centreCoordinateX, centreCoordinateY);

                WebPoint pointMax = new WebPoint(upperCoordinateX, upperCoordinateY);
                WebPoint pointMin = new WebPoint(lowerCoordinateX, lowerCoordinateY);

                gridCellObservationCount.CentreCoordinate        = centrePoint;
                gridCellObservationCount.OrginalCentreCoordinate = centrePoint;
                //gridCellObservationCount.GridCellBoundingBox = new WebBoundingBox() { Max = pointMax, Min = pointMin };
                gridCellObservationCount.BoundingBox             = new WebPolygon();
                gridCellObservationCount.BoundingBox.LinearRings = new List <WebLinearRing>();
                gridCellObservationCount.BoundingBox.LinearRings.Add(new WebLinearRing());
                gridCellObservationCount.BoundingBox.LinearRings[0].Points = new List <WebPoint>();
                gridCellObservationCount.BoundingBox.LinearRings[0].Points.Add(new WebPoint());
                gridCellObservationCount.BoundingBox.LinearRings[0].Points.Add(new WebPoint());
                gridCellObservationCount.BoundingBox.LinearRings[0].Points.Add(new WebPoint());
                gridCellObservationCount.BoundingBox.LinearRings[0].Points.Add(new WebPoint());
                gridCellObservationCount.BoundingBox.LinearRings[0].Points.Add(new WebPoint());
                //Create the linear ring that is the "bounding polygon".
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[0].X = pointMin.X;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[0].Y = pointMin.Y;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[1].X = pointMin.X;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[1].Y = pointMax.Y;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[2].X = pointMax.X;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[2].Y = pointMax.Y;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[3].X = pointMax.X;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[3].Y = pointMin.Y;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[4].X = pointMin.X;
                gridCellObservationCount.BoundingBox.LinearRings[0].Points[4].Y = pointMin.Y;

                gridCellObservationCount.OrginalBoundingBox = new WebBoundingBox {
                    Max = pointMax, Min = pointMin
                };
            }
        }
 public WebCoordinateSystem GetCoordinateSystem(Boolean refresh)
 {
     if (_coordinateSystem.IsNull() || refresh)
     {
         _coordinateSystem = new WebCoordinateSystem();
     }
     return(_coordinateSystem);
 }
Example #19
0
 /// <summary>
 /// Get geography for regions.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="GUIDs">Region GUIDs.</param>
 /// <param name="coordinateSystem">Coordinate system used in returned geography information.</param>
 /// <returns>Geography for regions.</returns>
 public List <WebRegionGeography> GetRegionsGeographyByGUIDs(WebClientInformation clientInformation,
                                                             List <String> GUIDs,
                                                             WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 2))
     {
         return(client.Client.GetRegionsGeographyByGUIDs(clientInformation, GUIDs, coordinateSystem));
     }
 }
 /// <summary>
 /// Get species observation provenances
 /// that matches the search criteria.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="searchCriteria">Species observation search criteria - defined in class WebSpeciesObservationSearchCriteria.</param>
 /// <param name="coordinateSystem">Coordinate system used in search criteria.</param>
 /// <returns>Number of species that matches the search criteria.</returns>
 public List <WebSpeciesObservationProvenance> GetProvenancesBySearchCriteria(WebClientInformation clientInformation,
                                                                              WebSpeciesObservationSearchCriteria searchCriteria,
                                                                              WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 5))
     {
         return(client.Client.GetSpeciesObservationProvenancesBySearchCriteria(clientInformation, searchCriteria, coordinateSystem));
     }
 }
 /// <summary>
 /// Gets number of species observations
 /// that matches the search criteria.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="searchCriteria">The species observation search criteria.</param>
 /// <param name="coordinateSystem">Coordinate system used in geometry search criteria.
 /// </param>
 /// <returns>No of species observations that matches the search criteria.</returns>
 public Int64 GetSpeciesObservationCountBySearchCriteria(WebClientInformation clientInformation,
                                                         WebSpeciesObservationSearchCriteria searchCriteria,
                                                         WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 5))
     {
         return(client.Client.GetSpeciesObservationCountBySearchCriteria(clientInformation, searchCriteria, coordinateSystem));
     }
 }
 /// <summary>
 /// Test if specified geometries contains any conservation relevant
 /// species observations.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="searchCriteria">
 /// Species observation search criteria including at least one
 /// polygon, bounding box or region.
 /// </param>
 /// <param name="coordinateSystem">Coordinate system used in geometry search criterias.</param>
 /// <returns>True if specified geometries contains conservation relevant species observations.</returns>
 public Boolean HasConservationSpeciesObservation(WebClientInformation clientInformation,
                                                  WebSpeciesObservationSearchCriteria searchCriteria,
                                                  WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 5))
     {
         return(client.Client.HasConservationSpeciesObservation(clientInformation, searchCriteria, coordinateSystem));
     }
 }
 /// <summary>
 /// Get an indication if specified geometries contains any
 /// protected species observations.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="searchCriteria">
 /// The species observation search criteria.
 /// At least one of BoundingBox, Polygons and RegionGuids
 /// must be specified.
 /// Search criterias that may be used: Accuracy,
 /// BirdNestActivityLimit, BoundingBox, IsAccuracyConsidered,
 /// IsDisturbanceSensitivityConsidered, MinProtectionLevel,
 /// ObservationDateTime, Polygons and RegionGuids.
 /// </param>
 /// <param name="coordinateSystem">Coordinate system used in geometry search criterias.</param>
 /// <returns>
 /// True, if specified geometries contains any
 /// protected species observations.
 /// </returns>
 public Boolean GetProtectedSpeciesObservationIndication(WebClientInformation clientInformation,
                                                         WebSpeciesObservationSearchCriteria searchCriteria,
                                                         WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 20))
     {
         return(client.Client.GetProtectedSpeciesObservationIndication(clientInformation, searchCriteria, coordinateSystem));
     }
 }
Example #24
0
 /// <summary>
 /// Get cities that matches the search criteria.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="searchCriteria">City search criteria.</param>
 /// <param name="coordinateSystem">Coordinate system used in returned geography information.</param>
 /// <returns>Regions that matches the search criterias.</returns>
 public List <WebCityInformation> GetCitiesByNameSearchString(WebClientInformation clientInformation,
                                                              WebStringSearchCriteria searchCriteria,
                                                              WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 1))
     {
         return(client.Client.GetCitiesByNameSearchString(clientInformation, searchCriteria, coordinateSystem));
     }
 }
 /// <summary>
 /// Get requested species observations.
 /// Scope is restricted to those observations
 /// that the user has access rights to.
 /// Max 25000 observations can be retrieved in one call.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="speciesObservationIds">Id for species observations to get.</param>
 /// <param name="coordinateSystem">
 /// Coordinate system used in returned species observations.
 /// </param>
 /// <returns>Species observations.</returns>
 public WebDarwinCoreInformation GetDarwinCoreByIds(WebClientInformation clientInformation,
                                                    List <Int64> speciesObservationIds,
                                                    WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 5))
     {
         return(client.Client.GetDarwinCoreByIds(clientInformation, speciesObservationIds, coordinateSystem));
     }
 }
Example #26
0
 /// <summary>
 /// Get geography for regions.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="regionIds">Region ids.</param>
 /// <param name="coordinateSystem">Coordinate system used in returned geography information.</param>
 /// <returns>Geography for regions.</returns>
 public List <WebRegionGeography> GetRegionsGeographyByIds(WebClientInformation clientInformation,
                                                           List <Int32> regionIds,
                                                           WebCoordinateSystem coordinateSystem)
 {
     using (ClientProxy client = new ClientProxy(this, 2))
     {
         return(client.Client.GetRegionsGeographyByIds(clientInformation, regionIds, coordinateSystem));
     }
 }
 /// <summary>
 /// Get region geography cache key.
 /// </summary>
 /// <param name="regionUniqueString">String that is unique for a region.</param>
 /// <param name="coordinateSystem">Coordinate system used in returned geography information.</param>
 /// <returns>Region geography cache key.</returns>
 private String GetRegionGeographyCacheKey(String regionUniqueString,
                                           WebCoordinateSystem coordinateSystem)
 {
     return(Settings.Default.RegionGeographyCacheKey +
            Settings.Default.CacheKeyDelimiter +
            regionUniqueString +
            Settings.Default.CacheKeyDelimiter +
            coordinateSystem.GetWkt());
 }
 private WebCoordinateSystem GetCoordinateSystem()
 {
     if (_coordinateSystem.IsNull())
     {
         _coordinateSystem    = new WebCoordinateSystem();
         _coordinateSystem.Id = CoordinateSystemId.Rt90_25_gon_v;
     }
     return(_coordinateSystem);
 }
 /// <summary>
 /// Get information about species observations paged
 /// that matches the search criteria.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="searchCriteria">The species observation search criteria.</param>
 /// <param name="coordinateSystem">
 /// Coordinate system used in geometry search criterias
 /// and returned species observations.
 /// </param>
 /// <param name="pageSpecification"></param>
 /// <returns>Information about requested species observations.</returns>
 public List <WebDarwinCore> GetDarwinCoreBySearchCriteriaPage(WebClientInformation clientInformation,
                                                               WebSpeciesObservationSearchCriteria searchCriteria,
                                                               WebCoordinateSystem coordinateSystem,
                                                               WebSpeciesObservationPageSpecification pageSpecification)
 {
     using (ClientProxy client = new ClientProxy(this, 20))
     {
         return(client.Client.GetDarwinCoreBySearchCriteriaPage(clientInformation, searchCriteria, coordinateSystem, pageSpecification));
     }
 }
 /// <summary>
 /// Get requested species observations.
 /// Scope is restricted to those observations
 /// that the user has access rights to.
 /// Species observations are returned in a format
 /// that is compatible with Darwin Core 1.5.
 /// Max 25000 observations with information
 /// can be retrieved in one call.
 /// </summary>
 /// <param name="clientInformation">Information about the client that makes this web service call.</param>
 /// <param name="speciesObservationIds">Id for species observations to get.</param>
 /// <param name="coordinateSystem">
 /// Coordinate system used in returned species observations.
 /// </param>
 /// <param name="speciesObservationSpecification">
 /// Specify which subset of the data that should be
 /// returned for each species observation.
 /// All information for each species observation is
 /// returned if this parameter is null.
 /// This parameter is currently not used.
 /// </param>
 /// <returns>Species observations.</returns>
 public WebSpeciesObservationInformation GetSpeciesObservationsByIds(WebClientInformation clientInformation,
                                                                     List <Int64> speciesObservationIds,
                                                                     WebCoordinateSystem coordinateSystem,
                                                                     WebSpeciesObservationSpecification speciesObservationSpecification)
 {
     using (ClientProxy client = new ClientProxy(this, 5))
     {
         return(client.Client.GetSpeciesObservationsByIds(clientInformation, speciesObservationIds, coordinateSystem, speciesObservationSpecification));
     }
 }