/// <summary> /// Convert a WebBoundingBox instance into a WebPolygon /// instance with same geographic area. /// </summary> /// <param name="boundingBox">Bounding box.</param> /// <returns>A WebPolygon instance.</returns> public static WebPolygon GetPolygon(this WebBoundingBox boundingBox) { WebLinearRing linearRing; WebPolygon polygon; linearRing = new WebLinearRing(); linearRing.Points = new List <WebPoint>(); linearRing.Points.Add(new WebPoint(boundingBox.Min.X, boundingBox.Min.Y)); linearRing.Points.Add(new WebPoint(boundingBox.Max.X, boundingBox.Min.Y)); linearRing.Points.Add(new WebPoint(boundingBox.Max.X, boundingBox.Max.Y)); linearRing.Points.Add(new WebPoint(boundingBox.Min.X, boundingBox.Max.Y)); linearRing.Points.Add(new WebPoint(boundingBox.Min.X, boundingBox.Min.Y)); polygon = new WebPolygon(); polygon.LinearRings = new List <WebLinearRing>(); polygon.LinearRings.Add(linearRing); return(polygon); }
public void GetGeometry() { SqlGeometry polygonGeometry; WebLinearRing linearRing; WebPolygon polygon; linearRing = new WebLinearRing(); linearRing.Points = new List <WebPoint>(); linearRing.Points.Add(new WebPoint(2, 2)); linearRing.Points.Add(new WebPoint(4, 1)); linearRing.Points.Add(new WebPoint(5, 4)); linearRing.Points.Add(new WebPoint(2, 2)); polygon = new WebPolygon(); polygon.LinearRings = new List <WebLinearRing>(); polygon.LinearRings.Add(linearRing); polygonGeometry = polygon.GetGeometry(); Assert.IsNotNull(polygonGeometry); }
/// <summary> /// Check that data is valid. /// </summary> /// <param name="linearRing">The linear ring.</param> public static void CheckData(this WebLinearRing linearRing) { if (linearRing.IsNotNull()) { linearRing.Points.CheckNotEmpty("Points"); foreach (WebPoint point in linearRing.Points) { point.CheckData(); } if (linearRing.Points.Count < 3) { throw new ArgumentException("A linear ring must contain at least 3 points."); } if (!linearRing.Points[0].Equal(linearRing.Points[linearRing.Points.Count - 1])) { throw new ArgumentException("First and last point of a linear ring must be the same."); } } }
/// <summary> /// Convert a ILinearRing instance to a WebLinearRing instance. /// </summary> /// <param name="linearRing">An ILinearRing instance.</param> /// <returns>A WebLinearRing instance.</returns> protected WebLinearRing GetLinearRing(ILinearRing linearRing) { WebLinearRing webLinearRing; webLinearRing = null; if (linearRing.IsNotNull()) { webLinearRing = new WebLinearRing(); if (linearRing.Points.IsNotEmpty()) { webLinearRing.Points = new List <WebPoint>(); foreach (Point point in linearRing.Points) { webLinearRing.Points.Add(GetPoint(point)); } } } return(webLinearRing); }
/// <summary> /// Convert a ILinearRing instance to a WebLinearRing instance. /// </summary> /// <param name="linearRing">An ILinearRing instance.</param> /// <returns>A WebLinearRing instance.</returns> public static WebLinearRing ToWebLinearRing(this ILinearRing linearRing) { WebLinearRing webLinearRing; webLinearRing = null; if (linearRing.IsNotNull()) { webLinearRing = new WebLinearRing(); if (linearRing.Points.IsNotEmpty()) { webLinearRing.Points = new List <WebPoint>(); foreach (IPoint point in linearRing.Points) { webLinearRing.Points.Add(ToWebPoint(point)); } } } return(webLinearRing); }
public void GetBoundingBox() { WebBoundingBox boundingBox; WebLinearRing linearRing; WebPolygon polygon; linearRing = new WebLinearRing(); linearRing.Points = new List <WebPoint>(); linearRing.Points.Add(new WebPoint(2, 2)); linearRing.Points.Add(new WebPoint(4, 1)); linearRing.Points.Add(new WebPoint(5, 4)); linearRing.Points.Add(new WebPoint(2, 2)); polygon = new WebPolygon(); polygon.LinearRings = new List <WebLinearRing>(); polygon.LinearRings.Add(linearRing); boundingBox = polygon.GetBoundingBox(); Assert.IsNotNull(boundingBox); Assert.AreEqual(2, boundingBox.Min.X); Assert.AreEqual(5, boundingBox.Max.X); Assert.AreEqual(1, boundingBox.Min.Y); Assert.AreEqual(4, boundingBox.Max.Y); }
public void GetDarwinCoreBySearchCriteria() { WebBirdNestActivity birdNestActivity; WebCoordinateSystem coordinateSystem, wgsCoordinateSystem; WebDarwinCoreInformation information1, information2; WebLinearRing linearRing; WebPolygon polygon; WebSpeciesObservationSearchCriteria searchCriteria; coordinateSystem = new WebCoordinateSystem(); coordinateSystem.Id = CoordinateSystemId.Rt90_25_gon_v; // Test search criteria Accuracy. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.IncludePositiveObservations = true; searchCriteria.IsAccuracySpecified = true; searchCriteria.Accuracy = 111; information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.IsTrue(Double.Parse(darwinCore.Location.CoordinateUncertaintyInMeters) <= searchCriteria.Accuracy); } searchCriteria.Accuracy = 59; information2 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information2); Assert.IsTrue(information2.SpeciesObservationCount < information1.SpeciesObservationCount); foreach (WebDarwinCore darwinCore in information2.SpeciesObservations) { Assert.IsTrue(Double.Parse(darwinCore.Location.CoordinateUncertaintyInMeters) <= searchCriteria.Accuracy); } // Test search criteria BoundingBox. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.IncludePositiveObservations = true; searchCriteria.BoundingBox = new WebBoundingBox(); searchCriteria.BoundingBox.Max = new WebPoint(1645000, 6681000); searchCriteria.BoundingBox.Min = new WebPoint(1308000, 6222000); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.IsTrue(darwinCore.Location.CoordinateX <= searchCriteria.BoundingBox.Max.X); Assert.IsTrue(darwinCore.Location.CoordinateX >= searchCriteria.BoundingBox.Min.X); Assert.IsTrue(darwinCore.Location.CoordinateY <= searchCriteria.BoundingBox.Max.Y); Assert.IsTrue(darwinCore.Location.CoordinateY >= searchCriteria.BoundingBox.Min.Y); } searchCriteria.BoundingBox.Max = new WebPoint(1500000, 6500000); searchCriteria.BoundingBox.Min = new WebPoint(1400000, 6300000); information2 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information2); Assert.IsTrue(information2.SpeciesObservationCount < information1.SpeciesObservationCount); foreach (WebDarwinCore darwinCore in information2.SpeciesObservations) { Assert.IsTrue(darwinCore.Location.CoordinateX <= searchCriteria.BoundingBox.Max.X); Assert.IsTrue(darwinCore.Location.CoordinateX >= searchCriteria.BoundingBox.Min.X); Assert.IsTrue(darwinCore.Location.CoordinateY <= searchCriteria.BoundingBox.Max.Y); Assert.IsTrue(darwinCore.Location.CoordinateY >= searchCriteria.BoundingBox.Min.Y); } // Test error with coordinate conversion. searchCriteria.BoundingBox.Max = new WebPoint(17.7, 60.0); searchCriteria.BoundingBox.Min = new WebPoint(17.6, 59.9); wgsCoordinateSystem = new WebCoordinateSystem(); wgsCoordinateSystem.Id = CoordinateSystemId.WGS84; information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, wgsCoordinateSystem); CheckDarwinCoreInformation(information1); // Test search criteria ChangeDateTime. // Test search criteria DataFieldSearchCriteria. // Test search criteria DataSourceIds. // Test search criteria IncludeNeverFoundObservations. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.IncludeNeverFoundObservations = true; information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.IsTrue(darwinCore.Occurrence.IsNeverFoundObservation); } // Test search criteria IncludeNotRediscoveredObservations. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.IncludeNotRediscoveredObservations = true; information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.IsTrue(darwinCore.Occurrence.IsNotRediscoveredObservation); } // Test search criteria IncludePositiveObservations. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.IncludePositiveObservations = true; information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.IsTrue(darwinCore.Occurrence.IsPositiveObservation); } // Test search criteria IncludeRedListCategories. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludeNotRediscoveredObservations = true; searchCriteria.IncludeRedListCategories = new List <RedListCategory>(); searchCriteria.IncludeRedListCategories.Add(RedListCategory.CR); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { // The check for not empty red list category should not be // necessary but data on test server is not up to date. // This test has a problem with taxon 232265 that // is redlisted as VU since its parent taxon is // red listed as NT. if (darwinCore.Conservation.RedlistCategory.IsNotEmpty() && (Int32.Parse(darwinCore.Taxon.TaxonID) != 232265)) { Assert.AreEqual(searchCriteria.IncludeRedListCategories[0].ToString(), darwinCore.Conservation.RedlistCategory.Substring(0, 2).ToUpper()); } } // Test search criteria IncludeRedlistedTaxa. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.Accuracy = 3; searchCriteria.IsAccuracySpecified = true; searchCriteria.IncludeNotRediscoveredObservations = true; searchCriteria.IncludeRedlistedTaxa = true; information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); Assert.IsTrue(information1.SpeciesObservations.IsNotEmpty()); // Test search criteria LocalityNameSearchString. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludePositiveObservations = true; searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.LocalityNameSearchString = new WebStringSearchCriteria(); searchCriteria.LocalityNameSearchString.CompareOperators = new List <StringCompareOperator>(); searchCriteria.LocalityNameSearchString.CompareOperators.Add(StringCompareOperator.Like); searchCriteria.LocalityNameSearchString.SearchString = "Fullerö%"; information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.AreEqual(searchCriteria.LocalityNameSearchString.SearchString.Substring(0, 7).ToUpper(), darwinCore.Location.Locality.Substring(0, 7).ToUpper()); } // Test search criteria ObservationDateTime. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludePositiveObservations = true; searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.ObservationDateTime = new WebDateTimeSearchCriteria(); searchCriteria.ObservationDateTime.Begin = new DateTime(2009, 8, 1); searchCriteria.ObservationDateTime.End = new DateTime(2009, 8, 31); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.IsTrue(searchCriteria.ObservationDateTime.Begin <= darwinCore.Event.Start); Assert.IsTrue(searchCriteria.ObservationDateTime.End >= darwinCore.Event.Start); } searchCriteria.ObservationDateTime.PartOfYear = new List <WebDateTimeInterval>(); searchCriteria.ObservationDateTime.PartOfYear.Add(new WebDateTimeInterval()); searchCriteria.ObservationDateTime.PartOfYear[0].Begin = new DateTime(2009, 8, 1); searchCriteria.ObservationDateTime.PartOfYear[0].End = new DateTime(2009, 8, 31); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.AreEqual(searchCriteria.ObservationDateTime.PartOfYear[0].Begin.Month, darwinCore.Event.Start.Month); Assert.IsTrue(searchCriteria.ObservationDateTime.PartOfYear[0].Begin.Day <= darwinCore.Event.Start.Day); Assert.IsTrue(searchCriteria.ObservationDateTime.PartOfYear[0].End.Day >= darwinCore.Event.Start.Day); } // Test search criteria ObserverIds. // Test search criteria Polygons. linearRing = new WebLinearRing(); linearRing.Points = new List <WebPoint>(); linearRing.Points.Add(new WebPoint(1500000, 6500000)); linearRing.Points.Add(new WebPoint(1800000, 6500000)); linearRing.Points.Add(new WebPoint(1800000, 6800000)); linearRing.Points.Add(new WebPoint(1500000, 6500000)); polygon = new WebPolygon(); polygon.LinearRings = new List <WebLinearRing>(); polygon.LinearRings.Add(linearRing); searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludePositiveObservations = true; searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.Polygons = new List <WebPolygon>(); searchCriteria.Polygons.Add(polygon); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); Assert.IsTrue(information1.SpeciesObservations.IsNotEmpty()); linearRing = new WebLinearRing(); linearRing.Points = new List <WebPoint>(); linearRing.Points.Add(new WebPoint(1300000, 6100000)); linearRing.Points.Add(new WebPoint(1600000, 6100000)); linearRing.Points.Add(new WebPoint(1600000, 6300000)); linearRing.Points.Add(new WebPoint(1300000, 6100000)); polygon = new WebPolygon(); polygon.LinearRings = new List <WebLinearRing>(); polygon.LinearRings.Add(linearRing); searchCriteria.Polygons.Add(polygon); information2 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information2); Assert.IsTrue(information2.SpeciesObservations.IsNotEmpty()); Assert.IsTrue(information1.SpeciesObservationCount < information2.SpeciesObservationCount); // Test search criteria ProjectIds. // Test search criteria RegionIds. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludePositiveObservations = true; searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add((Int32)(TaxonId.DrumGrasshopper)); searchCriteria.TaxonIds.Add((Int32)(TaxonId.Hedgehog)); searchCriteria.RegionGuids = new List <String>(); searchCriteria.RegionGuids.Add(Settings.Default.UpplandGuid); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); Assert.IsTrue(information1.SpeciesObservations.IsNotEmpty()); searchCriteria.RegionGuids.Add(Settings.Default.BlekingeGUID); information2 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information2); Assert.IsTrue(information2.SpeciesObservations.IsNotEmpty()); Assert.IsTrue(information1.SpeciesObservationCount < information2.SpeciesObservationCount); searchCriteria.RegionGuids = new List <String>(); searchCriteria.RegionGuids.Add(Settings.Default.VastmanlandCountyGuid); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); Assert.IsTrue(information1.SpeciesObservations.IsNotEmpty()); // Test search criteria RegionLogicalOperator. // Test search criteria RegistrationDateTime. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludePositiveObservations = true; searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); searchCriteria.RegistrationDateTime = new WebDateTimeSearchCriteria(); searchCriteria.RegistrationDateTime.Begin = new DateTime(2009, 8, 1); searchCriteria.RegistrationDateTime.End = new DateTime(2009, 8, 31); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); searchCriteria.RegistrationDateTime.PartOfYear = new List <WebDateTimeInterval>(); searchCriteria.RegistrationDateTime.PartOfYear.Add(new WebDateTimeInterval()); searchCriteria.RegistrationDateTime.PartOfYear[0].Begin = new DateTime(2009, 8, 1); searchCriteria.RegistrationDateTime.PartOfYear[0].End = new DateTime(2009, 8, 31); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); // Test search criteria SpeciesActivityIds. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludePositiveObservations = true; searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.TwiteId); searchCriteria.SpeciesActivityIds = new List <Int32>(); birdNestActivity = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetBirdNestActivities(GetClientInformation())[0]; searchCriteria.SpeciesActivityIds.Add(birdNestActivity.Id); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { if (darwinCore.DatasetName == "Fåglar") { Assert.AreEqual(birdNestActivity.Name, darwinCore.Occurrence.Behavior); } } // Test search criteria TaxonIds. searchCriteria = new WebSpeciesObservationSearchCriteria(); searchCriteria.IncludePositiveObservations = true; searchCriteria.TaxonIds = new List <Int32>(); searchCriteria.TaxonIds.Add(Settings.Default.DrumGrasshopperId); information1 = WebServiceProxy.SwedishSpeciesObservationSOAPService.GetDarwinCoreBySearchCriteria(GetClientInformation(), searchCriteria, coordinateSystem); CheckDarwinCoreInformation(information1); foreach (WebDarwinCore darwinCore in information1.SpeciesObservations) { Assert.AreEqual(Settings.Default.DrumGrasshopperId, Int32.Parse(darwinCore.Taxon.TaxonID)); } // Test search criteria TaxonValidationStatusIds. }
/// <summary> /// Cast web linearring to linearring /// </summary> /// <param name="webLinearRing"></param> /// <returns></returns> public static ILinearRing ToLinearRing(this WebLinearRing webLinearRing) { return(new LinearRing((from p in webLinearRing.Points select p.ToCoordinate()).ToArray())); }