/// <summary>
        /// Converts to data polygon.
        /// </summary>
        /// <param name="polygon">The polygon to convert.</param>
        /// <returns>Converted DataPolygon.</returns>
        private static DataPolygon ConvertToDataPolygon(IPolygon polygon)
        {
            DataPolygon dataPolygon = new DataPolygon();

            dataPolygon.LinearRings = new List <DataLinearRing>();
            if (polygon.LinearRings == null)
            {
                return(dataPolygon);
            }

            foreach (ILinearRing linearRing in polygon.LinearRings)
            {
                if (linearRing.Points == null || linearRing.Points.Count == 0)
                {
                    continue;
                }

                DataLinearRing dataLinearRing = new DataLinearRing();
                dataLinearRing.Points = new List <DataPoint>();
                foreach (IPoint point in linearRing.Points)
                {
                    var dataPoint = new DataPoint(point.X, point.Y, point.Z);
                    dataLinearRing.Points.Add(dataPoint);
                }

                dataPolygon.LinearRings.Add(dataLinearRing);
            }

            return(dataPolygon);
        }
        /// <summary>
        /// Converts a GeoJSON FeatureCollection to a list with data polygons.
        /// </summary>
        /// <param name="featureCollection">The GeoJSON FeatureCollection.</param>
        /// <returns>Converted polygons.</returns>
        public static List <DataPolygon> ConvertToDataPolygons(FeatureCollection featureCollection)
        {
            var dataPolygons = new List <DataPolygon>();

            if (featureCollection.IsNull())
            {
                return(dataPolygons);
            }

            foreach (Feature feature in featureCollection.Features)
            {
                ////if (feature.Type == GeoJSONObjectType.Polygon)
                if (feature.Geometry != null && feature.Geometry.GetType() == typeof(ArtDatabanken.GIS.GeoJSON.Net.Geometry.Polygon))
                {
                    ArtDatabanken.GIS.GeoJSON.Net.Geometry.Polygon polygon = (ArtDatabanken.GIS.GeoJSON.Net.Geometry.Polygon)feature.Geometry;
                    DataPolygon dataPolygon = ConvertToDataPolygon(polygon);
                    dataPolygons.Add(dataPolygon);
                }
                else if (feature.Geometry != null && feature.Geometry.GetType() == typeof(ArtDatabanken.GIS.GeoJSON.Net.Geometry.MultiPolygon))
                {
                    ArtDatabanken.GIS.GeoJSON.Net.Geometry.MultiPolygon multiPolygon = (ArtDatabanken.GIS.GeoJSON.Net.Geometry.MultiPolygon)feature.Geometry;
                    foreach (ArtDatabanken.GIS.GeoJSON.Net.Geometry.Polygon polygon in multiPolygon.Coordinates)
                    {
                        DataPolygon dataPolygon = ConvertToDataPolygon(polygon);
                        dataPolygons.Add(dataPolygon);
                    }
                }
            }

            return(dataPolygons);
        }
        public void DataPolygon_Equality()
        {
            DataLinearRing dataLinearRing1 = new DataLinearRing();

            dataLinearRing1.Points = new List <DataPoint>();
            dataLinearRing1.Points.Add(new DataPoint(1.0, 2.0, null));
            dataLinearRing1.Points.Add(new DataPoint(2.0, 3.0, null));
            dataLinearRing1.Points.Add(new DataPoint(3.0, 4.0, null));

            DataLinearRing dataLinearRing2 = new DataLinearRing();

            dataLinearRing2.Points = new List <DataPoint>();
            dataLinearRing2.Points.Add(new DataPoint(1.0, 2.0, null));
            dataLinearRing2.Points.Add(new DataPoint(2.0, 3.0, null));
            dataLinearRing2.Points.Add(new DataPoint(3.0, 4.0, null));

            DataPolygon dataPolygon1 = new DataPolygon();

            dataPolygon1.LinearRings = new List <DataLinearRing>();
            dataPolygon1.LinearRings.Add(dataLinearRing1);

            DataPolygon dataPolygon2 = new DataPolygon();

            dataPolygon2.LinearRings = new List <DataLinearRing>();
            dataPolygon2.LinearRings.Add(dataLinearRing2);

            Assert.AreEqual(dataPolygon1, dataPolygon2);
            Assert.AreEqual(dataPolygon1.GetHashCode(), dataPolygon2.GetHashCode());


            dataLinearRing2.Points.RemoveAt(2);
            Assert.AreNotEqual(dataPolygon1, dataPolygon2);
            Assert.AreNotEqual(dataPolygon1.GetHashCode(), dataPolygon2.GetHashCode());


            dataLinearRing2.Points.Add(new DataPoint(3.0, 4.0, null));
            Assert.AreEqual(dataPolygon1, dataPolygon2);
            Assert.AreEqual(dataPolygon1.GetHashCode(), dataPolygon2.GetHashCode());

            DataLinearRing dataLinearRing3 = new DataLinearRing();

            dataLinearRing3.Points = new List <DataPoint>();
            dataLinearRing3.Points.Add(new DataPoint(1.0, 2.0, null));
            dataLinearRing3.Points.Add(new DataPoint(2.0, 5.0, null));
            dataLinearRing3.Points.Add(new DataPoint(3.0, 4.0, null));
            DataPolygon dataPolygon3 = new DataPolygon();

            dataPolygon3.LinearRings = new List <DataLinearRing>();
            dataPolygon3.LinearRings.Add(dataLinearRing3);


            Assert.AreNotEqual(dataPolygon1, dataPolygon3);
            Assert.AreNotEqual(dataPolygon1.GetHashCode(), dataPolygon3.GetHashCode());
        }
        public void GetQueryComplexityEstimate_ObservationMapWith1TaxaWithSpatialFilter_ReturnMediumEstimate()
        {
            DataPolygon dataPolygon = CreateSampleDataPolygon();

            SessionHandler.MySettings.Filter.Taxa.AddTaxonId(1);
            SessionHandler.MySettings.Filter.Spatial.Polygons.Add(dataPolygon);
            //var result = QueryComplexityManager.GetQueryComplexityEstimate(ResultType.SpeciesObservationMap, SessionHandler.UserContext, SessionHandler.MySettings);
            SpeciesObservationResultCalculator resultCalculator = new SpeciesObservationResultCalculator(SessionHandler.UserContext, SessionHandler.MySettings);
            QueryComplexityEstimate            result           = resultCalculator.GetQueryComplexityEstimate();

            Assert.AreEqual(QueryComplexityExecutionTime.Medium, result.QueryComplexityExecutionTime);
        }
