public void LoadData()
        {
            Boolean            isRegionGeographyLoaded;
            List <String>      regionGuids;
            WebRegionGeography regionGeography;

            isRegionGeographyLoaded = false;
            regionGuids             = new List <String>();
            regionGuids.Add(Settings.Default.ProvinceBlekingeGUID);
            regionGuids.Add(Settings.Default.ProvinceSkaneGUID);
            using (DataReader dataReader = GetContext().GetGeoReferenceDatabase().GetRegionsGeographyByGUIDs(regionGuids))
            {
                while (dataReader.Read())
                {
                    isRegionGeographyLoaded = true;
                    regionGeography         = new WebRegionGeography();
                    regionGeography.LoadData(dataReader);

                    Assert.IsTrue(0 <= regionGeography.Id);
                    Assert.IsNotNull(regionGeography.BoundingBox);
                    Assert.IsTrue(regionGeography.GUID.IsNotEmpty());
                    Assert.IsNotNull(regionGeography.MultiPolygon);
                }
            }
            Assert.IsTrue(isRegionGeographyLoaded);
        }
Exemple #2
0
        /// <summary>
        /// Test if point is located inside region.
        /// Currently only two dimensions are handled.
        /// </summary>
        /// <param name="regionGeography">This region geography.</param>
        /// <param name="context">Web service request context.</param>
        /// <param name="coordinateSystem">Coordinate system used in region.</param>
        /// <param name='point'>Point.</param>
        /// <returns>True if point is located inside region.</returns>
        public static Boolean IsPointInsideGeography(this WebRegionGeography regionGeography,
                                                     WebServiceContext context,
                                                     WebCoordinateSystem coordinateSystem,
                                                     WebPoint point)
        {
            SqlGeography geographyMultiPolygon, geographyPoint;

            geographyPoint        = point.GetGeography();
            geographyMultiPolygon = regionGeography.GetMultiPolygonGeography(context, coordinateSystem);
            return(geographyMultiPolygon.STIntersects(geographyPoint).Value);
        }
        /// <summary>
        /// Load data into the WebRegionGeography instance.
        /// </summary>
        /// <param name="regionGeography">This region geography.</param>
        /// <param name='dataReader'>An open data reader.</param>
        public static void LoadData(this WebRegionGeography regionGeography,
                                    DataReader dataReader)
        {
            Int32  categoryId;
            String nativeId;

            regionGeography.Id          = dataReader.GetInt32(RegionData.ID);
            regionGeography.BoundingBox = new WebBoundingBox();
            regionGeography.BoundingBox.LoadData(dataReader, RegionData.BOUNDING_BOX);
            categoryId                   = dataReader.GetInt32(RegionData.CATEGORY_ID);
            nativeId                     = dataReader.GetString(RegionData.NATIVE_ID);
            regionGeography.GUID         = new RegionGUID(categoryId, nativeId).GUID;
            regionGeography.MultiPolygon = new WebMultiPolygon();
            regionGeography.MultiPolygon.LoadData(dataReader, RegionData.POLYGON);
        }
Exemple #4
0
        /// <summary>
        /// Test if point is located inside region.
        /// Currently only two dimensions are handled.
        /// </summary>
        /// <param name="regionGeography">This region geography.</param>
        /// <param name="context">Web service request context.</param>
        /// <param name="coordinateSystem">Coordinate system used in region.</param>
        /// <param name='point'>Point.</param>
        /// <returns>True if point is located inside region.</returns>
        public static Boolean IsPointInsideGeometry(this WebRegionGeography regionGeography,
                                                    WebServiceContext context,
                                                    WebCoordinateSystem coordinateSystem,
                                                    WebPoint point)
        {
            SqlGeometry geometryMultiPolygon, geometryPoint;

            if (regionGeography.BoundingBox.IsPointInside(point))
            {
                geometryPoint        = point.GetGeometry();
                geometryMultiPolygon = regionGeography.GetMultiPolygonGeometry(context, coordinateSystem);
                return(geometryMultiPolygon.STContains(geometryPoint).Value);
            }
            else
            {
                // Species observation can not be inside region
                // since it is not inside the regions bounding box.
                return(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// Get a SqlGeometry instance with same information as
        /// property MultiPolygon in provided WebRegionGeography.
        /// </summary>
        /// <param name="regionGeography">This region geography.</param>
        /// <param name="context">Web service request context.</param>
        /// <param name="coordinateSystem">Coordinate system used in region.</param>
        /// <returns>
        /// A SqlGeometry instance with same information as
        /// property MultiPolygon in provided WebRegionGeography.
        /// </returns>
        private static SqlGeometry GetMultiPolygonGeometry(this WebRegionGeography regionGeography,
                                                           WebServiceContext context,
                                                           WebCoordinateSystem coordinateSystem)
        {
            SqlGeometry geometryMultiPolygon;
            String      cacheKey;

            // Get cached information.
            cacheKey = "RegionSqlGeometry:" +
                       regionGeography.Id +
                       ":CoordinateSystem:" +
                       coordinateSystem.GetWkt();
            geometryMultiPolygon = (SqlGeometry)context.GetCachedObject(cacheKey);

            if (geometryMultiPolygon.IsNull())
            {
                geometryMultiPolygon = regionGeography.MultiPolygon.GetGeometry();

                // Add information to cache.
                context.AddCachedObject(cacheKey, geometryMultiPolygon, new TimeSpan(1, 0, 0), CacheItemPriority.BelowNormal);
            }

            return(geometryMultiPolygon);
        }