예제 #1
0
        private IPolygon CreateSelectionPolygon(Coordinate worldPosition)
        {
            if (MultiSelectionMode == MultiSelectionMode.Rectangle)
            {
                if (0 == Math.Abs(mouseDownLocation.X - worldPosition.X))
                {
                    return(null);
                }
                if (0 == Math.Abs(mouseDownLocation.Y - worldPosition.Y))
                {
                    return(null);
                }
                return(CreatePolygon(Math.Min(mouseDownLocation.X, worldPosition.X),
                                     Math.Max(mouseDownLocation.Y, worldPosition.Y),
                                     Math.Max(mouseDownLocation.X, worldPosition.X),
                                     Math.Min(mouseDownLocation.Y, worldPosition.Y)));
            }
            var vertices = selectPoints.Select(point => Map.ImageToWorld(point)).ToList();

            if (vertices.Count == 1)
            {
                // too few points to create a polygon
                return(null);
            }
            vertices.Add((Coordinate)worldPosition.Clone());
            vertices.Add((Coordinate)vertices[0].Clone());
            ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());

            return(GeometryFactory.CreatePolygon(newLinearRing, null));
        }
예제 #2
0
        private void InitializeShape(string filename, bool FileBasedIndex)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException(String.Format("Could not find file \"{0}\"", filename));
            }

            if (!filename.ToLower().EndsWith(".shp"))
            {
                throw (new Exception("Invalid shapefile filename: " + filename));
            }

            recordHeaders = LoadIndexfile(GetIndexFilePath());

            //Read the spatial bounding box of the contents
            brShapeIndex.BaseStream.Seek(36, 0); //seek to box

            double x1, x2, y1, y2;

            x1 = brShapeIndex.ReadDouble();
            y1 = brShapeIndex.ReadDouble();
            x2 = brShapeIndex.ReadDouble();
            y2 = brShapeIndex.ReadDouble();

            _Envelope = GeometryFactory.CreateEnvelope(x1, x2, y1, y2);
        }
예제 #3
0
        public static ICoordinate ImageToWorld(Map map, double width, double height)
        {
            ICoordinate c1 = map.ImageToWorld(new PointF(0, 0));
            ICoordinate c2 = map.ImageToWorld(new PointF((float)width, (float)height));

            return(GeometryFactory.CreateCoordinate(Math.Abs(c1.X - c2.X), Math.Abs(c1.Y - c2.Y)));
        }
예제 #4
0
        /// <summary>
        /// Reads a node from a stream recursively
        /// </summary>
        /// <param name="depth">Current depth</param>
        /// <param name="br">Binary reader reference</param>
        /// <returns></returns>
        private static QuadTreeOld ReadNode(uint depth, ref System.IO.BinaryReader br)
        {
            QuadTreeOld node = new QuadTreeOld();

            node._Depth = depth;
            node.Box    = GeometryFactory.CreateEnvelope(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble());
            bool IsLeaf = br.ReadBoolean();

            if (IsLeaf)
            {
                int FeatureCount = br.ReadInt32();
                node._objList = new List <BoxObjects>();
                for (int i = 0; i < FeatureCount; i++)
                {
                    BoxObjects box = new BoxObjects();
                    box.box = GeometryFactory.CreateEnvelope(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble());
                    box.ID  = (uint)br.ReadInt32();
                    node._objList.Add(box);
                }
            }
            else
            {
                node.Child0 = ReadNode(node._Depth + 1, ref br);
                node.Child1 = ReadNode(node._Depth + 1, ref br);
            }
            return(node);
        }
예제 #5
0
        protected IEnumerable <TrackerFeature> CreateTrackersForGeometry(IGeometry geometry)
        {
            var coordinates = geometry.Coordinates;

            if (coordinates.Length == 0)
            {
                yield break;
            }

            yield return(new TrackerFeature(this, GeometryFactory.CreatePoint(coordinates[0].X, coordinates[0].Y), 0,
                                            trackerSmallStart));

            for (var i = 1; i < coordinates.Length - 1; i++)
            {
                yield return
                    (new TrackerFeature(this, GeometryFactory.CreatePoint(coordinates[i].X, coordinates[i].Y), i,
                                        trackerSmall));
            }

            if (coordinates.Length > 1)
            {
                yield return
                    (new TrackerFeature(this, GeometryFactory.CreatePoint(coordinates.Last().X, coordinates.Last().Y),
                                        coordinates.Length - 1, trackerSmallEnd));
            }
        }