コード例 #5
0
        /// <summary>
        /// Converts a DataPolygon to Polygon.
        /// </summary>
        /// <param name="dataPolygon">The data polygon.</param>
        /// <param name="dataContext">The data context.</param>
        /// <returns></returns>
        public static Polygon ToPolygon(this DataPolygon dataPolygon, DataContext dataContext)
        {
            var polygon = new Polygon();

            polygon.LinearRings = new List <ILinearRing>();

            foreach (DataLinearRing dataLinearRing in dataPolygon.LinearRings)
            {
                LinearRing linearRing = dataLinearRing.ToLinearRing(dataContext);
                polygon.LinearRings.Add(linearRing);
            }

            return(polygon);
        }
        public void Add_and_remove_spatial_filter()
        {
            var     filterController = new FilterController();
            Polygon polygon1         = CreateTestPolygon1();
            Polygon polygon2         = CreateTestPolygon2();
            var     feature1         = new Feature(polygon1);
            var     feature2         = new Feature(polygon2);
            var     features         = new List <Feature> {
                feature1, feature2
            };
            var    featureCollection = new FeatureCollection(features);
            string geojson           = JsonConvert.SerializeObject(featureCollection, JsonHelper.GetDefaultJsonSerializerSettings());

            // Update spatial filter
            JsonNetResult result     = filterController.UpdateSpatialFilter(geojson);
            JsonModel     jsonResult = (JsonModel)result.Data;

            Assert.IsTrue(jsonResult.Success);
            Assert.IsTrue(SessionHandler.MySettings.Filter.Spatial.IsActive == true);
            Assert.IsTrue(SessionHandler.MySettings.Filter.Spatial.Polygons.Count == 2);

            DataPolygon dataPolygon1 = SessionHandler.MySettings.Filter.Spatial.Polygons[0];

            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[0].X - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[0]).Longitude) < 0.001);
            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[1].X - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[1]).Longitude) < 0.001);
            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[2].X - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[2]).Longitude) < 0.001);
            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[3].X - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[3]).Longitude) < 0.001);
            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[0].Y - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[0]).Latitude) < 0.001);
            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[1].Y - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[1]).Latitude) < 0.001);
            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[2].Y - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[2]).Latitude) < 0.001);
            Assert.IsTrue(Math.Abs(dataPolygon1.LinearRings[0].Points[3].Y - ((GeographicPosition)polygon1.Coordinates[0].Coordinates[3]).Latitude) < 0.001);


            // Get spatial filter
            result     = filterController.GetSpatialFilterAsGeoJSON();
            jsonResult = (JsonModel)result.Data;
            Assert.IsTrue(jsonResult.Success);
            FeatureCollection featureCollectionFromServer = (FeatureCollection)jsonResult.Data;

            Assert.IsTrue(featureCollectionFromServer.Features.Count == 2);


            // Clear spatial filter
            result     = filterController.ClearSpatialFilter();
            jsonResult = (JsonModel)result.Data;
            Assert.IsTrue(jsonResult.Success);
            Assert.IsTrue(SessionHandler.MySettings.Filter.Spatial.Polygons.Count == 0);
        }
        private DataPolygon CreateSampleDataPolygon()
        {
            DataLinearRing dataLinearRing1 = new DataLinearRing();

            dataLinearRing1.Points = new List <DataPoint>();
            dataLinearRing1.Points.Add(new DataPoint(1.0, 2.0, null));
            dataLinearRing1.Points.Add(new DataPoint(2.0, 3.0, null));
            dataLinearRing1.Points.Add(new DataPoint(3.0, 4.0, null));

            DataPolygon dataPolygon1 = new DataPolygon();

            dataPolygon1.LinearRings = new List <DataLinearRing>();
            dataPolygon1.LinearRings.Add(dataLinearRing1);

            return(dataPolygon1);
        }
        private DataPolygon GetPolygon2()
        {
            DataPolygon      polygon    = new DataPolygon();
            DataLinearRing   linearRing = new DataLinearRing();
            List <DataPoint> points     = new List <DataPoint>();

            points.Add(new DataPoint(10, 10, null));
            points.Add(new DataPoint(10, 20, null));
            points.Add(new DataPoint(20, 20, null));
            points.Add(new DataPoint(20, 10, null));
            points.Add(new DataPoint(10, 10, null));
            linearRing.Points   = points;
            polygon.LinearRings = new List <DataLinearRing>();
            polygon.LinearRings.Add(linearRing);
            return(polygon);
        }
        /// <summary>
        /// Converts a GeoJSON Polygon to a DataPolygon.
        /// </summary>
        /// <param name="polygon">The GeoJSON polygon.</param>
        /// <returns>Converted DataPolygon.</returns>
        public static DataPolygon ConvertToDataPolygon(ArtDatabanken.GIS.GeoJSON.Net.Geometry.Polygon polygon)
        {
            var dataPolygon = new DataPolygon();

            dataPolygon.LinearRings = new List <DataLinearRing>();
            foreach (ArtDatabanken.GIS.GeoJSON.Net.Geometry.LineString lineString in polygon.Coordinates)
            {
                var dataLinearRing = new DataLinearRing();
                dataLinearRing.Points = new List <DataPoint>();
                foreach (GeographicPosition pos in lineString.Coordinates)
                {
                    var dataPoint = new DataPoint(pos.Longitude, pos.Latitude, pos.Altitude);
                    dataLinearRing.Points.Add(dataPoint);
                }

                dataPolygon.LinearRings.Add(dataLinearRing);
            }

            return(dataPolygon);
        }
