Exemple #1
0
        public void SnapToLineStringUsingFreeAtObject()
        {
            var mockRepository = new MockRepository();
            var feature = mockRepository.CreateMock<IFeature>();

            using (mockRepository.Record())
            {
                Expect.Call(feature.Geometry).Return(lineString).Repeat.Any();
            }
            
            using (mockRepository.Playback())
            {
                var features = new [] {feature};
                var layers = new[] { new VectorLayer() };

                IPoint snapSource = new Point(5, 5);
                SnapRule snapRule = new SnapRule
                                        {
                                            SnapRole = SnapRole.FreeAtObject,
                                            Obligatory = true,
                                            PixelGravity = 40
                                        };

                SnapResult snapResults = snapRule.Execute(null, features, layers, snapSource, null,
                                                             snapSource.Coordinates[0],
                                                             CreateEnvelope(snapSource, 10),
                                                             0);
                Assert.IsNotNull(snapResults);  
                Assert.IsNotNull(snapResults.Location);
                Assert.AreEqual(0, snapResults.Location.Y);
                Assert.AreEqual(5, snapResults.Location.X);
            }
        }
        protected Country InsertCountryAround(Point center, double buffer = 0.1, string name = "Neverland")
        {
            var coordinates = center.Buffer(buffer).Coordinates.Reverse().ToArray();
            var polygon = Default.GeometryFactory.CreatePolygon(new LinearRing(coordinates), null);
            var country = new Country { GeoData = polygon, Name = name };
            Session.Save(country);
            Session.Flush();
            Session.Clear();

            return country;
        }
Exemple #3
0
        public override void OnMouseDown(GeoAPI.Geometries.ICoordinate worldPosition, System.Windows.Forms.MouseEventArgs e)
        {
            // Starting a new measurement?
            if (pointGeometries.Count() >= 2 && Control.ModifierKeys != Keys.Alt)
            {
                Clear();
            }

            // Add the newly selected point
            var point = new GeoPoint(worldPosition);
            pointLayer.DataSource.Add(point);

            CalculateDistance();

            // Refresh the screen
            pointLayer.RenderRequired = true;
            MapControl.Refresh(); // HACK: Why is this needed? (Only RenderRequired = true isn't enough...)
            
            base.OnMouseDown(worldPosition, e);
        }
Exemple #4
0
        public override void OnMouseDown(GeoAPI.Geometries.ICoordinate worldPosition, System.Windows.Forms.MouseEventArgs e)
        {
            // Starting a new measurement?
            if (pointGeometries.Count() >= 2 && Control.ModifierKeys != Keys.Alt)
            {
                Clear();
            }

            // Add the newly selected point
            var point = new GeoPoint(worldPosition);

            pointLayer.DataSource.Add(point);

            CalculateDistance();

            // Refresh the screen
            pointLayer.RenderRequired = true;
            MapControl.Refresh(); // HACK: Why is this needed? (Only RenderRequired = true isn't enough...)

            base.OnMouseDown(worldPosition, e);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();
              var log = LogManager.GetLogger(typeof (Program));

              NHibernateProfiler.Initialize();

              var cfg = new Configuration().Configure();

              cfg.AddAuxiliaryDatabaseObject(
            new SpatialAuxiliaryDatabaseObject(cfg));

              var sessionFactory = cfg.BuildSessionFactory();

              //Houston, TX
              var houstonTX = new Point(-95.383056, 29.762778);

              using (var session = sessionFactory.OpenSession())
              {
            using (var tx = session.BeginTransaction())
            {
              var query = session.CreateCriteria(
            typeof (StatePart))
            .Add(SpatialExpression.Contains(
              "Geometry", houstonTX));
              var part = query.UniqueResult<StatePart>();
              if (part == null)
              {
            log.InfoFormat("Houston, we have a problem.");
              }
              else
              {
            log.InfoFormat("Houston is in {0}",
              part.Name);
              }
              tx.Commit();
            }
              }
        }
Exemple #6
0
        public void SnapToLineStringUsingFreeAtObject()
        {
            MockRepository mockRepository = new MockRepository();
            IFeature feature = mockRepository.CreateMock<IFeature>();

            using (mockRepository.Record())
            {
                Expect.Call(feature.Geometry).Return(lineString).Repeat.Any();
            }
            using (mockRepository.Playback())
            {
                VectorLayer lineStringLayer = new VectorLayer
                {
                    DataSource = new FeatureCollection
                    {
                        Features = new List<IFeature> { feature }
                    }
                };

                IPoint snapSource = new Point(5, 5);
                SnapRule snapRule = new SnapRule
                                        {
                                            TargetLayer = lineStringLayer,
                                            SnapRole = SnapRole.FreeAtObject,
                                            Obligatory = true,
                                            PixelGravity = 40
                                        };

                ISnapResult snapResults = snapRule.Execute(null, snapSource, null,
                                                             snapSource.Coordinates[0],
                                                             CreateEnvelope(snapSource, 10),
                                                             0);
                Assert.IsNotNull(snapResults);  
                Assert.IsNotNull(snapResults.Location);
                Assert.AreEqual(0, snapResults.Location.Y);
                Assert.AreEqual(5, snapResults.Location.X);
            }
        }
        private static IPoint ReadPoint(JsonTextReader jreader)
        {
            if (jreader == null)
            {
                throw new ArgumentNullException("reader", "A valid JSON reader object is required.");
            }

            IPoint point = null;

            if (jreader.TokenClass == JsonTokenClass.Array)
            {
                jreader.ReadToken(JsonTokenClass.Array);
                double x = Convert.ToDouble(jreader.ReadNumber());
                double y = Convert.ToDouble(jreader.ReadNumber());
                double z = double.NaN;
                if (jreader.TokenClass == JsonTokenClass.Number)
                {
                    z = Convert.ToDouble(jreader.ReadNumber());
                }
                jreader.ReadToken(JsonTokenClass.EndArray);
                point = new GisSharpBlog.NetTopologySuite.Geometries.Point(x, y, z);
            }
            return(point);
        }