예제 #6
0
        /// <summary>
        /// Find the nearest feature to worldPos out of a collection of candidates. If there is no geometry
        /// with a distance less than limit null is returned.
        /// </summary>
        /// <param name="candidates"></param>
        /// <param name="worldPos"></param>
        /// <param name="limit"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        private static IFeature FindNearestFeature(VectorLayer vectorLayer, IEnumerable candidates, ICoordinate worldPos,
                                                   float limit, out double distance)
        {
            IPoint point = GeometryFactory.CreatePoint(worldPos.X, worldPos.Y);

            IFeature current = null;

            distance = double.MaxValue;
            foreach (IFeature feature in candidates)
            {
                IGeometry geometry;
                if (vectorLayer.CustomRenderers.Count > 0)
                {
                    geometry = vectorLayer.CustomRenderers[0].GetRenderedFeatureGeometry(feature, vectorLayer);
                }
                else
                {
                    if (vectorLayer.CoordinateTransformation != null)
                    {
                        geometry = GeometryTransform.TransformGeometry(feature.Geometry, vectorLayer.CoordinateTransformation.MathTransform);
                    }
                    else
                    {
                        geometry = feature.Geometry;
                    }
                }
                double localDistance = geometry.Distance(point);
                if ((localDistance < distance) && (localDistance < limit))
                {
                    current  = feature;
                    distance = localDistance;
                }
            }
            return(current);
        }
예제 #7
0
        public void ZoomToBox_WithAspectCorrection()
        {
            var map = new Map(new Size(400, 200));

            map.ZoomToFit(GeometryFactory.CreateEnvelope(10, 20, 100, 180));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(15, 140), map.Center);
            Assert.AreEqual(160d, map.Zoom);
        }
예제 #8
0
        public void ZoomToBox_NoAspectCorrection()
        {
            var map = new Map(new Size(400, 200));

            map.ZoomToFit(GeometryFactory.CreateEnvelope(20, 50, 100, 80));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(35, 90), map.Center);
            Assert.AreEqual(40d, map.Zoom);
        }
예제 #9
0
        /// <summary>
        /// Returns the next feature at worldPos.
        /// </summary>
        /// <param name="worldPos"></param>
        /// <param name="limit"></param>
        /// <param name="outLayer"></param>
        /// the layer containing the next feature; null if no next feature is found.
        /// <param name="feature"></param>
        /// <param name="condition"></param>
        /// <returns>the next feature at worldPos, null if there is no next feature.</returns>
        public IFeature GetNextFeatureAtPosition(ICoordinate worldPos, float limit, out Layer outLayer, IFeature feature,
                                                 Func <ILayer, bool> condition)
        {
            IEnvelope envelope     = GetEnvelope(worldPos, limit);
            IFeature  nextFeature  = null;
            bool      featureFound = false;

            outLayer = null;

            foreach (ILayer mapLayer in Map.GetAllVisibleLayers(false))
            {
                var    vectorLayer = mapLayer as VectorLayer;
                IPoint point       = GeometryFactory.CreatePoint(worldPos);
                if (vectorLayer == null || !vectorLayer.IsSelectable)
                {
                    continue;
                }
                if ((null != condition) && (!condition(vectorLayer)))
                {
                    continue;
                }

                if (vectorLayer.DataSource != null)
                {
                    var objectsAt = vectorLayer.GetFeatures(envelope);
                    foreach (IFeature featureAt in objectsAt)
                    {
                        // GetFeatures(envelope) uses the geometry bounds; this results in more
                        // geometries than we actually are interested in (especially linestrings and polygons).
                        double distance = featureAt.Geometry.Distance(point);

                        if (distance >= limit)
                        {
                            continue;
                        }
                        if (featureFound)
                        {
                            nextFeature = featureAt;
                            outLayer    = vectorLayer;
                            return(nextFeature);
                        }
                        if (featureAt == feature)
                        {
                            featureFound = true;
                            continue;
                        }
                        if (null != nextFeature)
                        {
                            continue;
                        }
                        // If feature is last in collections objectsAt nextfeature is first
                        nextFeature = featureAt;
                        outLayer    = vectorLayer;
                    }
                }
            }
            return(nextFeature);
        }
