Ejemplo n.º 1
0
 /// <summary>
 /// 拷贝的构造函数。
 /// </summary>
 /// <param name="bufferAnalystParameter">BufferAnalystParameter 对象实例。</param>
 /// <exception cref="ArgumentNullException">bufferAnalystParameter 为空时抛出异常。</exception>
 public BufferAnalystParameter(BufferAnalystParameter bufferAnalystParameter)
 {
     if (bufferAnalystParameter == null)
         throw new ArgumentNullException("bufferAnalystParameter", Resources.ArgumentIsNotNull);
     this.EndType = bufferAnalystParameter.EndType;
     if (bufferAnalystParameter.LeftDistance != null)
         this.LeftDistance = new BufferDistance(bufferAnalystParameter.LeftDistance);
     if (bufferAnalystParameter.RightDistance != null)
         this.RightDistance = new BufferDistance(bufferAnalystParameter.RightDistance);
     this.SemicircleLineSegment = bufferAnalystParameter.SemicircleLineSegment;
 }
        public void CreatBuffer()
        {
            try
            {
                // 获取地图中的选择集,并转换为记录集
                // Get the dataset in the map, and convert it to recordset.
                Selection[] selections = m_srcMapControl.Map.FindSelection(true);
                Selection   selection  = selections[0];
                Recordset   recordset  = selection.ToRecordset();

                this.CopyDataset(m_bufferDataName);

                //PrjCoordSys gaussPrjSys = this.GetTargetPrjCoordSys(type);
                //Boolean result = CoordSysTranslator.Convert(m_processDataset, gaussPrjSys, new CoordSysTransParameter(), CoordSysTransMethod.GeocentricTranslation);


                //设置缓冲区分析参数
                BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter();
                bufferAnalystParam.EndType       = BufferEndType.Flat;
                bufferAnalystParam.LeftDistance  = 100;
                bufferAnalystParam.RightDistance = 100;

                this.result = m_bufferDataset as DatasetVector;
                //调用创建矢量数据集缓冲区方法
                Boolean istrue = BufferAnalyst.CreateBuffer(recordset, result, bufferAnalystParam, false, true);

                Recordset recordset2 = result.GetRecordset(false, SuperMap.Data.CursorType.Dynamic);

                m_srcMapControl.Map.Layers.Add(result, true);
                m_srcMapControl.Map.Center = result.Bounds.Center;
                m_srcMapControl.Map.Scale  = m_srcMapControl.Map.Scale;
                m_srcMapControl.Map.Refresh();

                recordset2.Dispose();

                // 刷新地图
                // Refresh the map.
                m_srcMapControl.Map.Refresh();

                recordset.Dispose();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 3
0
        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 void Buffer_ByRegionSegment()
        {
            string serviceUrl = string.Format("http://{0}:8090/iserver/services/spatialanalyst-changchun/restjsr", ip);
            SpatialAnalyst spatialAnalyst = new SpatialAnalyst(serviceUrl);

            BufferAnalystParameter bufferAnalystParameter = new BufferAnalystParameter();
            bufferAnalystParameter.EndType = BufferEndType.ROUND;
            bufferAnalystParameter.SemicircleLineSegment = 12;
            bufferAnalystParameter.LeftDistance = new BufferDistance() { Value = 2 };
            bufferAnalystParameter.RightDistance = new BufferDistance() { Value = 55557 };

            Geometry geometry = new Geometry();
            geometry.Type = GeometryType.REGION;
            Point2D point1 = new Point2D(23, 23);
            Point2D point2 = new Point2D(33, 37);
            Point2D point3 = new Point2D(33, 38);
            geometry.Points = new Point2D[] { point1, point2, point3 };
            geometry.Parts = new int[] { 3 };

            GeometrySpatialAnalystResult result = spatialAnalyst.Buffer(geometry, bufferAnalystParameter);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Succeed);
            Assert.IsTrue(result.ResultGeometry != null);
            Assert.IsTrue(result.ResultGeometry.Type == GeometryType.REGION);
            Assert.IsTrue(result.ResultGeometry.Points.Length == 98);
        }
        public void Buffer_ByPoint()
        {
            string serviceUrl = string.Format("http://{0}:8090/iserver/services/spatialanalyst-changchun/restjsr", ip);
            SpatialAnalyst spatialAnalyst = new SpatialAnalyst(serviceUrl);

            BufferAnalystParameter bufferAnalystParameter = new BufferAnalystParameter();
            bufferAnalystParameter.EndType = BufferEndType.ROUND;
            bufferAnalystParameter.SemicircleLineSegment = 4;
            bufferAnalystParameter.LeftDistance = new BufferDistance() { Value = 105.2 };
            bufferAnalystParameter.RightDistance = new BufferDistance() { Value = 105.2 };

            Geometry geometry = new Geometry();
            geometry.Type = GeometryType.POINT;
            Point2D point1 = new Point2D(23, 23);
            Point2D point2 = new Point2D(33, 37);
            geometry.Points = new Point2D[] { point1 };
            geometry.Parts = new int[] { 1 };

            GeometrySpatialAnalystResult result = spatialAnalyst.Buffer(geometry, bufferAnalystParameter);

            Assert.IsNotNull(result);
        }
        public void Buffer_ByPolygonDatasetUnion()
        {
            string serviceUrl = string.Format("http://{0}:8090/iserver/services/spatialanalyst-changchun/restjsr", ip);
            SpatialAnalyst spatialAnalyst = new SpatialAnalyst(serviceUrl);

            BufferAnalystParameter bufferAnalystParameter = new BufferAnalystParameter();
            bufferAnalystParameter.EndType = BufferEndType.ROUND;
            bufferAnalystParameter.SemicircleLineSegment = 4;
            bufferAnalystParameter.LeftDistance = new BufferDistance() { Value = 105.2 };
            bufferAnalystParameter.RightDistance = new BufferDistance() { Value = 105.2 };

            BufferResultSetting bufferResultSetting = new BufferResultSetting();
            bufferResultSetting.DataReturnOption = new DataReturnOption()
            {
                Dataset = "resultPolygon",
                DataReturnMode = DataReturnMode.DATASET_AND_RECORDSET,
                DeleteExistResultDataset = true
            };
            bufferResultSetting.IsAttributeRetained = true;
            bufferResultSetting.IsUnion = true;
            try
            {
                DatasetSpatialAnalystResult result = spatialAnalyst.Buffer("WaterPoly@Changchun", bufferAnalystParameter, null, bufferResultSetting);

                Assert.IsTrue(result != null);
                Assert.IsTrue(result.Succeed);
                Assert.IsTrue(result.Dataset == "resultPolygon@Changchun");
                Assert.IsTrue(result.Recordset != null);
                Assert.IsTrue(result.Recordset.Features != null);
                Assert.IsTrue(result.Recordset.Features.Length == 1);
            }
            catch (ServiceException e)
            {
                Assert.IsTrue(true);
                Assert.IsTrue(e.Code == 400);
            }
            finally
            {

            }
        }
        public void Buffer_ByLineDatasetFlatBuffer()
        {
            string serviceUrl = string.Format("http://{0}:8090/iserver/services/spatialanalyst-changchun/restjsr", ip);
            SpatialAnalyst spatialAnalyst = new SpatialAnalyst(serviceUrl);

            BufferAnalystParameter bufferAnalystParameter = new BufferAnalystParameter();
            bufferAnalystParameter.EndType = BufferEndType.FLAT;
            bufferAnalystParameter.SemicircleLineSegment = 4;
            bufferAnalystParameter.LeftDistance = new BufferDistance() { Value = 105.2 };
            bufferAnalystParameter.RightDistance = new BufferDistance() { Value = 105.2 };

            QueryParameter filterQueryParameter = new QueryParameter();
            filterQueryParameter.AttributeFilter = "smid=5 or smid =1";

            BufferResultSetting bufferResultSetting = new BufferResultSetting();
            bufferResultSetting.DataReturnOption = new DataReturnOption()
            {
                Dataset = "resultLine",
                DataReturnMode = DataReturnMode.DATASET_AND_RECORDSET,
                DeleteExistResultDataset = true
            };
            bufferResultSetting.IsAttributeRetained = true;

            try
            {
                DatasetSpatialAnalystResult result = spatialAnalyst.Buffer("Edit_Line@Changchun", bufferAnalystParameter, filterQueryParameter, bufferResultSetting);
            }
            catch (ServiceException e)
            {
                Assert.IsTrue(true);
                Assert.IsTrue(e.Code == 400);
            }
        }
        public void Buffer_ByLineDatasetHasAttributerFilter()
        {
            string serviceUrl = string.Format("http://{0}:8090/iserver/services/spatialanalyst-changchun/restjsr", ip);
            SpatialAnalyst spatialAnalyst = new SpatialAnalyst(serviceUrl);

            BufferAnalystParameter bufferAnalystParameter = new BufferAnalystParameter();
            bufferAnalystParameter.EndType = BufferEndType.ROUND;
            bufferAnalystParameter.SemicircleLineSegment = 4;
            bufferAnalystParameter.LeftDistance = new BufferDistance() { Value = 105.2 };
            bufferAnalystParameter.RightDistance = new BufferDistance() { Value = 105.2 };

            QueryParameter filterQueryParameter = new QueryParameter();
            filterQueryParameter.AttributeFilter = "smid=5 or smid =1";

            BufferResultSetting bufferResultSetting = new BufferResultSetting();
            bufferResultSetting.DataReturnOption = new DataReturnOption()
            {
                Dataset = "resultLine",
                DataReturnMode = DataReturnMode.DATASET_AND_RECORDSET,
                DeleteExistResultDataset = true
            };
            bufferResultSetting.IsAttributeRetained = true;

            DatasetSpatialAnalystResult result = spatialAnalyst.Buffer("Edit_Line@Changchun", bufferAnalystParameter, filterQueryParameter, bufferResultSetting);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Succeed);
            Assert.IsTrue(result.Dataset == "resultLine@Changchun");
            Assert.IsTrue(result.Recordset != null);
            Assert.IsTrue(result.Recordset.Features != null);
            Assert.IsTrue(result.Recordset.Features.Length == 1);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 根据几何对象创建缓冲区,成功则返回一个面对象,失败则返回空值。
 /// </summary>
 /// <param name="geometry">需要创建缓冲区的几何对象。</param>
 /// <param name="bufferAnalystParameter">缓冲区分析参数,必设参数。指定缓冲距离、缓冲区端点类型等缓冲区分析需要的信息,请参见 <see cref="BufferAnalystParameter"/> 类。</param>
 /// <returns>几何对象缓冲区分析结果。</returns>
 /// <exception cref="SuperMap.Connector.Utility.ServiceException">服务端处理错误时抛出异常。</exception>
 /// <example>
 /// 以下示例代码演示如何根据几何对象进行缓冲区分析。
 /// <code>
 /// using System;
 /// using System.Collections.Generic;
 /// using System.Text;
 /// using SuperMap.Connector;
 /// using SuperMap.Connector.Utility;
 /// 
 /// class Program
 /// {
 ///     static void Main(string[] args)
 ///     {
 ///         //根据服务组件地址初始化一个SpatialAnalyst对象。
 ///          SpatialAnalyst spatialAnalyst = new SpatialAnalyst("http://localhost:8090/iserver/services/spatialanalyst-changchun/restjsr");
 ///
 ///         //初始化一个Buffer分析参数。
 ///          BufferAnalystParameter bufferparameter = new BufferAnalystParameter()
 ///         {
 ///             EndType = BufferEndType.ROUND,
 ///             LeftDistance = new BufferDistance() { Value = 100 },   //左侧缓冲距离100米。
 ///             RightDistance = new BufferDistance() { Value = 100 },
 ///             SemicircleLineSegment = 12
 ///         };
 ///
 ///         //缓冲几何对象。
 ///          Point2D point1 = new Point2D(23, 23);
 ///         Point2D point2 = new Point2D(33, 37);
 ///         Point2D point3 = new Point2D(33, 38);
 ///         Point2D point4 = new Point2D(23, 23);
 ///         Geometry bufferSourceGeometry = new Geometry()
 ///         {
 ///             Type = GeometryType.REGION,
 ///             Parts = new int[] { 4 },
 ///             Points = new Point2D[] { point1, point2, point3, point4 },
 ///         };
 /// 
 ///         //执行缓冲区分析。
 ///          GeometrySpatialAnalystResult bufferResult = spatialAnalyst.Buffer(bufferSourceGeometry, bufferparameter);
 ///         Console.ReadLine();
 ///     }
 /// }
 /// </code>
 /// </example>
 public GeometrySpatialAnalystResult Buffer(Geometry geometry, BufferAnalystParameter bufferAnalystParameter)
 {
     return _spatialAnalystProvier.Buffer(geometry, bufferAnalystParameter);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 根据数据集创建缓冲区。
        /// </summary>
        /// <param name="datasetName">数据集标识。</param>
        /// <param name="filterQueryParameter">过滤参数,可选。设置了过滤参数后,只对数据集中满足此过滤条件的对象创建缓冲区。</param>
        /// <param name="bufferAnalystParameter">缓冲区分析参数,必设参数。指定缓冲距离、缓冲区端点类型等缓冲区分析需要的信息,请参见 <see cref="BufferAnalystParameter"/> 类。</param>
        /// <param name="bufferResultSetting">数据集缓冲区分析结果设置参数。</param>
        /// <returns>数据集缓冲区分析结果。</returns>
        /// <exception cref="ArgumentNullException">参数 datasetName 为空时抛出异常。</exception>
        /// <exception cref="SuperMap.Connector.Utility.ServiceException">服务端处理错误时抛出异常。</exception>
        /// <example>
        /// 以下示例代码演示如何根据数据集进行缓冲区分析。
        /// <code>
        /// using System;
        /// using System.Collections.Generic;
        /// using System.Text;
        /// using SuperMap.Connector;
        /// using SuperMap.Connector.Utility;
        ///
        /// class Program
        /// {
        ///     static void Main(string[] args)
        ///     {
        ///         //根据服务组件地址初始化一个SpatialAnalyst对象。
        ///          SpatialAnalyst spatialAnalyst = new SpatialAnalyst("http://*****:*****@Changchun";   //用来进行缓冲区分析的数据集,@符号前为数据集名称,@符号后为数据源名称。
        /// 
        ///         //执行缓冲区分析。
        ///          DatasetSpatialAnalystResult bufferResult = spatialAnalyst.Buffer(datasetName, bufferparameter, filterQueryParameter, bufferResultSetting);
        /// 
        ///         Console.WriteLine(string.Format("缓冲区分析结果数据集名称为:{0}", bufferResult.Dataset));
        ///         Console.ReadLine();
        ///     }
        /// }
        /// 
        /// //分析输出如下结果:
        /// //缓冲区分析结果数据集名称为:bufferResult@Changchun
        /// </code>
        /// </example>
        public DatasetSpatialAnalystResult Buffer(string datasetName, BufferAnalystParameter bufferAnalystParameter, QueryParameter filterQueryParameter, BufferResultSetting bufferResultSetting)
        {
#if NET40
            if (string.IsNullOrWhiteSpace(datasetName))
            {
                throw new ArgumentNullException("datasetName", Resources.ArgumentIsNotNull);
            }
#else
            if (string.IsNullOrEmpty(datasetName))
            {
                throw new ArgumentNullException("datasetName", Resources.ArgumentIsNotNull);
            }
#endif
            return _spatialAnalystProvier.Buffer(datasetName, bufferAnalystParameter, filterQueryParameter, bufferResultSetting);
        }
Ejemplo n.º 11
0
        //Buffer查询
        public void BufferQuery()
        {
            try
            {
                //清除已有查询结果
                if (m_layerResultDataset != null)
                {
                    this.ClearResult();
                }
                //创建结果面数据集
                String bufferName = "bufferRegionDataset";
                if (m_workspace.Datasources[0].Datasets.Contains(bufferName))
                {
                    m_workspace.Datasources[0].Datasets.Delete(bufferName);
                }
                DatasetVector bufferDataset = (DatasetVector)m_workspace.Datasources[0].Datasets.CreateFromTemplate(bufferName, m_srcDatasetVector);

                BufferAnalystParameter bufferAnalystParam = new BufferAnalystParameter();
                bufferAnalystParam.EndType      = BufferEndType.Round;
                bufferAnalystParam.LeftDistance = m_bufferRadius;

                Boolean isTrue = SuperMap.Analyst.SpatialAnalyst.BufferAnalyst.CreateBuffer(m_selectRegion, bufferDataset, bufferAnalystParam, false, true);

                m_layerBufferDataset = this.AddResultToScene(bufferDataset, Color.FromArgb(100, 255, 255, 0)) as Layer3DDataset;

                //进行叠加分析
                QueryParameter para = new QueryParameter();
                para.SpatialQueryMode   = SpatialQueryMode.Intersect;
                para.SpatialQueryObject = bufferDataset;

                Recordset recordset = m_srcDatasetVector.Query(para);

                List <Int32> ids = new List <int>(recordset.RecordCount);

                while (!recordset.IsEOF)
                {
                    ids.Add(recordset.GetID());
                    recordset.MoveNext();
                }

                String resultName = "BufferResult";
                if (m_workspace.Datasources[0].Datasets.Contains(resultName))
                {
                    m_workspace.Datasources[0].Datasets.Delete(resultName);
                }
                DatasetVector dataset_result = (DatasetVector)m_workspace.Datasources[0].Datasets.CreateFromTemplate(resultName, m_srcDatasetVector);
                Console.Write(isTrue);


                // 将空间查询结果追加到新建的数据集中
                dataset_result.Append(recordset);

                m_layerSrcRegion.IsVisible = false;
                //将结果数据集添加到场景中

                Color color = Color.FromArgb(200, 0, 233, 0);
                m_layerResultDataset = this.AddResultToScene(dataset_result, color) as Layer3DDataset;

                //如果场景中有osgb图层,设置osgb图层可见
                Layer3Ds layer3ds = m_sceneControl.Scene.Layers;
                for (int i = 0; i < layer3ds.Count; i++)
                {
                    Layer3D layer = layer3ds[i];
                    if (layer.Type == Layer3DType.OSGB)
                    {
                        layer.IsVisible = true;
                    }
                }

                recordset.Dispose();
                m_selectRegion.Dispose();
                m_selectRegion = null;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 public DatasetSpatialAnalystResult Buffer(string datasetName, BufferAnalystParameter bufferAnalystParameter, QueryParameter filterQueryParameter, BufferResultSetting bufferResultSetting)
 {
     string baseUrl = string.Format("{0}/spatialanalyst/datasets/{1}/buffer.json?returnContent=true", this._serviceUrl,
         HttpUtility.UrlEncode(datasetName));
     DatasetBufferRequestParameter parameter = new DatasetBufferRequestParameter(bufferAnalystParameter, filterQueryParameter, bufferResultSetting);
     string strBufferResult = SynchHttpRequest.GetRequestString(baseUrl, HttpRequestMethod.POST, JsonConvert.SerializeObject(parameter));
     return JsonConvert.DeserializeObject<DatasetSpatialAnalystResult>(strBufferResult);
 }
 public GeometrySpatialAnalystResult Buffer(Geometry geometry, BufferAnalystParameter bufferAnalystParameter)
 {
     string baseUrl = string.Format("{0}/spatialanalyst/geometry/buffer.json?returnContent=true", this._serviceUrl);
     GeometryBufferRequestParameter parameter = new GeometryBufferRequestParameter(geometry, bufferAnalystParameter);
     string strBufferResult = SynchHttpRequest.GetRequestString(baseUrl, HttpRequestMethod.POST, JsonConvert.SerializeObject(parameter));
     return JsonConvert.DeserializeObject<GeometrySpatialAnalystResult>(strBufferResult);
 }
Ejemplo n.º 14
0
        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);
        }