コード例 #10
0
        ///// <summary>
        ///// Converts a list of DataPolygons to a GeoJSON FeatureCollection.
        ///// </summary>
        ///// <param name="dataPolygons">The DataPolygons.</param>
        ///// <returns></returns>
        //public static FeatureCollection ConvertToGeoJSONFeatureCollection(List<DataPolygon> dataPolygons, IUserContext userContext, CoordinateSystem fromCoordinateSystem, CoordinateSystem toCoordinateSystem)
        //{
        //    var featureCollection = new FeatureCollection(new List<Feature>());
        //    DataContext dataContext = new DataContext(userContext);
        //    foreach (DataPolygon dataPolygon in dataPolygons)
        //    {
        //        var pol = dataPolygon.ToPolygon(dataContext);
        //        pol = GisTools.CoordinateConversionManager.GetConvertedPolygon(pol, fromCoordinateSystem, toCoordinateSystem);

        //        Polygon polygon = ConvertToGeoJSONPolygon(dataPolygon);

        //        var feature = new Feature(polygon);
        //        featureCollection.Features.Add(feature);
        //    }

        //    return featureCollection;
        //}

        /// <summary>
        /// Converts a DataPolygon to a GeoJSON polygon.
        /// </summary>
        /// <param name="dataPolygon">The DataPolygon to convert.</param>
        /// <returns></returns>
        public static Polygon ConvertToGeoJSONPolygon(DataPolygon dataPolygon)
        {
            var polygon = new Polygon(new List <LineString>());

            if (dataPolygon.IsNull() || dataPolygon.LinearRings.IsEmpty())
            {
                return(polygon);
            }

            foreach (DataLinearRing dataLinearRing in dataPolygon.LinearRings)
            {
                var coordinates = new List <GeographicPosition>();
                foreach (DataPoint dataPoint in dataLinearRing.Points)
                {
                    var position = new GeographicPosition(dataPoint.X, dataPoint.Y, dataPoint.Z);
                    coordinates.Add(position);
                }
                var lineString = new LineString(coordinates);
                polygon.Coordinates.Add(lineString);
            }
            return(polygon);
        }