예제 #10
0
        public static IEnvelope GetEnvelope(ICoordinate worldPos, double width, double height)
        {
            // maak een rectangle in wereldcoordinaten ter grootte van 20 pixels rondom de click
            IPoint    p        = GeometryFactory.CreatePoint(worldPos.X, worldPos.Y);
            IEnvelope Envelope = (IEnvelope)p.EnvelopeInternal.Clone();

            Envelope.SetCentre(p, width, height);
            return(Envelope);
        }
예제 #11
0
        public static IEnvelope GetEnvelope(ICoordinate worldPos, float radius)
        {
            // maak een rectangle in wereldcoordinaten ter grootte van 20 pixels rondom de click
            IPoint    p        = GeometryFactory.CreatePoint(worldPos);
            IEnvelope Envelope = (IEnvelope)p.EnvelopeInternal.Clone();

            Envelope.SetCentre(p, radius, radius);
            return(Envelope);
        }
예제 #12
0
파일: MapTest.cs 프로젝트: Sony-NS/SharpMap
        public void WorldToMap_DefaultMap_ReturnValue()
        {
            Map map = new Map(new System.Drawing.Size(500, 200));

            map.Center = GeometryFactory.CreateCoordinate(23, 34);
            map.Zoom   = 1000;
            System.Drawing.PointF p = map.WorldToImage(GeometryFactory.CreateCoordinate(8, 50));
            Assert.AreEqual(new System.Drawing.PointF(242.5f, 92), p);
        }
예제 #13
0
        public void ImageToWorld_DefaultMap_ReturnValue()
        {
            var map = new Map(new Size(500, 200))
            {
                Center = GeometryFactory.CreateCoordinate(23, 34), Zoom = 1000
            };
            ICoordinate p = map.ImageToWorld(new PointF(242.5f, 92));

            Assert.AreEqual(GeometryFactory.CreateCoordinate(8, 50), p);
        }
예제 #14
0
        public void GetExtents_ValidDatasource()
        {
            var map    = new Map(new Size(400, 200));
            var vLayer = new VectorLayer("Geom layer", CreateTestFeatureProvider());

            map.Layers.Add(vLayer);
            IEnvelope box = map.GetExtents();

            Assert.AreEqual(GeometryFactory.CreateEnvelope(0, 50, 0, 346.3493254), box);
        }
예제 #15
0
파일: MapTest.cs 프로젝트: Sony-NS/SharpMap
        public void ZoomToBoxWithMarginDoesAddMargin()
        {
            Map       map      = new Map(new Size(400, 200));
            IEnvelope envelope = GeometryFactory.CreateEnvelope(20, 50, 100, 80);

            //action! zoom to box with margin
            map.ZoomToFit(envelope, true);

            //see the heigth has a 10% extra!
            Assert.AreEqual(22, map.Envelope.Height);
        }
예제 #16
0
        public void ZoomToBoxSetsMapHeight()
        {
            var       map      = new Map(new Size(400, 200));
            IEnvelope envelope = GeometryFactory.CreateEnvelope(20, 50, 100, 80);

            //action! zoom to box with margin
            map.ZoomToFit(envelope, false);

            //see the heigth has a 10% extra!
            Assert.AreEqual(20, map.Envelope.Height);
        }
예제 #17
0
        public void ZoomToBoxWithMarginDoesNotMessUpGivenEnvelope()
        {
            var       map      = new Map(new Size(400, 200));
            IEnvelope envelope = GeometryFactory.CreateEnvelope(20, 50, 100, 80);

            //action! zoom to box with margin
            map.ZoomToFit(envelope, true);
            Assert.AreEqual(20, envelope.MinX);
            Assert.AreEqual(50, envelope.MaxX);
            Assert.AreEqual(80, envelope.MinY);
            Assert.AreEqual(100, envelope.MaxY);
        }
