private void TryExportPolygon(Feature[] features, string shpFileName) { EsriShapeFilesWriterII w = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Polygon); w.BeginWrite(); Feature feature = features[0]; string[] fieldNames = feature.FieldNames; Feature[] retFeature = new Feature[features.Length]; for (int i = 0; i < features.Length; i++) { ShapePolygon ply = (features[i].Geometry as ShapePolygon).Clone() as ShapePolygon; ShapeRing[] rings = ply.Rings; ShapeRing[] newRings = new ShapeRing[rings.Length]; for (int j = 0; j < rings.Length; j++) { ShapePoint[] points = rings[j].Points; ShapePoint[] newPoints = new ShapePoint[points.Length]; for (int p = 0; p < points.Length; p++) { double prjx = points[p].X; double prjy = points[p].Y; double geox, geoy; _canvas.CoordTransform.Prj2Geo(prjx, prjy, out geox, out geoy); newPoints[p] = new ShapePoint(geox, geoy); } newRings[j] = new ShapeRing(newPoints); } ShapePolygon newPly = new ShapePolygon(newRings); Feature fet = new Feature(features[i].OID, newPly, fieldNames, features[i].FieldValues, null); retFeature[i] = fet; } w.Write(retFeature); w.EndWriter(); }
private unsafe void TryExport2ShapeFile(IRasterDataProvider dataProvider, ContourLine[] cntLines, string shpFileName, IProgressMonitor progress, bool isNeedDisplay) { int cntCount = cntLines.Length; string tip = "正在将等值线导出为矢量文件({0}/{1})..."; progress.Reset("正在将等值线导出为矢量文件...", cntLines.Length); IEsriShapeFilesWriter writer = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Polyline); writer.BeginWrite(); try { double resX = dataProvider.CoordEnvelope.Width / dataProvider.Width; double resY = dataProvider.CoordEnvelope.Height / dataProvider.Height; double minX = dataProvider.CoordEnvelope.MinX; double maxY = dataProvider.CoordEnvelope.MaxY; Feature[] buffer = new Feature[1]; for (int i = 0; i < cntCount; i++) { if (cntLines[i] == null) { continue; } Feature fet = GetFeature(cntLines[i], resX, resY, minX, maxY, i); if (fet != null) { buffer[0] = fet; writer.Write(buffer); } progress.Boost(i, string.Format(tip, i + 1, cntCount)); } } finally { writer.EndWriter(); progress.Boost(cntCount); //没有直接显示则打开矢量文件 if (!isNeedDisplay) { if (MsgBox.ShowQuestionYesNo("是否打开矢量文件\"" + shpFileName + "\"?") == DialogResult.Yes) { OpenFileFactory.Open(shpFileName); } } } }
/// <summary> /// 保存矢量数据到文件 /// </summary> /// <param name="shpFileName"></param> /// <param name="features"></param> private void SaveToShp(string shpFileName, Feature[] features) { IEsriShapeFilesWriter writer = null; try { writer = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Polygon); writer.BeginWrite(); writer.Write(features); } finally { if (writer != null) { writer.EndWriter(); } } }
private string GenerateShpFormTxt(string fileName) { if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) { return(null); } string[] pointInfos = File.ReadAllLines(fileName, Encoding.Default); if (pointInfos == null || pointInfos.Length < 2) { return(null); } List <Feature> features = new List <Feature>(); _pointInfos.Clear(); ShapePoint pt; string[] fieldNames = pointInfos[0].Replace(" ", "").Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); string[] fieldValues; for (int i = 1; i < pointInfos.Length; i++) { fieldValues = pointInfos[i].Replace(" ", "").Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (fieldValues.Length != fieldNames.Length) { continue; } pt = new ShapePoint(float.Parse(fieldValues[2]), float.Parse(fieldValues[3])); Feature f = new Feature(i - 1, pt, fieldNames, fieldValues, null); features.Add(f); _pointInfos.AppendLine(string.Format("{0}\t{1}\t", i, fieldValues[1])); } if (features.Count < 1) { return(null); } string shpFileName = Path.Combine(Path.GetDirectoryName(_gxdFile), Path.GetFileNameWithoutExtension(_gxdFile) + ".shp"); EsriShapeFilesWriterII w = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Point); w.BeginWrite(); w.Write(features.ToArray()); w.EndWriter(); //mcd文件 CreateMcd(shpFileName); return(shpFileName); }
protected void SaveToShpFile(string RGFRfilename, Feature[] leftFeatures) { try { EsriShapeFilesWriterII HdfRGFRWriter = new EsriShapeFilesWriterII(RGFRfilename, enumShapeType.Point); HdfRGFRWriter.BeginWrite(); HdfRGFRWriter.Write(leftFeatures, new Action <int, string>(Progress)); HdfRGFRWriter.EndWriter(); btnOpenOutDir.Enabled = true; _labeledPt = 0; } catch (IOException ex) { MessageBox.Show(ex.Message, "HdfGlobalFirePointReader", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { FinishProgress(); } }
private unsafe void TryExport2ShapeFile(IRasterDataProvider dataProvider, ContourLine[] cntLines, string shpFileName) { int cntCount = cntLines.Length; string tip = "正在将等值线导出为矢量文件({0}/{1})..."; float interval = 100f / cntCount; IEsriShapeFilesWriter writer = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Polyline); writer.BeginWrite(); int index = 0; try { double resX = dataProvider.CoordEnvelope.Width / dataProvider.Width; double resY = dataProvider.CoordEnvelope.Height / dataProvider.Height; double minX = dataProvider.CoordEnvelope.MinX; double maxY = dataProvider.CoordEnvelope.MaxY; Feature[] buffer = new Feature[1]; for (int i = 0; i < cntCount; i++) { if (cntLines[i] == null) { continue; } index = (int)(Math.Floor(interval * i)); Feature fet = GetFeature(cntLines[i], resX, resY, minX, maxY, i); if (fet != null) { buffer[0] = fet; writer.Write(buffer); } if (_progressTracker != null) { _progressTracker(index, string.Format(tip, i, cntCount)); } } } finally { writer.EndWriter(); } }
private void TryExportIceLine2Shp(Feature[] iceLines, string shpFileName) { int cntCount = iceLines.Length; string tip = "正在将等值线导出为矢量文件({0}/{1})..."; int progress = 0; float interval = 100f / cntCount; IEsriShapeFilesWriter writer = null; try { writer = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Polyline); writer.BeginWrite(); Feature[] buffer = new Feature[1]; for (int i = 0; i < cntCount; i++) { if (iceLines[i] == null) { continue; } progress = (int)(Math.Floor(interval * i)); //Feature fet = GetIceLineFeature(iceLines[i], resX, resY, minX, maxY, i); Feature fet = iceLines[i]; if (fet != null) { buffer[0] = fet; writer.Write(buffer); } if (_progressTracker != null) { _progressTracker(progress, string.Format(tip, i, cntCount)); } } } finally { if (writer != null) { writer.EndWriter(); } } }
private string GenaratePoints(string gxdFileName) { string[] lines = File.ReadAllLines(_firFile); if (lines == null || lines.Length < 2) { return(null); } List <Feature> features = new List <Feature>(); ShapePoint pt; string[] fieldValues; string[] fieldNames = new string[] { "火区号", "经度", "纬度", "像元个数", "像元覆盖面积", "明火面积" }; for (int i = 1; i < lines.Length; i++) { fieldValues = lines[i].Replace(" ", "").Split(new char[] { '\t' }, 6, StringSplitOptions.RemoveEmptyEntries); if (fieldValues != null) { //经纬度坐标度分秒转十进制 double x = GetAngleFromString(fieldValues[1]); double y = GetAngleFromString(fieldValues[2]); pt = new ShapePoint(x, y); Feature f = new Feature(i - 1, pt, fieldNames, fieldValues, null); features.Add(f); } } if (features.Count < 1) { return(null); } string shpFileName = Path.Combine(Path.GetDirectoryName(gxdFileName), Path.GetFileNameWithoutExtension(gxdFileName) + ".shp"); EsriShapeFilesWriterII w = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Point); w.BeginWrite(); w.Write(features.ToArray()); w.EndWriter(); //mcd文件 CreateMcd(shpFileName); return(shpFileName); }