Exemple #8
0
        public void GetHashCodeMustBeComputed()
        {
            var first = new Point(1.0, 2.0);

            Assert.AreEqual(712319917, first.GetHashCode());
        }
        private void ctlMap_MouseClick(object sender, MapMouseEventArgs e)
        {
            if (isbegin==true)
            {
                BaseGeometry bg = GetItemByID("routing", "begin");

                if (bg != null)
                {
                    LayerReset();
                }

                    var data = new ObservableCollection<VectorLayerData>();
                    var point = new Point(ctlMap.ViewportPointToLocation(e.ViewportPoint).Longitude, ctlMap.ViewportPointToLocation(e.ViewportPoint).Latitude);
                    data.Add(new VectorLayerData
                    {
                        Geo = point.AsBinary(),
                        ID = "begin",
                        Label = "起点",

                    });

                    layer.Add(data);

                isbegin = false;
            }

            if (islast==true)
            {
                 var data = new ObservableCollection<VectorLayerData>();
                var point = new Point(ctlMap.ViewportPointToLocation(e.ViewportPoint).Longitude, ctlMap.ViewportPointToLocation(e.ViewportPoint).Latitude);
                data.Add(new VectorLayerData
                {
                    Geo = point.AsBinary(),
                    ID = "last",
                    Label = "终点",

                });

                layer.Add(data);

                DraggablePushpin dp = GetDCarByMSID("drapcar", carml);
                if (dp != null)
                {
                    GetBegionRoad(dp.Location.Latitude, dp.Location.Longitude, 100);
                }
                Dtimer.Begin();
                Ltimer.Begin();
                islast = false;
            }

            if (isbarrier==true)
            {
                 //初始化一个图标

                var data = new ObservableCollection<VectorLayerData>();
                var point = new Point(ctlMap.ViewportPointToLocation(e.ViewportPoint).Longitude, ctlMap.ViewportPointToLocation(e.ViewportPoint).Latitude);
                GetBarrier(point.X, point.Y, 30);
                data.Add(new VectorLayerData
                {
                    Geo = point.AsBinary(),
                    ID = "barrier",
                    Label = "障碍"+bn.ToString(),
                  });

                layer.Add(data);

                isbarrier = false;
                bn++;

            }
        }
        private void ctlMap_MouseClick(object sender, MapMouseEventArgs e)
        {
            if (isbegin == true)
            {
                BaseGeometry bg = GetItemByID("routing", "begin");

                if (bg != null)
                {
                    LayerReset();
                }


                var data  = new ObservableCollection <VectorLayerData>();
                var point = new Point(ctlMap.ViewportPointToLocation(e.ViewportPoint).Longitude, ctlMap.ViewportPointToLocation(e.ViewportPoint).Latitude);
                data.Add(new VectorLayerData
                {
                    Geo   = point.AsBinary(),
                    ID    = "begin",
                    Label = "起点",
                });

                layer.Add(data);

                isbegin = false;
            }

            if (islast == true)
            {
                var data  = new ObservableCollection <VectorLayerData>();
                var point = new Point(ctlMap.ViewportPointToLocation(e.ViewportPoint).Longitude, ctlMap.ViewportPointToLocation(e.ViewportPoint).Latitude);
                data.Add(new VectorLayerData
                {
                    Geo   = point.AsBinary(),
                    ID    = "last",
                    Label = "终点",
                });

                layer.Add(data);


                DraggablePushpin dp = GetDCarByMSID("drapcar", carml);
                if (dp != null)
                {
                    GetBegionRoad(dp.Location.Latitude, dp.Location.Longitude, 100);
                }
                Dtimer.Begin();
                Ltimer.Begin();
                islast = false;
            }

            if (isbarrier == true)
            {
                //初始化一个图标

                var data  = new ObservableCollection <VectorLayerData>();
                var point = new Point(ctlMap.ViewportPointToLocation(e.ViewportPoint).Longitude, ctlMap.ViewportPointToLocation(e.ViewportPoint).Latitude);
                GetBarrier(point.X, point.Y, 30);
                data.Add(new VectorLayerData
                {
                    Geo   = point.AsBinary(),
                    ID    = "barrier",
                    Label = "障碍" + bn.ToString(),
                });

                layer.Add(data);

                isbarrier = false;
                bn++;
            }
        }
Exemple #11
0
 /// <summary>
 /// Creates a new <c>PointWrapper</c> that wraps the supplied geometry.
 /// </summary>
 /// <param name="g">The geometry to wrap</param>
 internal PointWrapper(NTS.Point p)
     : base(p)
 {
 }
Exemple #12
0
 protected Polygon GetDefaultPolygon(Point center, double buffer = 0.1)
 {
     var ring = new LinearRing(center.Buffer(buffer).Coordinates.Reverse().ToArray());
     return (Polygon)Default.GeometryFactory.CreatePolygon(ring, null);
 }