예제 #18
0
파일: MapTest.cs 프로젝트: Sony-NS/SharpMap
        public void WorldToImage()
        {
            Map map = new Map(new Size(1000, 500));

            map.Zoom   = 360;
            map.Center = GeometryFactory.CreateCoordinate(0, 0);
            Assert.AreEqual(new PointF(500, 250), map.WorldToImage(GeometryFactory.CreateCoordinate(0, 0)));
            Assert.AreEqual(new PointF(0, 0), map.WorldToImage(GeometryFactory.CreateCoordinate(-180, 90)));
            Assert.AreEqual(new PointF(0, 500), map.WorldToImage(GeometryFactory.CreateCoordinate(-180, -90)));
            Assert.AreEqual(new PointF(1000, 0), map.WorldToImage(GeometryFactory.CreateCoordinate(180, 90)));
            Assert.AreEqual(new PointF(1000, 500), map.WorldToImage(GeometryFactory.CreateCoordinate(180, -90)));
        }
예제 #19
0
        private void CreateNewLine()
        {
            if (newArrowLineLayer == null)
            {
                return;
            }

            newArrowLineGeometry = GeometryFactory.CreateLineString(new[] { startCoordinate, endCoordinate });

            ((DataTableFeatureProvider)newArrowLineLayer.DataSource).Clear();
            newArrowLineLayer.DataSource.Add(newArrowLineGeometry);
        }
예제 #20
0
        private IPolygon CreatePolygon(double left, double top, double right, double bottom)
        {
            var vertices = new List <Coordinate>
            {
                GeometryFactoryEx.CreateCoordinate(left, bottom),
                GeometryFactoryEx.CreateCoordinate(right, bottom),
                GeometryFactoryEx.CreateCoordinate(right, top),
                GeometryFactoryEx.CreateCoordinate(left, top)
            };

            vertices.Add((Coordinate)vertices[0].Clone());
            ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());

            return(GeometryFactory.CreatePolygon(newLinearRing, null));
        }
예제 #21
0
        public override TrackerFeature GetTrackerAtCoordinate(Coordinate worldPos)
        {
            var trackerFeature = base.GetTrackerAtCoordinate(worldPos);

            if (trackerFeature == null)
            {
                var org   = Layer.Map.ImageToWorld(new PointF(0, 0));
                var range = Layer.Map.ImageToWorld(new PointF(6, 6)); // todo make attribute
                if (SourceFeature.Geometry.Distance(GeometryFactory.CreatePoint(worldPos)) < Math.Abs(range.X - org.X))
                {
                    return(AllTracker);
                }
            }
            return(trackerFeature);
        }
예제 #22
0
 public override void OnDraw(Graphics graphics)
 {
     if (MultiSelectionMode == MultiSelectionMode.Lasso)
     {
         GraphicsHelper.DrawSelectionLasso(graphics, KeyExtendSelection ? Color.Magenta : Color.DeepSkyBlue, selectPoints.ToArray());
     }
     else
     {
         ICoordinate coordinate1 = GeometryFactory.CreateCoordinate(mouseDownLocation.X, mouseDownLocation.Y);
         ICoordinate coordinate2 = GeometryFactory.CreateCoordinate(WORLDPOSITION.X, WORLDPOSITION.Y);
         PointF      point1      = Map.WorldToImage(coordinate1);
         PointF      point2      = Map.WorldToImage(coordinate2);
         GraphicsHelper.DrawSelectionRectangle(graphics, KeyExtendSelection ? Color.Magenta : Color.DeepSkyBlue, point1, point2);
     }
 }
예제 #23
0
        private void StartNewLine(ICoordinate worldPos)
        {
            List <ICoordinate> verticies = new List <ICoordinate>
            {
                GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y),
                GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y)
            };
            ILineString lineString = GeometryFactory.CreateLineString(verticies.ToArray());

            ((DataTableFeatureProvider)newLineLayer.DataSource).Clear();
            newLineLayer.DataSource.Add(lineString);

            adding            = true;
            ActualAutoCurve   = AutoCurve;
            ActualMinDistance = MinDistance;
        }
예제 #24
0
        public override void OnMouseMove(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (startCoordinate == null)
            {
                return;
            }

            if (!((MouseButtons.None == e.Button) || (MouseButtons.Left == e.Button)))
            {
                return;
            }

            EndCoordinate = GeometryFactory.CreateCoordinate(worldPosition.X, worldPosition.Y);
            ShowSnap(newArrowLineGeometry, worldPosition);
            DoDrawing(true);
        }