コード例 #11
0
        /// <summary>
        /// Gets the bounding box of a DataPolygon.
        /// </summary>
        /// <param name="polygon">The polygon.</param>
        /// <returns></returns>
        public static BoundingBox GetBoundingBox(this DataPolygon polygon)
        {
            if (polygon == null || polygon.LinearRings == null || polygon.LinearRings.Count == 0 || polygon.LinearRings[0].Points.Count < 3)
            {
                return(null);
            }

            BoundingBox boundingBox = new BoundingBox();

            boundingBox.Min = new Point(polygon.LinearRings[0].Points[0].X, polygon.LinearRings[0].Points[0].Y);
            boundingBox.Max = new Point(polygon.LinearRings[0].Points[0].X, polygon.LinearRings[0].Points[0].Y);
            for (int i = 1; i < polygon.LinearRings[0].Points.Count; i++)
            {
                DataPoint point = polygon.LinearRings[0].Points[i];
                if (point.X < boundingBox.Min.X)
                {
                    boundingBox.Min.X = point.X;
                }

                if (point.Y < boundingBox.Min.Y)
                {
                    boundingBox.Min.Y = point.Y;
                }

                if (point.X > boundingBox.Max.X)
                {
                    boundingBox.Max.X = point.X;
                }

                if (point.Y > boundingBox.Max.Y)
                {
                    boundingBox.Max.Y = point.Y;
                }
            }

            return(boundingBox);
        }