예제 #1
0
        public void GeoPolygon_Serialize()
        {
            GeoPolygon poly;

            poly = new GeoPolygon(
                new GeoCoordinate[] {
                new GeoCoordinate(10, 20)
            });

            poly = (GeoPolygon)GeoRegion.Parse(poly.ToString());
            Assert.AreEqual(1, poly.Vertices.Count);
            Assert.IsTrue(new GeoCoordinate(10, 20) == poly.Vertices[0]);

            poly = new GeoPolygon(
                new GeoCoordinate[] {
                new GeoCoordinate(10, 20),
                new GeoCoordinate(0, 20),
                new GeoCoordinate(0, 0)
            });

            poly = (GeoPolygon)GeoRegion.Parse(poly.ToString());
            Assert.AreEqual(3, poly.Vertices.Count);
            Assert.IsTrue(new GeoCoordinate(10, 20) == poly.Vertices[0]);
            Assert.IsTrue(new GeoCoordinate(0, 20) == poly.Vertices[1]);
            Assert.IsTrue(new GeoCoordinate(0, 0) == poly.Vertices[2]);
        }
예제 #2
0
        public void GeoCircle_Serialize()
        {
            var circle1 = new GeoCircle(GeoCoordinate.Origin, 10, GeoHelper.EarthRadiusMiles);
            var circle2 = (GeoCircle)GeoRegion.Parse(circle1.ToString());

            Assert.AreEqual(circle1, circle2);
        }
예제 #3
0
        //---------------------------------------------------------------------
        // Static members

        internal static GeoQuery FromMessage(GeoQueryMsg queryMsg)
        {
            GeoQuery query = new GeoQuery();
            string   value;

            query.Options       = GeoQueryOptions.Load(queryMsg);
            query.EntityFilters = queryMsg._GetArray("EntityFilter");
            query.GroupFilters  = queryMsg._GetArray("QueryFilter");

            value = queryMsg._Get("Region", (string)null);
            if (!string.IsNullOrWhiteSpace(value))
            {
                query.Region = GeoRegion.Parse(value);
            }

            if (!string.IsNullOrWhiteSpace(queryMsg["MinTimeUtc"]))
            {
                query.MinTimeUtc = queryMsg._Get("MinTimeUtc", DateTime.MinValue);
            }

            if (!string.IsNullOrWhiteSpace(queryMsg["MaxTimeUtc"]))
            {
                query.MaxTimeUtc = queryMsg._Get("MaxTimeUtc", DateTime.MaxValue);
            }

            return(query);
        }
예제 #4
0
        public void GeoRectangle_Serialize()
        {
            var r1 = new GeoRectangle(new GeoCoordinate(30, 20), new GeoCoordinate(-30, 5));
            var r2 = (GeoRectangle)GeoRegion.Parse(r1.ToString());

            Assert.AreEqual(r1, r2);
        }
예제 #5
0
        public void GeoPolygon_Bounds()
        {
            GeoPolygon poly;

            poly = new GeoPolygon(
                new GeoCoordinate[] {
                new GeoCoordinate(10, 20),
                new GeoCoordinate(0, 20),
                new GeoCoordinate(0, 0)
            });

            Assert.AreEqual(new GeoRectangle(10, 20, 0, 0), poly.Bounds);

            // Verify that bounds are restored after serialization

            poly = (GeoPolygon)GeoRegion.Parse(poly.ToString());
            Assert.AreEqual(new GeoRectangle(10, 20, 0, 0), poly.Bounds);
        }
예제 #6
0
        /// <summary>
        /// Derived classes must implement this to load the option fields from the
        /// query passed.
        /// </summary>
        /// <param name="queryMsg">The source message.</param>
        /// <remarks>
        /// The derived class must store its values as <see cref="PropertyMsg" /> fields
        /// using <b>"Option."</b> as the key prefix for each value's property name.
        /// </remarks>
        protected override void LoadFrom(GeoQueryMsg queryMsg)
        {
            string value;
            double d;

            value = queryMsg._Get("Option.MapBounds", (string)null);
            if (!string.IsNullOrWhiteSpace(value))
            {
                MapBounds = (GeoRectangle)GeoRegion.Parse(value);
            }

            value = queryMsg._Get("Option.ResolutionMiles", (string)null);
            if (!string.IsNullOrWhiteSpace(value))
            {
                if (double.TryParse(value, out d))
                {
                    ResolutionMiles = d;
                }
            }
        }
예제 #7
0
        public void GeoCompositeRegion_Serialize()
        {
            GeoCompositeRegion comp;
            GeoPolygon         poly;

            // Test additive regions only

            comp = new GeoCompositeRegion(
                new GeoRegion[] {
                new GeoRectangle(30, 30, -30, -30),
                new GeoCircle(0, 0, 20, GeoHelper.EarthRadiusMiles),
                new GeoPolygon(
                    new GeoCoordinate[] {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(20, 20),
                    new GeoCoordinate(0, 30)
                })
            });

            comp = (GeoCompositeRegion)GeoRegion.Parse(comp.ToString());

            Assert.AreEqual(3, comp.AdditiveRegions.Count);
            Assert.IsTrue(new GeoRectangle(30, 30, -30, -30) == (GeoRectangle)comp.AdditiveRegions[0]);
            Assert.IsTrue(new GeoCircle(0, 0, 20, GeoHelper.EarthRadiusMiles) == (GeoCircle)comp.AdditiveRegions[1]);

            poly = (GeoPolygon)comp.AdditiveRegions[2];
            Assert.AreEqual(3, poly.Vertices.Count);
            Assert.AreEqual(new GeoCoordinate(0, 0), poly.Vertices[0]);
            Assert.AreEqual(new GeoCoordinate(20, 20), poly.Vertices[1]);
            Assert.AreEqual(new GeoCoordinate(0, 30), poly.Vertices[2]);

            Assert.IsNull(comp.SubtractiveRegions);

            // Test additive and subtractive regions

            comp = new GeoCompositeRegion(
                new GeoRegion[] {
                new GeoRectangle(10, 10, 0, 0)
            },
                new GeoRegion[] {
                new GeoRectangle(30, 30, -30, -30),
                new GeoCircle(0, 0, 20, GeoHelper.EarthRadiusMiles),
                new GeoPolygon(
                    new GeoCoordinate[] {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(20, 20),
                    new GeoCoordinate(0, 30)
                })
            });

            comp = (GeoCompositeRegion)GeoRegion.Parse(comp.ToString());

            Assert.AreEqual(1, comp.AdditiveRegions.Count);
            Assert.IsTrue(new GeoRectangle(10, 10, 0, 0) == (GeoRectangle)comp.AdditiveRegions[0]);

            Assert.AreEqual(3, comp.SubtractiveRegions.Count);
            Assert.IsTrue(new GeoRectangle(30, 30, -30, -30) == (GeoRectangle)comp.SubtractiveRegions[0]);
            Assert.IsTrue(new GeoCircle(0, 0, 20, GeoHelper.EarthRadiusMiles) == (GeoCircle)comp.SubtractiveRegions[1]);

            poly = (GeoPolygon)comp.SubtractiveRegions[2];
            Assert.AreEqual(3, poly.Vertices.Count);
            Assert.AreEqual(new GeoCoordinate(0, 0), poly.Vertices[0]);
            Assert.AreEqual(new GeoCoordinate(20, 20), poly.Vertices[1]);
            Assert.AreEqual(new GeoCoordinate(0, 30), poly.Vertices[2]);
        }