예제 #25
0
        public void Initalize_MapInstance()
        {
            var map = new Map(new Size(2, 1));

            Assert.IsNotNull(map);
            Assert.IsNotNull(map.Layers);
            Assert.AreEqual(2f, map.Size.Width);
            Assert.AreEqual(1f, map.Size.Height);
            Assert.AreEqual(Color.Transparent, map.BackColor);
            Assert.AreEqual(1e9, map.MaximumZoom);
            Assert.AreEqual(1e-4, map.MinimumZoom);

            Assert.AreEqual(GeometryFactory.CreateCoordinate(0, 0), map.Center,
                            "map.Center should be initialized to (0,0)");
            Assert.AreEqual(1000, map.Zoom, "Map zoom should be initialized to 1000.0");
        }
예제 #26
0
파일: MapTest.cs 프로젝트: Sony-NS/SharpMap
        public void ImageToWorld()
        {
            Map map = new Map(new System.Drawing.Size(1000, 500));

            map.Zoom   = 360;
            map.Center = GeometryFactory.CreateCoordinate(0, 0);
            Assert.AreEqual(GeometryFactory.CreateCoordinate(0, 0),
                            map.ImageToWorld(new System.Drawing.PointF(500, 250)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, 90),
                            map.ImageToWorld(new System.Drawing.PointF(0, 0)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, -90),
                            map.ImageToWorld(new System.Drawing.PointF(0, 500)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(180, 90),
                            map.ImageToWorld(new System.Drawing.PointF(1000, 0)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(180, -90),
                            map.ImageToWorld(new System.Drawing.PointF(1000, 500)));
        }
예제 #27
0
        public void ImageToWorld()
        {
            Map map = new Map(new Size(1000, 500))
            {
                Zoom = 360, Center = GeometryFactory.CreateCoordinate(0, 0)
            };

            Assert.AreEqual(GeometryFactory.CreateCoordinate(0, 0),
                            map.ImageToWorld(new PointF(500, 250)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, 90),
                            map.ImageToWorld(new PointF(0, 0)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(-180, -90),
                            map.ImageToWorld(new PointF(0, 500)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(180, 90),
                            map.ImageToWorld(new PointF(1000, 0)));
            Assert.AreEqual(GeometryFactory.CreateCoordinate(180, -90),
                            map.ImageToWorld(new PointF(1000, 500)));
        }
예제 #28
0
        private static ILineString RemoveCurvePoint(ILineString lineString, int removeNumber, ICoordinate addCoordinate)
        {
            List <ICoordinate> vertices = new List <ICoordinate>();

            for (int i = 0; (i >= 0) && (i < lineString.Coordinates.Length - removeNumber); i++)
            {
                vertices.Add(lineString.Coordinates[i]);
            }
            if (null != addCoordinate)
            {
                vertices.Add(addCoordinate);
            }
            if (vertices.Count > 1)
            {
                return(GeometryFactory.CreateLineString(vertices.ToArray()));
            }
            return(null);
        }
예제 #29
0
파일: Map.cs 프로젝트: Sony-NS/SharpMap
        /// <summary>
        /// Initializes a new map
        /// </summary>
        /// <param name="size">Size of map in pixels</param>
        public Map(Size size)
        {
            name = "map";

            maximumZoom      = double.MaxValue;
            minimumZoom      = 0;
            center           = GeometryFactory.CreateCoordinate(0, 0);
            zoom             = 1000;
            pixelAspectRatio = 1.0;

            Size = size;

            Layers = new EventedList <ILayer>();

            BackColor            = Color.Transparent;
            mapTransform         = new Matrix();
            mapTransformInverted = new Matrix();

            UpdateDimensions();
        }
예제 #30
0
        public void AddingALayerShouldCauseZoomToExtendsIfNoValidExtendsBefore()
        {
            var map = new Map(new Size(10, 100))
            {
                Center = GeometryFactory.CreateCoordinate(90, 900)
            };

            //now add a layer with defined extends
            var geometry   = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)");
            var dataSource = new DataTableFeatureProvider(geometry);

            var vectorLayerWithExtends = new VectorLayer("Layer with extends")
            {
                DataSource = dataSource
            };

            map.Layers.Add(vectorLayerWithExtends);

            Assert.AreEqual(new Envelope(19, 41, -85, 135), map.Envelope);
        }