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)); }
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); }
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))); }
/// <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); }
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)); } }
/// <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); }
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); }
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); }
/// <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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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))); }
private void CreateNewLine() { if (newArrowLineLayer == null) { return; } newArrowLineGeometry = GeometryFactory.CreateLineString(new[] { startCoordinate, endCoordinate }); ((DataTableFeatureProvider)newArrowLineLayer.DataSource).Clear(); newArrowLineLayer.DataSource.Add(newArrowLineGeometry); }
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)); }
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); }
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); } }
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; }
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); }
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"); }
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))); }
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))); }
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); }
/// <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(); }
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); }