/// <summary>
        /// Convert a point from one coordinate system to
        /// another coordinate system.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="point">Point that should be converted.</param>
        /// <param name="fromCoordinateSystem">From coordinate system.</param>
        /// <param name="toCoordinateSystem">To coordinate system.</param>
        /// <returns>WebPoint with coordinates according to toCoordinateSystem</returns>
        public virtual WebPoint GetConvertedPoint(WebServiceContext context,
                                                  WebPoint point,
                                                  WebCoordinateSystem fromCoordinateSystem,
                                                  WebCoordinateSystem toCoordinateSystem)
        {
            String   cacheKey;
            WebPoint toPoint;

            // Get cached information.
            cacheKey = Settings.Default.PointCacheKey +
                       Settings.Default.CacheKeyDelimiter +
                       point.X.WebToString() +
                       Settings.Default.CacheKeyDelimiter +
                       point.Y.WebToString() +
                       Settings.Default.CacheKeyDelimiter +
                       fromCoordinateSystem.GetWkt() +
                       Settings.Default.CacheKeyDelimiter +
                       toCoordinateSystem.GetWkt();
            toPoint = (WebPoint)(context.GetCachedObject(cacheKey));

            // Data not in cache - store it in the cache.
            if (toPoint.IsNull())
            {
                toPoint = GetConvertedPoint(point,
                                            fromCoordinateSystem,
                                            toCoordinateSystem);
                // Add information to cache.
                context.AddCachedObject(cacheKey,
                                        toPoint,
                                        new TimeSpan(0, 1, 0, 0),
                                        CacheItemPriority.Low);
            }

            return(toPoint);
        }
 /// <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());
 }
        /// <summary>
        /// Get coordinate converter transformator.
        /// </summary>
        /// <param name="fromCoordinateSystem">From coordinate system.</param>
        /// <param name="toCoordinateSystem">To coordinate system.</param>
        /// <returns>Coordinate converter transformator.</returns>
        private ICoordinateTransformation GetTransformator(WebCoordinateSystem fromCoordinateSystem,
                                                           WebCoordinateSystem toCoordinateSystem)
        {
            CoordinateTransformationFactory factory;
            ICoordinateSystem fromSystem, toSystem;

            factory    = new CoordinateTransformationFactory();
            fromSystem = CoordinateSystemWktReader.Parse(fromCoordinateSystem.GetWkt()) as ICoordinateSystem;
            toSystem   = CoordinateSystemWktReader.Parse(toCoordinateSystem.GetWkt()) as ICoordinateSystem;
            return(factory.CreateFromCoordinateSystems(fromSystem, toSystem));
        }
Esempio n. 4
0
 /// <summary>
 /// Get coordinate system as string.
 /// </summary>
 /// <param name="coordinateSystem">Coordinate system.</param>
 /// <returns>Coordinate system as string.</returns>
 public static String WebToString(this WebCoordinateSystem coordinateSystem)
 {
     if (coordinateSystem.IsNull())
     {
         return(String.Empty);
     }
     else
     {
         return("Coordinate system: Id = " + coordinateSystem.Id +
                ", Wkt = [" + coordinateSystem.GetWkt() + "]" +
                coordinateSystem.DataFields.WebToString());
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Get envelope for polygons in JSON format.
        /// </summary>
        /// <param name="polygons">Get envelope for these polygons.</param>
        /// <param name="buffer">Add this buffer to envelope. Unit is meters.</param>
        /// <param name="coordinateSystem">Polygons are defined in this coordinate system.</param>
        /// <returns>Envelope for polygons in JSON format.</returns>
        public static String GetEnvelopeJson(this List <WebPolygon> polygons,
                                             WebCoordinateSystem coordinateSystem,
                                             Int32 buffer)
        {
            String              envelopeJson;
            WebBoundingBox      boundingBox;
            WebCoordinateSystem googleCoordinateSystem;

            envelopeJson = null;
            if (polygons.IsNotEmpty())
            {
                // Convert polygons to Google Mercator.
                googleCoordinateSystem    = new WebCoordinateSystem();
                googleCoordinateSystem.Id = CoordinateSystemId.GoogleMercator;
                if (googleCoordinateSystem.GetWkt() != coordinateSystem.GetWkt())
                {
                    polygons = WebServiceData.CoordinateConversionManager.GetConvertedPolygons(polygons,
                                                                                               coordinateSystem,
                                                                                               googleCoordinateSystem);
                }

                // Get bounding box with buffer.
                boundingBox = polygons.GetBoundingBox();
                boundingBox.AddBuffer(buffer);
                if (googleCoordinateSystem.GetWkt() != coordinateSystem.GetWkt())
                {
                    boundingBox = WebServiceData.CoordinateConversionManager.GetConvertedBoundingBox(boundingBox,
                                                                                                     googleCoordinateSystem,
                                                                                                     coordinateSystem).GetBoundingBox();
                }

                envelopeJson = boundingBox.GetJson();
            }

            return(envelopeJson);
        }
Esempio n. 6
0
        /// <summary>
        /// Check that data is valid.
        /// </summary>
        /// <param name="coordinateSystem">This coordinate system.</param>
        public static void CheckData(this WebCoordinateSystem coordinateSystem)
        {
            String wkt;

            coordinateSystem.CheckNotNull("coordinateSystem");
            if (coordinateSystem.Id == CoordinateSystemId.None)
            {
                // Verify externally defined WKT.
                // Internally defined WKT's are assumed to be correct.
                wkt = coordinateSystem.GetWkt();
                wkt.CheckNotEmpty("coordinateSystem.wkt");
                try
                {
                    CoordinateSystemWktReader.Parse(wkt);
                }
                catch
                {
                    throw new ArgumentException("Wrong format in coordinate system: " + wkt);
                }
            }
        }
        /// <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);
        }