private IGeometry BuildGrid() { var lines = new ILineString[_numLines * 2]; int index = 0; for (int i = 0; i < _numLines; i++) { Coordinate p0 = new Coordinate(GetRandOrdinate(), 0); Coordinate p1 = new Coordinate(GetRandOrdinate(), GridWidth); ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 }); lines[index++] = line; } for (int i = 0; i < _numLines; i++) { Coordinate p0 = new Coordinate(0, GetRandOrdinate()); Coordinate p1 = new Coordinate(GridWidth, GetRandOrdinate()); ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 }); lines[index++] = line; } IMultiLineString ml = _geomFactory.CreateMultiLineString(lines); _grid = ml.Buffer(_lineWidth); var wktWriter = new WKTWriter(2) {Formatted = true, MaxCoordinatesPerLine = 6}; if (Verbose) Console.WriteLine(wktWriter.Write(_grid)); return _grid; }
public static Point[] TransformToImageI(ILineString line, Map map, bool simplifyGeometry, ref int pointCount) { var length = line.Coordinates.Length; var points = new Point[length]; points[0] = WorldtoMap(line.Coordinates[0], map); Point pt = points[0]; Point pt2 = pt; pointCount = 1; int i = 1; for (; i < length - 1; i++) { pt = WorldtoMap(line.Coordinates[i], map); if (!simplifyGeometry || Math.Abs(pt2.X - pt.X) > 0 || Math.Abs(pt2.Y - pt.Y) > 0) { points[pointCount] = pt; pointCount++; pt2 = pt; } } if (length > 1) points[pointCount++] = WorldtoMap(line.Coordinates[i], map); return points; }
public bool Intersects(Coordinate pt, ILineString ring) { var seq = ring.CoordinateSequence; var seqProj = Project(seq, _facingPlane); Coordinate ptProj = Project(pt, _facingPlane); return Location.Exterior != RayCrossingCounter.LocatePointInRing(ptProj, seqProj); }
/// <summary> /// </summary> /// <param name="line">the line to buffer</param> /// <param name="startWidth">the buffer width at the start of the line</param> /// <param name="endWidth">the buffer width at the end of the line</param> /// <returns>The variable-width buffer polygon</returns> public static IGeometry Buffer(ILineString line, double startWidth, double endWidth) { var width = Interpolate(line, startWidth, endWidth); var vb = new VariableWidthBuffer(line, width); return vb.GetResult(); }
/// <summary> /// /// </summary> /// <param name="line"></param> /// <returns></returns> public static IGeometry LineStringSelfIntersectionsOp(ILineString line) { IGeometry lineEndPts = GetEndPoints(line); IGeometry nodedLine = line.Union(lineEndPts); IGeometry nodedEndPts = GetEndPoints(nodedLine); IGeometry selfIntersections = nodedEndPts.Difference(lineEndPts); return selfIntersections; }
private static void GeometryToSqlGeometry(ILineString geom, SqlGeometryBuilder bldr) { bldr.BeginGeometry(OpenGisGeometryType.LineString); AddFigure(geom, bldr); bldr.EndGeometry(); }
private static IMultiLineString SqlGeometryToGeometryMultiLineString(SqlGeometry geometry, GeometryFactory factory) { ILineString[] lineStrings = new ILineString[geometry.STNumGeometries().Value]; for (int i = 1; i <= lineStrings.Length; i++) lineStrings[i - 1] = SqlGeometryToGeometryLineString(geometry.STGeometryN(i), factory); return factory.CreateMultiLineString(lineStrings); }
public override void StartRun(int runSize) { int nVertices = runSize*DENSIFY_FACTOR; _line1 = CreateLine("LINESTRING (0 0, 100 100)", nVertices); _line2 = CreateLine("LINESTRING (0 1, 100 99)", nVertices); // force compilation of intersects code _line1.Intersects(_line2); }
/// <summary> /// Renders a LineString to the map. /// </summary> /// <param name="g">Graphics reference</param> /// <param name="line">LineString to render</param> /// <param name="pen">Pen style used for rendering</param> /// <param name="map">Map reference</param> public static void DrawLineString(System.Drawing.Graphics g, ILineString line, System.Drawing.Pen pen, SharpMap.Map map) { if (line.Coordinates.Length > 1) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddLines(Transform.TransformToImage(line, map)); g.DrawPath(pen, gp); } }
private static void AddFigure(ILineString line, SqlGeometryBuilder bldr) { IList<Coordinate> coords = line.Coordinates; bldr.BeginFigure(coords[0].X, coords[0].Y); for (int i = 0; i < coords.Count; i++) bldr.AddLine(coords[i].X, coords[i].Y); bldr.EndFigure(); }
private void Add(ILineString lineString) { ICoordinateSequence seq = lineString.CoordinateSequence; for (int i = 1; i < seq.Count; i++) { Coordinate prev = seq.GetCoordinate(i - 1); Coordinate curr = seq.GetCoordinate(i); graph.AddEdge(prev, curr); } }
/// <summary> /// /// </summary> public LineStringSamples() : base() { ICoordinate[] coordinates = new ICoordinate[] { new Coordinate(10, 10), new Coordinate(20, 20), new Coordinate(20, 10), }; line = Factory.CreateLineString(coordinates); }
public static IGeometry angleBisectors(IGeometry g) { var pts = trianglePts(g); var cc = Triangle.InCentre(pts[0], pts[1], pts[2]); var geomFact = FunctionsUtil.getFactoryOrDefault(g); var line = new ILineString[3]; line[0] = geomFact.CreateLineString(new Coordinate[] { pts[0], cc }); line[1] = geomFact.CreateLineString(new Coordinate[] { pts[1], cc }); line[2] = geomFact.CreateLineString(new Coordinate[] { pts[2], cc }); return geomFact.CreateMultiLineString(line); }
private Coordinate[][] WriteGeom(JsonWriter writer, ILineString ls) { if (ls == null) throw new ArgumentNullException("ls"); writer.WritePropertyName("arcs"); writer.WriteStartArray(); writer.WriteValue(0); writer.WriteEndArray(); return new[] { ls.Coordinates }; }
/// <summary> /// return the coordinates along the gridProfile at stepSize intervals. /// </summary> /// <param name="gridProfile"></param> /// <param name="stepSize"></param> /// <returns></returns> public static IEnumerable<ICoordinate> GetGridProfileCoordinates(ILineString gridProfile, double stepSize) { var lengthIndexedLine = new LengthIndexedLine(gridProfile); if (0 == stepSize) throw new ArgumentException("Stepsize too small", "stepSize"); int count = (int)((gridProfile.Length / stepSize) + 1); for (int i=0; i<count; i++) { yield return (ICoordinate)lengthIndexedLine.ExtractPoint(i * stepSize).Clone(); } }
/// <summary> /// Fills gridvalues function with profiledata based on profileline over the grid /// </summary> /// <param name="function"></param> /// <param name="grid"></param> /// <param name="polyline"></param> public static void UpdateGridValues(Function function, IRegularGridCoverage grid, ILineString polyline) { function.Clear(); double offset = 0; double step = polyline.Length / 100; foreach (ICoordinate coordinate in GetGridProfileCoordinates(polyline, step)) { function[offset] = grid.Evaluate(coordinate); offset += step; } }
private static ILineString ExtractChain(ILineString line, int index, int maxChainSize) { int size = maxChainSize + 1; if (index + size > line.NumPoints) size = line.NumPoints - index; Coordinate[] pts = new Coordinate[size]; for (int i = 0; i < size; i++) { pts[i] = line.GetCoordinateN(index + i); } return line.Factory.CreateLineString(pts); }
public static IGeometry AngleBisectors(IGeometry g) { Coordinate[] pts = TrianglePts(g); Triangle t = new Triangle(pts[0], pts[1], pts[2]); Coordinate cc = t.InCentre(); IGeometryFactory geomFact = FunctionsUtil.GetFactoryOrDefault(g); ILineString[] line = new ILineString[3]; line[0] = geomFact.CreateLineString(new[] { pts[0], cc }); line[1] = geomFact.CreateLineString(new[] { pts[1], cc }); line[2] = geomFact.CreateLineString(new[] { pts[2], cc }); return geomFact.CreateMultiLineString(line); }
public static void LineStringSnapAllTrackers(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos) { for (int i = 0; i < lineString.Coordinates.Length; i++) { ICoordinate c1 = lineString.Coordinates[i]; double distance = GeometryHelper.Distance(c1.X, c1.Y, worldPos.X, worldPos.Y); if (distance >= minDistance) continue; minDistance = distance; snapResult = new SnapResult(lineString.Coordinates[i], null, lineString, i, i); } }
public static void ComputeDistance(ILineString line, Coordinate pt, PointPairDistance ptDist) { var coords = line.Coordinates; var tempSegment = new LineSegment(); for (var i = 0; i < coords.Length - 1; i++) { tempSegment.SetCoordinates(coords[i], coords[i + 1]); // this is somewhat inefficient - could do better var closestPt = tempSegment.ClosestPoint(pt); ptDist.SetMinimum(closestPt, pt); } }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); type = (ShapeGeometryType) Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) return geometryFactory.CreateMultiLineString(null); if (!(type == ShapeGeometryType.LineString || type == ShapeGeometryType.LineStringM || type == ShapeGeometryType.LineStringZ || type == ShapeGeometryType.LineStringZM)) throw new ShapefileException("Attempting to load a non-arc as arc."); // Read and for now ignore bounds. int bblength = GetBoundingBoxLength(); bbox = new double[bblength]; for (; bbindex < 4; bbindex++) { double d = file.ReadDouble(); bbox[bbindex] = d; } int numParts = file.ReadInt32(); int numPoints = file.ReadInt32(); int[] partOffsets = new int[numParts]; for (int i = 0; i < numParts; i++) partOffsets[i] = file.ReadInt32(); ILineString[] lines = new ILineString[numParts]; for (int part = 0; part < numParts; part++) { int start, finish, length; start = partOffsets[part]; if (part == numParts - 1) finish = numPoints; else finish = partOffsets[part + 1]; length = finish - start; CoordinateList points = new CoordinateList(); points.Capacity = length; for (int i = 0; i < length; i++) { double x = file.ReadDouble(); double y = file.ReadDouble(); ICoordinate external = new Coordinate(x, y); geometryFactory.PrecisionModel.MakePrecise(external); points.Add(external); } ILineString line = geometryFactory.CreateLineString(points.ToArray()); lines[part] = line; } geom = geometryFactory.CreateMultiLineString(lines); GrabZMValues(file); return geom; }
public void Setup() { factory = GeometryFactory.Fixed; a = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(100, 0), new Coordinate(200, 100), new Coordinate(200, 200), }); b = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(100, 100), new Coordinate(200, 200), }); c = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(0, 100), new Coordinate(100, 200), new Coordinate(200, 200), }); d = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(300, 0), new Coordinate(300, 200), new Coordinate(150, 200), new Coordinate(150, 300), }); e = factory.CreateLineString(new ICoordinate[] { new Coordinate(100, 300), new Coordinate(150, 300), new Coordinate(200, 300), }); result = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(300, 0), new Coordinate(300, 200), new Coordinate(150, 200), new Coordinate(150, 300), }); revresult = result.Reverse(); start = a.StartPoint; end = d.EndPoint; }
public void Render(LittleSharpRenderEngine engine, Graphics graphics, ILineString line, ILineStyle style) { if (line == null || style == null) return; System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); //TODO: Does not seems to add a single long line, but multiple line segments gp.AddLines(RenderUtil.CoordToPoint(line.Coordinates)); if (style.Outlines != null) foreach(IOutline linestyle in style.Outlines) RenderUtil.RenderOutline(engine, graphics, gp, linestyle); }
public static void LineStringSnapFreeAtObject(ref double minDistance, ref ISnapResult snapResult, IFeature feature, ILineString lineString, ICoordinate worldPos) { int vertexIndex; var nearestPoint = GeometryHelper.GetNearestPointAtLine(lineString, worldPos, minDistance, out vertexIndex); if (nearestPoint == null) { return; } minDistance = GeometryHelper.Distance(nearestPoint.X, nearestPoint.Y, worldPos.X, worldPos.Y); snapResult = new SnapResult(nearestPoint, feature, lineString, vertexIndex - 1, vertexIndex); }
/// <summary> /// Renders a LineString to the map. /// </summary> /// <param name="g">IGraphics reference</param> /// <param name="line">LineString to render</param> /// <param name="pen">Pen style used for rendering</param> /// <param name="map">Map reference</param> /// <param name="offset">Offset by which line will be moved to right</param> public void DrawLineString(IGraphics g, ILineString line, Pen pen, Map map, float offset) { var points = line.TransformToImage(map); if (points.Length > 1) { var gp = new GraphicsPath(); if (offset != 0d) points = RendererHelper.OffsetRight(points, offset); gp.AddLines(/*LimitValues(*/points/*, ExtremeValueLimit)*/); g.DrawPath(pen, gp); } }
public static IGeometry PerpendicularBisectors(IGeometry g) { Coordinate[] pts = TrianglePts(g); Coordinate cc = Triangle.Circumcentre(pts[0], pts[1], pts[2]); IGeometryFactory geomFact = FunctionsUtil.GetFactoryOrDefault(g); ILineString[] line = new ILineString[3]; Coordinate p0 = (new LineSegment(pts[1], pts[2])).ClosestPoint(cc); line[0] = geomFact.CreateLineString(new[] { p0, cc }); Coordinate p1 = (new LineSegment(pts[0], pts[2])).ClosestPoint(cc); line[1] = geomFact.CreateLineString(new[] { p1, cc }); Coordinate p2 = (new LineSegment(pts[0], pts[1])).ClosestPoint(cc); line[2] = geomFact.CreateLineString(new[] { p2, cc }); return geomFact.CreateMultiLineString(line); }
/// <summary> /// Simplifies the line with the given tolerance. /// Writes the result in file. /// </summary> /// <param name="line">Line to simplify</param> /// <param name="tolerance">Tolerance to use by simplify function</param> /// <param name="supposedResult">The supposed result</param> /// <param name="index"></param> public void Simplify(ILineString line, double tolerance, ILineString supposedResult, int index) { try { Console.WriteLine("Job {0} started", index); IGeometry geometry = TopologyPreservingSimplifier.Simplify((ILineString)line.Clone(), tolerance); Assert.IsTrue(geometry.Equals(supposedResult)); Console.WriteLine("Job {0} terminated", index); } finally { Interlocked.Increment(ref _finishedJob); } }
public static void LineStringSnapFree(ref double minDistance, ref ISnapResult snapResult, ILineString lineString, ICoordinate worldPos) { for (int i = 1; i < lineString.Coordinates.Length; i++) { ICoordinate c1 = lineString.Coordinates[i - 1]; ICoordinate c2 = lineString.Coordinates[i]; double distance = GeometryHelper.LinePointDistance(c1.X, c1.Y, c2.X, c2.Y, worldPos.X, worldPos.Y); if (distance >= minDistance) continue; minDistance = distance; snapResult = new SnapResult(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y), null, lineString, i - 1, i); } }
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> /// Converts a collection of <see cref="ISegmentString"/>s into a <see cref="IGeometry"/>. /// The geometry will be either a <see cref="ILineString"/> /// or a <see cref="IMultiLineString"/> (possibly empty). /// </summary> /// <param name="segStrings">A collection of <see cref="ISegmentString"/>.</param> /// <param name="geomFact">A geometry factory</param> /// <returns>A <see cref="ILineString"/> or a <see cref="IMultiLineString"/>.</returns> public static IGeometry ToGeometry(IList<ISegmentString> segStrings, IGeometryFactory geomFact) { ILineString[] lines = new ILineString[segStrings.Count]; int index = 0; foreach (ISegmentString ss in segStrings) { ILineString line = geomFact.CreateLineString(ss.Coordinates); lines[index++] = line; } if (lines.Length == 1) return lines[0]; return geomFact.CreateMultiLineString(lines); }
public static void DrawLineString(Graphics g, ILineString line, Pen pen, MapViewport map) { DrawLineString(g, line, pen, map, 0); }
private Dictionary <T, double> GetNewFractions(IList <int> trackerIndices, ILineString newLineString) { var newFractions = BranchToBranchFeatureService.UpdateNewFractions(originalBranchGeometry, newLineString, fractionLookUp.Values.ToList(), trackerIndices, FallOffPolicy); return(fractionLookUp.Keys.Zip(newFractions).ToDictionary(f => f.First, f => f.Second)); }
public ILineString Transform(ILineString g) { return(new LineString(Transform(g.Coordinates))); }
/// <summary> /// Saves the file to a new location /// </summary> /// <param name="fileName">The fileName to save</param> /// <param name="overwrite">Boolean that specifies whether or not to overwrite the existing file</param> public override void SaveAs(string fileName, bool overwrite) { EnsureValidFileToSave(fileName, overwrite); Filename = fileName; // Set ShapeType before setting header. if (CoordinateType == CoordinateType.Regular) { Header.ShapeType = ShapeType.PolyLine; } if (CoordinateType == CoordinateType.M) { Header.ShapeType = ShapeType.PolyLineM; } if (CoordinateType == CoordinateType.Z) { Header.ShapeType = ShapeType.PolyLineZ; } HeaderSaveAs(fileName); if (IndexMode) { SaveAsIndexed(Filename); return; } var bbWriter = new BufferedBinaryWriter(Filename); var indexWriter = new BufferedBinaryWriter(Header.ShxFilename); int fid = 0; int offset = 50; // the shapefile header starts at 100 bytes, so the initial offset is 50 words int contentLength = 0; foreach (IFeature f in Features) { List <int> parts = new List <int>(); offset += contentLength; // adding the previous content length from each loop calculates the word offset List <Coordinate> points = new List <Coordinate>(); contentLength = 22; for (int iPart = 0; iPart < f.Geometry.NumGeometries; iPart++) { parts.Add(points.Count); ILineString bl = f.Geometry.GetGeometryN(iPart) as ILineString; if (bl == null) { continue; } points.AddRange(bl.Coordinates); } contentLength += 2 * parts.Count; if (Header.ShapeType == ShapeType.PolyLine) { contentLength += points.Count * 8; // x, y } if (Header.ShapeType == ShapeType.PolyLineM) { contentLength += 8; // mmin mmax contentLength += points.Count * 12; // x, y, m } if (Header.ShapeType == ShapeType.PolyLineZ) { contentLength += 16; // mmin, mmax, zmin, zmax contentLength += points.Count * 16; // x, y, z, m } // Index File // --------------------------------------------------------- // Position Value Type Number Byte Order // --------------------------------------------------------- indexWriter.Write(offset, false); // Byte 0 Offset Integer 1 Big indexWriter.Write(contentLength, false); // Byte 4 Content Length Integer 1 Big // X Y Poly Lines // --------------------------------------------------------- // Position Value Type Number Byte Order // ------------------------------------------------------- bbWriter.Write(fid + 1, false); // Byte 0 Record Number Integer 1 Big bbWriter.Write(contentLength, false); // Byte 4 Content Length Integer 1 Big bbWriter.Write((int)Header.ShapeType); // Byte 8 Shape Type 3 Integer 1 Little if (Header.ShapeType == ShapeType.NullShape) { continue; } Envelope env = f.Geometry.EnvelopeInternal ?? new Envelope(); bbWriter.Write(env.MinX); // Byte 12 Xmin Double 1 Little bbWriter.Write(env.MinY); // Byte 20 Ymin Double 1 Little bbWriter.Write(env.MaxX); // Byte 28 Xmax Double 1 Little bbWriter.Write(env.MaxY); // Byte 36 Ymax Double 1 Little bbWriter.Write(parts.Count); // Byte 44 NumParts Integer 1 Little bbWriter.Write(points.Count); // Byte 48 NumPoints Integer 1 Little // Byte 52 Parts Integer NumParts Little foreach (int iPart in parts) { bbWriter.Write(iPart); } double[] xyVals = new double[points.Count * 2]; for (int ipoint = 0; ipoint < points.Count; ipoint++) { //double[] c = points[ipoint]; xyVals[ipoint * 2] = points[ipoint][Ordinate.X]; xyVals[ipoint * 2 + 1] = points[ipoint][Ordinate.Y]; } bbWriter.Write(xyVals); if (Header.ShapeType == ShapeType.PolyLineZ) { if (f.Geometry.EnvelopeInternal != null) { bbWriter.Write(f.Geometry.EnvelopeInternal.Minimum.Z); bbWriter.Write(f.Geometry.EnvelopeInternal.Maximum.Z); } double[] zVals = new double[points.Count]; for (int ipoint = 0; ipoint < points.Count; ipoint++) { zVals[ipoint] = points[ipoint].Z; } bbWriter.Write(zVals); } if (Header.ShapeType == ShapeType.PolyLineM || Header.ShapeType == ShapeType.PolyLineZ) { if (f.Geometry.EnvelopeInternal == null) { bbWriter.Write(0.0); bbWriter.Write(0.0); } else { bbWriter.Write(f.Geometry.EnvelopeInternal.Minimum.M); bbWriter.Write(f.Geometry.EnvelopeInternal.Maximum.M); } double[] mVals = new double[points.Count]; for (int ipoint = 0; ipoint < points.Count; ipoint++) { mVals[ipoint] = points[ipoint].M; } bbWriter.Write(mVals); } fid++; offset += 4; // header bytes } bbWriter.Close(); indexWriter.Close(); offset += contentLength; //offset += 4; WriteFileLength(Filename, offset); WriteFileLength(Header.ShxFilename, 50 + fid * 4); UpdateAttributes(); SaveProjection(); }
/// <summary> /// /// </summary> /// <param name="geom"></param> /// <param name="parent"></param> /// <returns></returns> protected virtual IGeometry TransformLineString(ILineString geom, IGeometry parent) { // should check for 1-point sequences and downgrade them to points return(Factory.CreateLineString(TransformCoordinates(geom.CoordinateSequence, geom))); }
/// <summary> /// Creates a new snapper using the points in the given {@link LineString} /// as target snap points. /// </summary> /// <param name="line"></param> /// <param name="snapTolerance"></param> public LineStringSnapper(ILineString line, double snapTolerance) : this(line.Coordinates, snapTolerance) { }
public ILineString ReverseTransform(ILineString g) { return(new LineString(ReverseTransform(g.Coordinates))); }
public static void SetOsmId(this ILineString lineString, string id) { lineString.UserData = id; }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); type = (ShapeGeometryType)Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) { return(geometryFactory.CreateMultiLineString(null)); } if (!(type == ShapeGeometryType.LineString || type == ShapeGeometryType.LineStringM || type == ShapeGeometryType.LineStringZ || type == ShapeGeometryType.LineStringZM)) { throw new ShapefileException("Attempting to load a non-arc as arc."); } // Read and for now ignore bounds. int bblength = GetBoundingBoxLength(); bbox = new double[bblength]; for (; bbindex < 4; bbindex++) { double d = file.ReadDouble(); bbox[bbindex] = d; } int numParts = file.ReadInt32(); int numPoints = file.ReadInt32(); int[] partOffsets = new int[numParts]; for (int i = 0; i < numParts; i++) { partOffsets[i] = file.ReadInt32(); } ILineString[] lines = new ILineString[numParts]; for (int part = 0; part < numParts; part++) { int start, finish, length; start = partOffsets[part]; if (part == numParts - 1) { finish = numPoints; } else { finish = partOffsets[part + 1]; } length = finish - start; CoordinateList points = new CoordinateList(); points.Capacity = length; for (int i = 0; i < length; i++) { double x = file.ReadDouble(); double y = file.ReadDouble(); ICoordinate external = new Coordinate(x, y); geometryFactory.PrecisionModel.MakePrecise(external); points.Add(external); } ILineString line = geometryFactory.CreateLineString(points.ToArray()); lines[part] = line; } geom = geometryFactory.CreateMultiLineString(lines); GrabZMValues(file); return(geom); }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="coordinateSpace">The size needed for each coordinate</param> /// <returns></returns> protected int GetByteStreamSize(ILineString geometry, int coordinateSpace) { return(GetByteStreamSize(geometry.CoordinateSequence, coordinateSpace)); }
/// <summary> /// /// </summary> /// <param name="lineString"></param> /// <param name="ordinates"></param> /// <param name="byteOrder">The byte order.</param> /// <param name="writer"></param> private void Write(ILineString lineString, Ordinates ordinates, ByteOrder byteOrder, BinaryWriter writer) { WriteHeader(PostGisGeometryType.LineString, HandleSRID ? lineString.SRID : -1, ordinates, byteOrder, writer); Write(lineString.CoordinateSequence, ordinates, writer, false); }
/// <summary> /// /// </summary> /// <param name="line"></param> /// <returns></returns> public Edge FindEdge(ILineString line) { return _lineEdgeMap[line]; }
/// <summary> /// Transforms a <see cref="ILineString"/> to an array of <see cref="PointF"/>s. /// </summary> /// <param name="self">The linestring</param> /// <param name="map">The map that defines the affine coordinate transformation</param> /// <returns>The array of <see cref="PointF"/>s</returns> public static PointF[] TransformToImage(this ILineString self, MapViewport map) { return(TransformToImage(self.Coordinates, map)); }
/// <summary> /// Function that actually renders the linestring /// </summary> /// <param name="map">The map</param> /// <param name="lineString">The line string to symbolize.</param> /// <param name="graphics">The graphics</param> protected abstract void OnRenderInternal(MapViewport map, ILineString lineString, Graphics graphics);
/// <summary> /// Clips a <see cref="ILineString"/> to the bounding box defined by <see cref="CohenSutherlandLineClipping(double,double,double,double)"/>. /// </summary> /// <param name="lineString">The line string to clip</param> /// <returns>A (possibly multi) line string</returns> public IMultiLineString ClipLineString(ILineString lineString) { //Factory var factory = lineString.Factory; //List of line strings that make up the multi line string result var lineStrings = new List <ILineString>(); //list of clipped vertices for current pass var clippedVertices = new List <Coordinate>(); //vertices of current line string var vertices = new List <Coordinate>(lineString.Coordinates); var count = vertices.Count; //Compute starting clipcode double x0, y0; OutsideClipCodes oc0Initial; var oc0 = oc0Initial = ComputeClipCode(vertices[0], out x0, out y0); //Point is inside => add it to the list if (oc0 == OutsideClipCodes.Inside) { clippedVertices.Add(vertices[0]); } double x1Old = double.NaN, y1Old = double.NaN; for (var i = 1; i < count; i++) { double x1, y1; OutsideClipCodes oc1Initial; var oc1 = oc1Initial = ComputeClipCode(vertices[i], out x1, out y1); var x1Orig = x1; var y1Orig = y1; var accept = false; while (true) { if ((oc0 | oc1) == OutsideClipCodes.Inside) { // Bitwise OR is 0. Trivially accept and get out of loop accept = true; break; } if ((oc0 & oc1) != OutsideClipCodes.Inside) { // Bitwise AND is not 0. Trivially reject and get out of loop break; } // failed both tests, so calculate the line segment to clip // from an outside point to an intersection with clip edge double x = double.NaN, y = double.NaN; // At least one endpoint is outside the clip rectangle; pick it. var ocOut = oc0 != OutsideClipCodes.Inside ? oc0 : oc1; // Now find the intersection point; // use formulas y = y0 + slope * (x - x0), x = x0 + (1 / slope) * (y - y0) if ((ocOut & OutsideClipCodes.Top) == OutsideClipCodes.Top) { // point is above the clip rectangle x = x0 + (x1 - x0) * (_ymax - y0) / (y1 - y0); y = _ymax; } else if ((ocOut & OutsideClipCodes.Bottom) == OutsideClipCodes.Bottom) { // point is below the clip rectangle x = x0 + (x1 - x0) * (_ymin - y0) / (y1 - y0); y = _ymin; } else if ((ocOut & OutsideClipCodes.Right) == OutsideClipCodes.Right) { // point is to the right of clip rectangle y = y0 + (y1 - y0) * (_xmax - x0) / (x1 - x0); x = _xmax; } else if ((ocOut & OutsideClipCodes.Left) == OutsideClipCodes.Left) { // point is to the left of clip rectangle y = y0 + (y1 - y0) * (_xmin - x0) / (x1 - x0); x = _xmin; } // Now we move outside point to intersection point to clip // and get ready for next pass. if (oc0 == ocOut) { x0 = x; y0 = y; oc0 = ComputeClipCode(x, y); } else { x1 = x; y1 = y; oc1 = ComputeClipCode(x, y); } } if (accept) { if (oc0Initial != oc0) { clippedVertices.Add(new Coordinate(x0, y0)); } if (x1Old != x1 || y1Old != y1) { clippedVertices.Add(new Coordinate(x1, y1)); } if (oc1Initial != OutsideClipCodes.Inside) { if (clippedVertices.Count > 0) { lineStrings.Add(factory.CreateLineString(clippedVertices.ToArray())); clippedVertices = new List <Coordinate>(); } } } x0 = x1Old = x1Orig; y0 = y1Old = y1Orig; oc0 = oc0Initial = oc1Initial; } if (clippedVertices.Count > 0) { lineStrings.Add(factory.CreateLineString(clippedVertices.ToArray())); } return(factory.CreateMultiLineString(lineStrings.ToArray())); }
private static bool HasSameStartAndEndPoint(ILineString lineString1, ILineString lineString2) { return((lineString1.StartPoint.Equals(lineString2.StartPoint) && lineString1.EndPoint.Equals(lineString2.EndPoint)) || (lineString1.StartPoint.Equals(lineString2.EndPoint) && lineString1.EndPoint.Equals(lineString2.StartPoint))); }
private void DrawMeasure(Graphics graphics, IGeometry geometry, StringCollection text) { string measureUnits = _appSettings.MeasureUnits; bool inFeet = measureUnits == "feet" || measureUnits == "both"; bool inMeters = measureUnits == "meters" || measureUnits == "both"; System.Drawing.Font font = _appSettings.MeasureFont; font = new System.Drawing.Font(font.FontFamily, Convert.ToSingle(font.Size * _resolution), font.Style, font.Unit); SolidBrush brush = new SolidBrush(Color.FromArgb(64, 64, 64)); SolidBrush glowBrush = new SolidBrush(Color.White); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; double convert = 1 / (_appSettings.MapUnits == "feet" ? 1 : Constants.MetersPerFoot); switch (geometry.OgcGeometryType) { case OgcGeometryType.LineString: ILineString lineString = (ILineString)geometry; if (text.Count == 0) { double d; if (_appSettings.MapCoordinateSystem.Equals(_appSettings.MeasureCoordinateSystem)) { d = lineString.Length * convert; } else { ILineString measureLineString = _appSettings.MapCoordinateSystem.ToGeodetic(lineString); measureLineString = _appSettings.MeasureCoordinateSystem.ToProjected(measureLineString); convert = 1 / (_appSettings.MeasureCoordinateSystem.MapUnits == "feet" ? 1 : Constants.MetersPerFoot); d = measureLineString.Length * convert; } if (inFeet) { text.Add(d < 5280 ? d.ToString("0") + " ft" : (d / 5280).ToString("0.0") + " mi"); } if (inMeters) { d *= Constants.MetersPerFoot; text.Add(d < 1000 ? d.ToString("0") + " m" : (d / 1000).ToString("0.0") + " km"); } } IPoint p; double angle; GetMidpoint(lineString, out p, out angle); angle = -(angle * 180 / Math.PI); angle = angle < -90 || 90 < angle ? angle + 180 : angle < 0 ? angle + 360 : angle; p = _transform.ReverseTransform(p); float x = Convert.ToSingle(p.Coordinate.X * _resolution); float y = Convert.ToSingle(p.Coordinate.Y * _resolution); format.LineAlignment = StringAlignment.Far; int[] pos = new int[] { 0, 1, 2, 3, 5, 6, 7, 8, 4 }; for (int i = 0; i < 9; ++i) { float offsetX = (pos[i] % 3) - 1; float offsetY = Convert.ToSingle(Math.Floor(pos[i] / 3.0)) - 1; System.Drawing.Drawing2D.GraphicsState state = graphics.Save(); graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; graphics.TranslateTransform(x, y); graphics.RotateTransform(Convert.ToSingle(angle)); graphics.DrawString(text.Join("\n"), font, i < 8 ? glowBrush : brush, Convert.ToSingle(offsetX * _resolution), Convert.ToSingle(offsetY - 3 * _resolution), format); graphics.Restore(state); } break; case OgcGeometryType.Polygon: IPolygon polygon = (IPolygon)geometry; IPoint c = polygon.Centroid; if (c != null) { double a; if (_appSettings.MapCoordinateSystem.Equals(_appSettings.MeasureCoordinateSystem)) { a = polygon.Area * convert * convert; } else { IPolygon measurePolygon = _appSettings.MapCoordinateSystem.ToGeodetic(polygon); measurePolygon = _appSettings.MeasureCoordinateSystem.ToProjected(measurePolygon); convert = 1 / (_appSettings.MeasureCoordinateSystem.MapUnits == "feet" ? 1 : Constants.MetersPerFoot); a = measurePolygon.Area * convert * convert; } double acres = a / Constants.SquareFeetPerAcre; if (inFeet) { double squareMile = Constants.FeetPerMile * Constants.FeetPerMile; text.Add(a <= squareMile ? a.ToString("0") + " sq ft" : (a / squareMile).ToString("0.00") + " sq mi"); } if (inMeters) { a *= Constants.MetersPerFoot * Constants.MetersPerFoot; text.Add(a <= 100000 ? a.ToString("0") + " sq m" : (a / 1000000).ToString("0.00") + " sq km"); } if (inFeet) { text.Add(acres.ToString("0.00") + " acres"); } DrawText(graphics, c, text.Join("\n"), font, brush, glowBrush, 0, 0, format); } break; } }
private void setMinCha(IFeature feature) { ILineString minLine = MinPoints.getMinVector(feature); AngleProperty property = new AngleProperty(feature); foreach (var line in property.Lines) { //int le = line.Intersection(feature.Geometry.Boundary).NumPoints; //if (le>1) //{ // for (int i = 0; i < le-1; i++) // { // double index = (line.Coordinates[i].Distance(line.Coordinates[i+1]) ); // /* minLine.Coordinates[1]*/ // //-line.Intersection(feature.Geometry).Coordinates[0].Distance(line.Coordinates[1]) // MinCha.Add(index);//最小差 // } //} //else //{ double index = (line.Length); /* line.Coordinates[1].Distance(line.Coordinates[0]) - line.Intersection(feature.Geometry).Coordinates[0].Distance(line.Coordinates[0])*/ /* minLine.Coordinates[1]*/ MinCha.Add(index);//最小差 //} } #region //ILineString minLine = MinPoints.getMinVector(feature); //AngleProperty property = new AngleProperty(feature); //foreach (var line in property.Lines) //{ // if (line.Intersection(feature.Geometry.Boundary).NumPoints == 2) // { // line.Intersection(feature.Geometry.Boundary).Coordinates[0].X -= feature.Geometry.Centroid.Coordinate.X; // line.Intersection(feature.Geometry.Boundary).Coordinates[0].Y -= feature.Geometry.Centroid.Coordinate.Y; // line.Intersection(feature.Geometry.Boundary).Coordinates[1].X -= feature.Geometry.Centroid.Coordinate.X; // line.Intersection(feature.Geometry.Boundary).Coordinates[1].Y -= feature.Geometry.Centroid.Coordinate.Y; // if (AngleProperty.getAngle(line.Intersection(feature.Geometry.Boundary).Coordinates[0]) > 90 && AngleProperty.getAngle(line.Intersection(feature.Geometry.Boundary).Coordinates[0]) < 270) // { // Index index1 = new Index(line.Coordinates[0].Distance(line.Intersection(feature.Geometry.Boundary).Coordinates[1]) - minLine.Coordinates[1].Distance(minLine.Coordinates[0]), "最小差"); // MinCha.Add(index1); // } // else if (AngleProperty.getAngle(line.Intersection(feature.Geometry.Boundary).Coordinates[0]) > 0 && AngleProperty.getAngle(line.Intersection(feature.Geometry.Boundary).Coordinates[0]) < 90||AngleProperty.getAngle(line.Intersection(feature.Geometry.Boundary).Coordinates[0])>270&& AngleProperty.getAngle(line.Intersection(feature.Geometry.Boundary).Coordinates[0])<360) // { // Index index1 = new Index(line.Coordinates[0].Distance(line.Intersection(feature.Geometry.Boundary).Coordinates[0]) - minLine.Coordinates[1].Distance(minLine.Coordinates[0]), "最小差"); // MinCha.Add(index1); // } // } // else if (line.Intersection(feature.Geometry.Boundary).NumPoints == 1 || line.Intersection(feature.Geometry.Boundary).NumPoints == 0) // { // Index index = new Index(line.Coordinates[1].Distance(line.Coordinates[0]) - minLine.Coordinates[1].Distance(minLine.Coordinates[0]), "最小差"); // MinCha.Add(index); // } // //else // //{ // // Console.WriteLine("交点超过三个,请检查小班"); // //} //} #endregion }
private static BaseLabel CreatePathLabel(ILineString line, string text, SizeF textMeasure, int priority, LabelStyle style, MapViewport map) { if (line == null) { return(null); } var factory = line.Factory; // Simplify the line for smoother labeling double avgCharacterSpace = 2d * textMeasure.Width / text.Length * map.PixelWidth; var simplifier = new NetTopologySuite.Simplify.VWLineSimplifier(line.Coordinates, avgCharacterSpace); line = factory.CreateLineString(simplifier.Simplify()); var labelLength = textMeasure.Width * map.PixelWidth; var labelHeight = textMeasure.Height * map.PixelHeight; var offsetX = style.Offset.X * map.PixelWidth; // positive = increasing measure var offsetY = style.Offset.Y * map.PixelHeight; // positive = right side of line var start = 0d; if (style.HorizontalAlignment == LabelStyle.HorizontalAlignmentEnum.Center) { start = line.Length * 0.5 - labelLength * 0.5; } else if (style.HorizontalAlignment == LabelStyle.HorizontalAlignmentEnum.Right) { start = line.Length - labelLength; } start += offsetX; // Constrain label length if (labelLength > 0.95 * line.Length && !style.IgnoreLength || start + labelLength < 0 || start > line.Length) { return(null); } // LengthIndexedLine idea courtesy FObermaier NetTopologySuite.LinearReferencing.LengthIndexedLine lil; // optimize for detailed lines (eg labelling rivers at continental level) // ratio and NumPoints based on instinct.... feel free to revise var mid = start + labelLength / 2.0; if (labelLength / line.Length < 0.5 && line.NumPoints > 200 && mid >= 0 && mid < line.Length) { lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(line); var midPt = lil.ExtractPoint(mid); // extract slightly more than label length to ensure offsetCurve follows line geometry var halfLen = labelLength * 0.6; // ensure non-negative indexes constrained to line length (due to special LengthIndexLine functionality) line = (LineString)lil.ExtractLine(Math.Max(0, mid - halfLen), Math.Min(mid + halfLen, line.Length)); // reset start lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(line); mid = lil.IndexOf(midPt); start = mid - labelLength / 2.0; } // basic extend var end = start + labelLength; if (start < 0 || end > line.Length) { line = ExtendLine(line, start <0 ? -1 * start : 0, end> line.Length ? end - line.Length : 0); start = 0; end = start + labelLength; } lil = new NetTopologySuite.LinearReferencing.LengthIndexedLine(line); // reverse var startPt = lil.ExtractPoint(start); var endPt = lil.ExtractPoint(end); if (LineNeedsReversing(startPt, endPt, false, map)) { start = end; end = start - labelLength; } line = (ILineString)lil.ExtractLine(start, end); // Build offset curve ILineString offsetCurve; var bufferParameters = new NetTopologySuite.Operation.Buffer.BufferParameters(4, GeoAPI.Operation.Buffer.EndCapStyle.Flat); // determine offset curve that will run through the vertical centre of the text if (style.VerticalAlignment != LabelStyle.VerticalAlignmentEnum.Middle) { var ocb = new NetTopologySuite.Operation.Buffer.OffsetCurveBuilder(factory.PrecisionModel, bufferParameters); // Left side positive var offsetCurvePoints = ocb.GetOffsetCurve(line.Coordinates, ((int)style.VerticalAlignment - 1) * 0.5 * labelHeight - offsetY); offsetCurve = factory.CreateLineString(offsetCurvePoints); } else { offsetCurve = line; } // basic extend var ratio = labelLength / offsetCurve.Length; if (ratio > 1.01) { var diff = labelLength - offsetCurve.Length; offsetCurve = ExtendLine(offsetCurve, diff / 2d, diff / 2d); } // enclosing polygon in world coords var affectedArea = (IPolygon)offsetCurve.Buffer(0.5d * labelHeight, bufferParameters); // fast, basic check (technically should use polygons for rotated views) if (!map.Envelope.Contains(affectedArea.EnvelopeInternal)) { return(null); } // using labelBox to pass text height to WarpedPath return(new PathLabel(text, LineStringToPath(offsetCurve, map), 0, priority, new LabelBox(0, 0, textMeasure.Width, textMeasure.Height), style) { AffectedArea = affectedArea }); }
/// <summary> /// Determines whether two polylines defined by series of coordinates intersects. /// </summary> /// <param name="line1">The first polyline to test.</param> /// <param name="line2">The second polyline to test.</param> /// <returns>true if polylines intersets, otherwise false.</returns> public bool Intersects(ILineString line1, ILineString line2) { return(this.GeometryLocator.Intersects(line1.Coordinates, line2.Coordinates)); }
/// <summary> /// /// </summary> /// <param name="line"></param> /// <returns></returns> public Edge FindEdge(ILineString line) { return((Edge)lineEdgeMap[line]); }
/// <summary> /// /// </summary> /// <param name="line"></param> public PolygonizeEdge(ILineString line) { this.line = line; }
/// <summary> /// Determines whether specific Coordinate is on the given polyline. /// </summary> /// <param name="c">The coordinate to check.</param> /// <param name="line">The line to check coordinate against.</param> /// <returns>true if coordinate lies on the polyline, otherwise false.</returns> public bool IsOnLine(Coordinate c, ILineString line) { return(this.GeometryLocator.IsOnLine(c, line.Coordinates)); }
/// <summary> /// /// </summary> /// <param name="lineString"></param> /// <param name="writer"></param> protected void Write(ILineString lineString, XmlTextWriter writer) { writer.WriteStartElement(GMLElements.gmlPrefix, "LineString", GMLElements.gmlNS); WriteCoordinates(lineString.Coordinates, writer); writer.WriteEndElement(); }
/// <summary> /// Converts a <c>LineString</c> to <LineString Tagged Text /// format, then appends it to the writer. /// </summary> /// <param name="lineString">The <c>LineString</c> to process.</param> /// <param name="level"></param> /// <param name="writer">The output writer to append to.</param> private void AppendLineStringTaggedText(ILineString lineString, int level, TextWriter writer) { writer.Write("LINESTRING "); AppendLineStringText(lineString, level, false, writer); }
private static void CalculateLabelAroundOnLineString(ILineString line, ref BaseLabel label, MapViewport map, System.Drawing.Graphics g, System.Drawing.SizeF textSize) { var sPoints = line.Coordinates; // only get point in enverlop of map var colPoint = new Collection <PointF>(); var bCheckStarted = false; //var testEnvelope = map.Envelope.Grow(map.PixelSize*10); for (var j = 0; j < sPoints.Length; j++) { if (map.Envelope.Contains(sPoints[j])) { //points[j] = map.WorldToImage(sPoints[j]); colPoint.Add(map.WorldToImage(sPoints[j])); bCheckStarted = true; } else if (bCheckStarted) { // fix bug curved line out of map in center segment of line break; } } if (colPoint.Count > 1) { label.TextOnPathLabel = new TextOnPath(); switch (label.Style.HorizontalAlignment) { case LabelStyle.HorizontalAlignmentEnum.Left: label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Left; break; case LabelStyle.HorizontalAlignmentEnum.Right: label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Right; break; case LabelStyle.HorizontalAlignmentEnum.Center: label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Center; break; default: label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Center; break; } switch (label.Style.VerticalAlignment) { case LabelStyle.VerticalAlignmentEnum.Bottom: label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.UnderPath; break; case LabelStyle.VerticalAlignmentEnum.Top: label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.OverPath; break; case LabelStyle.VerticalAlignmentEnum.Middle: label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.CenterPath; break; default: label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.CenterPath; break; } var idxStartPath = 0; var numberPoint = colPoint.Count; // start Optimzes Path points var step = 100; if (colPoint.Count >= step * 2) { numberPoint = step * 2;; switch (label.Style.HorizontalAlignment) { case LabelStyle.HorizontalAlignmentEnum.Left: //label.TextOnPathLabel.TextPathAlignTop = Gisoft.SharpMap.Rendering.TextPathAlign.Left; idxStartPath = 0; break; case LabelStyle.HorizontalAlignmentEnum.Right: //label.TextOnPathLabel.TextPathAlignTop = Gisoft.SharpMap.Rendering.TextPathAlign.Right; idxStartPath = colPoint.Count - step; break; case LabelStyle.HorizontalAlignmentEnum.Center: //label.TextOnPathLabel.TextPathAlignTop = Gisoft.SharpMap.Rendering.TextPathAlign.Center; idxStartPath = (int)colPoint.Count / 2 - step; break; default: //label.TextOnPathLabel.TextPathAlignTop = Gisoft.SharpMap.Rendering.TextPathAlign.Center; idxStartPath = (int)colPoint.Count / 2 - step; break; } } // end optimize path point var points = new PointF[numberPoint]; var count = 0; if (colPoint[0].X <= colPoint[colPoint.Count - 1].X) { for (var l = idxStartPath; l < numberPoint + idxStartPath; l++) { points[count] = colPoint[l]; count++; } } else { //reverse the path for (var k = numberPoint - 1 + idxStartPath; k >= idxStartPath; k--) { points[count] = colPoint[k]; count++; } } /* * //get text size in page units ie pixels * float textheight = label.Style.Font.Size; * switch (label.Style.Font.Unit) * { * case GraphicsUnit.Display: * textheight = textheight * g.DpiY / 75; * break; * case GraphicsUnit.Document: * textheight = textheight * g.DpiY / 300; * break; * case GraphicsUnit.Inch: * textheight = textheight * g.DpiY; * break; * case GraphicsUnit.Millimeter: * textheight = (float)(textheight / 25.4 * g.DpiY); * break; * case GraphicsUnit.Pixel: * //do nothing * break; * case GraphicsUnit.Point: * textheight = textheight * g.DpiY / 72; * break; * } * var topFont = new Font(label.Style.Font.FontFamily, textheight, label.Style.Font.Style, GraphicsUnit.Pixel); */ var topFont = label.Style.GetFontForGraphics(g); // var path = new GraphicsPath(); path.AddLines(points); label.TextOnPathLabel.PathColorTop = System.Drawing.Color.Transparent; label.TextOnPathLabel.Text = label.Text; label.TextOnPathLabel.LetterSpacePercentage = 90; label.TextOnPathLabel.FillColorTop = new System.Drawing.SolidBrush(label.Style.ForeColor); label.TextOnPathLabel.Font = topFont; label.TextOnPathLabel.PathDataTop = path.PathData; label.TextOnPathLabel.Graphics = g; //label.TextOnPathLabel.ShowPath=true; //label.TextOnPathLabel.PathColorTop = System.Drawing.Color.YellowGreen; if (label.Style.Halo != null) { label.TextOnPathLabel.ColorHalo = label.Style.Halo; } else { label.TextOnPathLabel.ColorHalo = null;// new System.Drawing.Pen(label.Style.ForeColor, (float)0.5); } path.Dispose(); // MeasureString to get region label.TextOnPathLabel.MeasureString = true; label.TextOnPathLabel.DrawTextOnPath(); label.TextOnPathLabel.MeasureString = false; // Get Region label for CollissionDetection here. var pathRegion = new GraphicsPath(); if (label.TextOnPathLabel.RegionList.Count > 0) { //int idxCenter = (int)label.TextOnPathLabel.PointsText.Count / 2; //System.Drawing.Drawing2D.Matrix rotationMatrix = g.Transform.Clone();// new Matrix(); //rotationMatrix.RotateAt(label.TextOnPathLabel.Angles[idxCenter], label.TextOnPathLabel.PointsText[idxCenter]); //if (label.TextOnPathLabel.PointsTextUp.Count > 0) //{ // for (int up = label.TextOnPathLabel.PointsTextUp.Count - 1; up >= 0; up--) // { // label.TextOnPathLabel.PointsText.Add(label.TextOnPathLabel.PointsTextUp[up]); // } //} pathRegion.AddRectangles(label.TextOnPathLabel.RegionList.ToArray()); // get box for detect colission here label.Box = new LabelBox(pathRegion.GetBounds()); //g.FillRectangle(System.Drawing.Brushes.YellowGreen, label.Box); } pathRegion.Dispose(); } }
public static string GetOsmId(this ILineString lineString) { return(lineString.UserData.ToString()); }
private static void WriteLineString(ILineString geometry, PostGis2GeometryHeader pgh, BinaryWriter writer) { writer.Write((uint)PostGis2GeometryType.LineString); WriteSequence(geometry.CoordinateSequence, pgh, writer, -1); }
private IGeometry PrimitiveCoordinateMapper(IGeometry geom) { if (geom is IPoint) { return(new Topology.Geometries.Point(PrimitiveCoordinateMapper(geom.Coordinates)[0])); } else if (geom is IMultiPoint) { IGeometry[] input = (geom as IMultiLineString).Geometries; IPoint[] output = new IPoint[input.Length]; for (int i = 0; i < input.Length; i++) { output[i] = (IPoint)PrimitiveCoordinateMapper(input[i]); } return(new MultiPoint(output)); } else if (geom is ILineString) { return(new LineString(PrimitiveCoordinateMapper(geom.Coordinates))); } else if (geom is ILinearRing) { return(new LinearRing(PrimitiveCoordinateMapper(geom.Coordinates))); } else if (geom is IMultiLineString) { IGeometry[] input = (geom as IMultiLineString).Geometries; ILineString[] output = new ILineString[input.Length]; for (int i = 0; i < input.Length; i++) { output[i] = (ILineString)PrimitiveCoordinateMapper(input[i]); } return(new MultiLineString(output)); } else if (geom is IPolygon) { ILineString shell = (ILineString)PrimitiveCoordinateMapper(((IPolygon)geom).Shell); ILineString[] input = (geom as IPolygon).Holes; ILinearRing[] output = new ILinearRing[input.Length]; for (int i = 0; i < input.Length; i++) { output[i] = new LinearRing(((ILineString)PrimitiveCoordinateMapper(input[i])).Coordinates); } return(new Polygon(new LinearRing(shell.Coordinates), output)); } else if (geom is IMultiPolygon) { IGeometry[] input = (geom as IMultiPolygon).Geometries; IPolygon[] output = new IPolygon[input.Length]; for (int i = 0; i < input.Length; i++) { output[i] = (IPolygon)PrimitiveCoordinateMapper(input[i]); } return(new MultiPolygon(output)); } else if (geom is IGeometryCollection) { IGeometry[] input = (geom as IGeometryCollection).Geometries; IGeometry[] output = new IGeometry[input.Length]; for (int i = 0; i < input.Length; i++) { output[i] = PrimitiveCoordinateMapper(input[i]); } return(new GeometryCollection(output)); } else { return(null); } }
/// <summary> /// Converts a <see cref="ILineString"/> to a <see cref="GeoAPILineString"/> /// </summary> /// <param name="self">The <see cref="ILineString"/> to convert</param> /// <param name="factory">The factory to create the <see cref="GeoAPILineString"/></param> /// <param name="setUserData">Sets the <see cref="GeoAPIGeometry.UserData"/> to <paramref name="self"/>.UserData</param> /// <returns>The converted geometry</returns> public static GeoAPILineString ToGeoAPI(this ILineString self, GeoAPIGeometryFactory factory = null, bool setUserData = false) { var useFactory = factory ?? self.Factory.ToGeoAPI(); return(FromLineString(self, useFactory, setUserData)); }