public void LineWrite(VectorFeature feat, double[] fractionalpt, double distance) { // Get the row and col of the cell we're looking for int[] rowcol = OpExtent.Pt2RowCol(fractionalpt); int fid = (int)feat.Feat.GetFID(); List <string> csvRows = new List <string>(); double finalDist = Math.Round(distance, _spacingDecimals); // Now we write a line to the file List <string> csvcols = new List <string>(); foreach (ECols item in header) { switch (item) { case (ECols.FID): csvcols.Add(fid.ToString(CultureInfo.InvariantCulture)); break; case (ECols.X): csvcols.Add((fractionalpt[0]).ToString(CultureInfo.InvariantCulture)); break; case (ECols.Y): csvcols.Add((fractionalpt[1]).ToString(CultureInfo.InvariantCulture)); break; case (ECols.DISTANCE): if (!String.IsNullOrEmpty(sFieldName)) { csvcols.Add(feat.GetFieldAsDouble(sFieldName).ToString(CultureInfo.InvariantCulture)); } break; case (ECols.STATION): csvcols.Add((finalDist).ToString(CultureInfo.InvariantCulture)); break; } } for (int did = 0; did < _inputRasters.Count; did++) { if (rowcol[1] > 0 && rowcol[1] < _inputRasters[did].Extent.Cols && rowcol[0] > 0 && rowcol[0] < _inputRasters[did].Extent.Rows) { T[] _buffer = new T[1]; _inputRasters[did].Read(rowcol[1], rowcol[0], 1, 1, _buffer); if (_buffer[0].Equals(inNodataVals[did])) { csvcols.Add(""); } else { csvcols.Add(DynamicMath.invariantString(_buffer[0])); } } else { csvcols.Add(""); } } csvRows.Add(String.Join(",", csvcols)); WriteLinesToCSV(csvRows); }
/// <summary> /// Loads the VectorFeature array with the features from the /// shapefile. /// </summary> private void LoadFile() { FileStream fs = new FileStream( _Filename, FileMode.Open ); BinaryReader br = new BinaryReader( fs ); VectorFeature tempFeature; int[] segments; int segmentPosition; int pointsInSegment; PointD[] tempPoints; PointD[] segmentPoints; _features = new VectorFeature[ _FeatureCount ]; if ( _ShapeType == ShapeType.Point ) { for ( int a=0; a < _FeatureCount; ++a ) { // Point types don't have parts (segments) / one point per feature tempFeature = new VectorFeature( 1, _mapMetrics ); tempPoints = new PointD[ 1 ]; fs.Seek( _OffsetOfRecord[ a ], 0 ); br.ReadInt32(); //Record number (not needed) br.ReadInt32(); //Content length (not needed) br.ReadInt32(); //Shape type (not needed) tempPoints[ 0 ] = new PointD( br.ReadDouble(), br.ReadDouble() ); tempFeature.AddSegment( tempPoints ); _features[ a ] = tempFeature; } } else { for ( int a=0; a < _FeatureCount; ++a ) { fs.Seek( _OffsetOfRecord[ a ] + 44, 0 ); // Read the number of parts (segments) and create a new VectorFeature tempFeature = new VectorFeature( br.ReadInt32(), _mapMetrics ); fs.Seek( _OffsetOfRecord[ a ], 0 ); br.ReadInt32(); //Record number (not needed) br.ReadInt32(); //Content length (not needed) br.ReadInt32(); //Shape type (not needed) tempFeature.Extents.Xmin = br.ReadDouble(); tempFeature.Extents.Ymin = br.ReadDouble(); tempFeature.Extents.Xmax = br.ReadDouble(); tempFeature.Extents.Ymax = br.ReadDouble(); br.ReadInt32(); // Number of parts (segments) gotten earlier tempPoints = new PointD[ br.ReadInt32() ]; // Number of points segments = new int[ tempFeature.SegmentCount + 1 ]; //Read in the segment indexes for ( int b=0; b<tempFeature.SegmentCount; ++b ) { segments[ b ] = br.ReadInt32(); } //Read in *ALL* of the points in the feature for ( int c=0; c<tempPoints.Length; ++c ) { tempPoints[ c ] = new PointD( br.ReadDouble(), br.ReadDouble() ); } //Add in an ending point for the inner loop that follows (e) segments[ tempFeature.SegmentCount ] = tempPoints.Length; //Watch your step... for ( int d=0; d<tempFeature.SegmentCount; ++d ) { pointsInSegment = segments[ d+1 ] - segments[ d ]; segmentPoints = new PointD[ pointsInSegment ]; segmentPosition = 0; for ( int e=segments[ d ]; e<segments[ d+1 ]; ++e ) { segmentPoints[ segmentPosition ] = tempPoints[ e ]; ++segmentPosition; } tempFeature.AddSegment( segmentPoints ); } _features[ a ] = tempFeature; } } _OffsetOfRecord = null; //don't need the info anymore _LengthOfRecord = null; GC.Collect(); br.Close(); fs.Close(); }
/// <summary> /// The constructor for the RenderThread. Sets up the private members /// of the class, but DOES NOT start the rendering process. /// </summary> /// @param metrics The MapMetrics object for this Map /// @param features The VectorFeature array /// @param type The type of shapefile we're going to draw /// @param beginning The array index of the VectorFeature to begin drawing with /// @param ending The array index of the VectorFeature to end drawing with /// @param pen The pen to draw the features with /// @param brush The brush to fill the features with public RenderThread( MapMetrics metrics, VectorFeature[] features, ShapeType type, int beginning, int ending, Pen pen, Brush brush ) { _mapMetrics = metrics; _features = features; _shapeType = type; _beginningFeature = beginning; _endingFeature = ending; _pen = (Pen) pen.Clone(); _brush = (Brush) brush.Clone(); _gr = Graphics.FromImage( _mapMetrics.Canvas ); }