Exemple #1
0
 /// <summary>
 /// Convert linear ring to JSON format.
 /// </summary>
 /// <param name="linearRing">Linear ring that should be converted.</param>
 /// <returns>Linear ring in JSON format.</returns>
 public static String GetJson(this WebLinearRing linearRing)
 {
     if (linearRing.IsNotNull())
     {
         return(linearRing.Points.GetJson());
     }
     else
     {
         return(String.Empty);
     }
 }
        /// <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);
        }
Exemple #3
0
 /// <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>
        /// Get linear ring from SqlGeometry.
        /// </summary>
        /// <param name="geometryLinearRing">Linear ring geometry.</param>
        /// <returns>Linear ring.</returns>
        public static WebLinearRing GetLinearRing(this SqlGeometry geometryLinearRing)
        {
            Int32         pointIndex;
            SqlGeometry   geometryPoint;
            WebLinearRing linearRing;

            if (geometryLinearRing.GetGeometryType() != SqlGeometryType.LineString)
            {
                throw new ArgumentException("Wrong geometry data type in GetLinearRing. Expected type 'LineString', actual type : " + geometryLinearRing.GetGeometryType().ToString());
            }

            linearRing        = new WebLinearRing();
            linearRing.Points = new List <WebPoint>();
            for (pointIndex = 1; pointIndex <= geometryLinearRing.STNumPoints(); pointIndex++)
            {
                geometryPoint = geometryLinearRing.STPointN(pointIndex);
                linearRing.Points.Add(geometryPoint.GetPoint());
            }
            return(linearRing);
        }