public static ILineString GetASecondLine() { var q1 = new Coordinate(0, 10); var q2 = new Coordinate(10, 0); var coordinatesq = new[] { q1, q2 }; var line2 = new GeometryFactory().CreateLineString(coordinatesq); return line2; }
public static ILineString GetALine() { var p1 = new Coordinate(0, 0); var p2 = new Coordinate(10, 10); var coordinatesp = new[] { p1, p2 }; var line1 = new GeometryFactory().CreateLineString(coordinatesp); return line1; }
public static void EnsureVisible(SharpMap.Map map, GeoAPI.Geometries.Coordinate pt) { const double ensureVisibleRatio = 0.1d; //Get current map envelope var bb = map.Envelope; System.Console.WriteLine(string.Format("Map envelope: {0}", bb)); //Set valid envelope var evbb = bb.Grow(- ensureVisibleRatio * bb.Width, -ensureVisibleRatio * bb.Height ); System.Console.WriteLine(string.Format("Valid envelope: {0}", evbb)); //Test if Point is in valid envelope if (evbb.Contains(pt)) return; //It is not System.Console.WriteLine(string.Format("Valid envelope does not contain {0}", pt)); //LineString from Map.Center -> to Point var ls = map.Factory.CreateLineString(new[] {evbb.Centre, pt}); System.Console.WriteLine(string.Format("LineString Map.Center -> Point: {0}", ls)); //Setup Linestring from BoundingBox var evbbpts = new [] {evbb.TopLeft(), evbb.TopRight(), evbb.BottomRight(), evbb.BottomLeft(), evbb.TopLeft() }; var evbblinearring = map.Factory.CreateLineString(evbbpts); System.Console.WriteLine(string.Format("Linestring of valid envelope: {0}", evbblinearring)); //// convert geometries to NTS //var ntsevbb = (NetTopologySuite.Geometries.LineString) // SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(evbblinearring, gf); //var ntsls = (NetTopologySuite.Geometries.LineString) // SharpMap.Converters.NTS.GeometryConverter.ToNTSGeometry(ls, gf); // Get intersection point var intGeo = evbblinearring.Intersection(ls); var intPt = (NetTopologySuite.Geometries.Point)intGeo; System.Console.WriteLine(string.Format("Intersection point is: {0}", intPt)); //Compute offset var dx = pt.X - intPt.X; var dy = pt.Y - intPt.Y; System.Console.WriteLine(string.Format("Map.Center needs to be shifted by: [{0}, {1}]", dx, dy)); //Set new center Center map.Center = new GeoAPI.Geometries.Coordinate(map.Center.X + dx, map.Center.Y + dy); }
public void Distance_CoordinateCollections() { var a = new[] { new Coordinate(5, 10), new Coordinate(19, 11), new Coordinate(6, 10.5), }; var b = new[] { new Coordinate(16, 35), new Coordinate(22, 57), new Coordinate(122, 213), }; var distance = Hausdorff.Distance(a, b); Assert.AreEqual(27.313000567495326, distance); }
private static IGeometry create_T(IGeometry g) { var gf = FunctionsUtil.getFactoryOrDefault(g); var tTop = new[] { new Coordinate(J_WIDTH, HEIGHT), new Coordinate(WIDTH - S_RADIUS - 5, HEIGHT) }; var tBottom = new[] { new Coordinate(J_WIDTH + 0.5*T_WIDTH, HEIGHT), new Coordinate(J_WIDTH + 0.5*T_WIDTH, 0) }; var lines = new[] { gf.CreateLineString(tTop), gf.CreateLineString(tBottom) }; return gf.CreateMultiLineString(lines); }
private static IGeometry create_S(IGeometry g) { var gf = FunctionsUtil.getFactoryOrDefault(g); double centreX = WIDTH - S_RADIUS; var top = new[] { new Coordinate(WIDTH, HEIGHT), new Coordinate(centreX, HEIGHT) }; var bottom = new[] { new Coordinate(centreX, 0), new Coordinate(WIDTH - 2*S_RADIUS, 0) }; var gsf = new GeometricShapeFactory(gf); gsf.Centre = new Coordinate(centreX, HEIGHT - S_RADIUS); gsf.Size = 2 * S_RADIUS; gsf.NumPoints = 10; var arcTop = gsf.CreateArc(0.5 * Math.PI, Math.PI); var gsf2 = new GeometricShapeFactory(gf); gsf2.Centre = new Coordinate(centreX, S_RADIUS); gsf2.Size = 2 * S_RADIUS; gsf2.NumPoints = 10; var arcBottom = (ILineString)((IGeometry)gsf2.CreateArc(1.5 * Math.PI, Math.PI)).Reverse(); var coordList = new CoordinateList(); coordList.Add(top, false); coordList.Add(arcTop.Coordinates, false, 1, arcTop.NumPoints - 1); coordList.Add(new Coordinate(centreX, HEIGHT / 2)); coordList.Add(arcBottom.Coordinates, false, 1, arcBottom.NumPoints - 1); coordList.Add(bottom, false); return gf.CreateLineString(coordList.ToCoordinateArray()); }
///<summary> /// Computes the transformation matrix by /// solving the two systems of linear equations /// defined by the control point mappings, /// if this is possible. /// </summary> /// <returns>True if the transformation matrix is solvable</returns> private bool Compute() { var bx = new[] { _dest0.X, _dest1.X, _dest2.X }; var row0 = Solve(bx); if (row0 == null) return false; _m00 = row0[0]; _m01 = row0[1]; _m02 = row0[2]; var by = new[] { _dest0.Y, _dest1.Y, _dest2.Y }; var row1 = Solve(by); if (row1 == null) return false; _m10 = row1[0]; _m11 = row1[1]; _m12 = row1[2]; return true; }