public void DeleteBuffer() { try { mRecordset.DeleteAll(); if (mLayerBuffer != null) { mSceneControl.Scene.Layers.Remove(mLayerBuffer.Name); mLayerBuffer = null; } mSceneControl.Scene.Refresh(); if (mBufferDataset != null) { mDatasource.Datasets.Delete(mBufferDataset.Name); mBufferDataset = null; } } catch (System.Exception ex) { Trace.WriteLine(ex.Message); } }
public string TransFile(byte[] fileBt, double width, string fileName, bool ifCreate) { // 0长度文件返回 0 string rst = "0"; if (fileBt.Length == 0) { return(rst); } string filePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString()); //存储文件路径 //创建系统日期文件夹,避免同一文件夹下文件太多问题,避免同一地图应文档重名 filePath = filePath + DateTime.Now.ToString("yyyyMMdd") + "\\"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } FileStream fstream; //是否创建新文件 if (ifCreate) { fstream = new FileStream(filePath + fileName, FileMode.Create); } else { fstream = new FileStream(filePath + fileName, FileMode.Append); } try { fstream.Write(fileBt, 0, fileBt.Length); //二进制转换成文件 //上传成功返回 1 fstream.Close(); } catch (Exception ex) { //上传失败返回 1 rst = "error"; } finally { fstream.Close(); } //读取坐标文件转换面积 //设置为实际值 string imgPath = filePath + fileName; //坐标点导入处理 StreamReader objReader = new StreamReader(imgPath); string sLine = ""; ArrayList LineList = new ArrayList(); while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null && !sLine.Equals("")) { LineList.Add(sLine); } } objReader.Close(); bool isrewrite = true; string sourcePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["sourcePath"].ToString()); //存储文件路径 string targetPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["targetPath"].ToString()); //存储文件路径 String targetPath = str + "\\tempFolder\\temp_gkfqd.shp"; string temp = GenerateRandomCode(10); targetPath = targetPath + DateTime.Now.ToString("yyyyMMdd") + "\\"; if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } targetPath = targetPath + temp + "\\"; if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } System.IO.File.Copy(sourcePath + "testG.smwu", targetPath + "testG.smwu", isrewrite); System.IO.File.Copy(sourcePath + "test.udd", targetPath + "test.udd", isrewrite); System.IO.File.Copy(sourcePath + "test.udb", targetPath + "test.udb", isrewrite); this.fileWorkspace = new SuperMap.Data.Workspace(); string workSpaceFilePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["BinPath"].ToString()); //存储文件路径 try { //打开工作空间及地图文件类型 WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(targetPath + "testG.smwu"); fileWorkspace.Open(conInfo); fileDatasource = fileWorkspace.Datasources["test"]; sourceDatasetVector = fileDatasource.Datasets["dataT"] as DatasetVector; Recordset recordset = (sourceDatasetVector as DatasetVector).GetRecordset(false, CursorType.Dynamic); // 获得记录集对应的批量更新对象 Recordset.BatchEditor editor = recordset.Batch; // 开始批量添加,将 example 数据集每条记录对应的几何对象添加到数据集中 editor.Begin(); //删除所有记录 recordset.DeleteAll(); Point2Ds points = new Point2Ds(); for (int i = 1; i < LineList.Count - 1; i++) { string[] fieldInfoListZ = LineList[i].ToString().Split(','); Point2D point2D = new Point2D(); point2D.X = double.Parse(fieldInfoListZ[0].ToString()); point2D.Y = double.Parse(fieldInfoListZ[1].ToString()); points.Add(point2D); } GeoLine geolineE = new GeoLine(); geolineE.AddPart(points); recordset.AddNew(geolineE); editor.Update(); //调用创建矢量数据集缓冲区方法 //设置缓冲区分析参数 BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter(); //FLAT:平头缓冲。ROUND:圆头缓冲。 bufferAnalystParam.EndType = BufferEndType.Flat; //左侧缓冲距离,单位:米。 bufferAnalystParam.LeftDistance = width / 2; //右侧缓冲距离,单位:米。 bufferAnalystParam.RightDistance = width / 2; String bufferName = "bufferRegionDt"; bufferName = fileDatasource.Datasets.GetAvailableDatasetName(bufferName); m_bufferDataset = fileDatasource.Datasets.Create(new DatasetVectorInfo(bufferName, DatasetType.Region)); //设置投影信息 不设置 报投影不一致错误 m_bufferDataset.Datasource.Datasets["bufferRegionDt"].PrjCoordSys = (fileDatasource.Datasets["dataT"] as DatasetVector).PrjCoordSys; Boolean isTrue = SuperMap.Analyst.SpatialAnalyst.BufferAnalyst.CreateBuffer(recordset, m_bufferDataset, bufferAnalystParam, false, true); Recordset recordsetS = m_bufferDataset.Query("SmID=1", CursorType.Static); pfm = double.Parse(recordsetS.GetFieldValue("SMAREA").ToString()); mu = pfm * 0.0015; double gongqing = 0.0666667 * mu; } catch (Exception ex) { Trace.WriteLine(ex.Message); } rst = String.Format("{0:F2}", mu); fileWorkspace.Close(); return(rst); }
public string TransFile(byte[] fileBt, string fileName, bool ifCreate) { // 0长度文件返回 0 string rst = "0"; if (fileBt.Length == 0) { return(rst); } string filePath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["CSVPath"].ToString()); //存储文件路径 //创建系统日期文件夹,避免同一文件夹下文件太多问题,避免同一地图应文档重名 // filePath = filePath + DateTime.Now.ToString("yyyyMMdd") + "\\"; if (!Directory.Exists(filePath)) { // Create the directory it does not exist. Directory.CreateDirectory(filePath); } FileStream fstream; //是否创建新文件 if (ifCreate) { fstream = new FileStream(filePath + fileName, FileMode.Create); } else { fstream = new FileStream(filePath + fileName, FileMode.Append); } try { fstream.Write(fileBt, 0, fileBt.Length); //二进制转换成文件 //上传成功返回 1 fstream.Close(); } catch (Exception ex) { //上传失败返回 1 rst = "error"; } finally { fstream.Close(); } //读取坐标文件转换面积 string imgPath = "d:/zuobiao.txt"; //坐标点导入处理 StreamReader objReader = new StreamReader(imgPath); string sLine = ""; ArrayList LineList = new ArrayList(); while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null && !sLine.Equals("")) { LineList.Add(sLine); } } objReader.Close(); this.fileWorkspace = new SuperMap.Data.Workspace(); try { //打开工作空间及地图文件类型 WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"d:\testG.smwu"); fileWorkspace.Open(conInfo); fileDatasource = fileWorkspace.Datasources["test"]; sourceDatasetVector = fileDatasource.Datasets["dataT"] as DatasetVector; //Recordset recordset = new Recordset(); Recordset recordset = (sourceDatasetVector as DatasetVector).GetRecordset(false, CursorType.Dynamic); // 获得记录集对应的批量更新对象 Recordset.BatchEditor editor = recordset.Batch; // 开始批量添加,将 example 数据集每条记录对应的几何对象添加到数据集中 editor.Begin(); //删除所有记录 recordset.DeleteAll(); Point2Ds points = new Point2Ds(); for (int i = 1; i < LineList.Count - 1; i++) { string[] fieldInfoListZ = LineList[i].ToString().Split(','); Point2D point2D = new Point2D(); point2D.X = double.Parse(fieldInfoListZ[0].ToString()); point2D.Y = double.Parse(fieldInfoListZ[1].ToString()); points.Add(point2D); } GeoLine geolineE = new GeoLine(); geolineE.AddPart(points); recordset.AddNew(geolineE); editor.Update(); //调用创建矢量数据集缓冲区方法 //设置缓冲区分析参数 BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter(); bufferAnalystParam.EndType = BufferEndType.Flat; bufferAnalystParam.LeftDistance = 50; bufferAnalystParam.RightDistance = 50; String bufferName = "bufferRegionDt"; bufferName = fileDatasource.Datasets.GetAvailableDatasetName(bufferName); m_bufferDataset = fileDatasource.Datasets.Create(new DatasetVectorInfo(bufferName, DatasetType.Region)); Boolean isTrue = SuperMap.Analyst.SpatialAnalyst.BufferAnalyst.CreateBuffer(recordset, m_bufferDataset, bufferAnalystParam, false, true); Recordset formatRecordset = m_bufferDataset.GetRecordset(false, CursorType.Dynamic); GeoRegion geometrySearch = (GeoRegion)formatRecordset.GetGeometry(); pfm = geometrySearch.Area; mu = pfm * 0.0015; double gongqing = 0.0666667 * mu; // 释放记录集 // recordset.Dispose(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } rst = pfm.ToString(); fileWorkspace.Close(); return(rst); }