zoukankan      html  css  js  c++  java
  • 点批量移动到线上(ArcGis版) 转载

    点批量移动到线上(ArcGis版)  

    2012-12-25 14:34:56|  分类: PostgreSQL |  标签: |字号 订阅

     
     
    原文:点批量移动到线上

    交通行业一个客户提出的需求:如下图,有高速公路中心线和很多设备点,这些设备点都没有在线上(由于地图缩小缘故看不太清),且设备点相对于线的偏移方向和距离没有规律,现在需要将这些点移动到线上。这里我基于Engine写了一段程序处理。

     

     

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    using ESRI.ArcGIS.Carto;

    using ESRI.ArcGIS.Geodatabase;

    using ESRI.ArcGIS.Geometry;

    using ESRI.ArcGIS.Display;

     

    namespace pointBatchOffset

    {

        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();

            }

     

    //开始执行

            private void button1_Click(object sender, EventArgs e)

            {

                //查询缓冲区图层

                IFeatureLayer ptLayer = queryFeatureLayer("pointZ");

                //得到指定图层上距point最近的feature上的最近点

                IFeatureClass  ptFeatClass = ptLayer.FeatureClass;

                IFeatureCursor featureCursor = featureCursor = ptFeatClass.Search(null, false);

                IFeature feature = featureCursor.NextFeature();

                IPoint point = new PointClass();

                while (feature != null)

                {     

                   point = feature.Shape as IPoint;  

                    //查找离点最近的线

                    IFeature nearFea = GetNearestFeature(point, 1.2);          

                   IPoint neaPoint = GetNearestPoint(point,nearFea);

                   neaPoint.Z = point.Z;

                    //移动点

                   MoveToNeaPoint(feature,point,neaPoint);

                    if (featureCursor == null || feature == null)

                    {

                        return;

                    }

                    feature = featureCursor.NextFeature();

                }

     

                MessageBox.Show("ok--");

            }

     

            //查询给定名称的图层

            private IFeatureLayer queryFeatureLayer(string name)

            {

                for (int i = 0; i < axMapControl1.LayerCount; i++)

                {

                    ILayer layer = axMapControl1.get_Layer(i);

                    if (layer.Name.Equals(name))

                    {

                        return (IFeatureLayer)layer;

                    }

                }

                return null;

            }

     

     

            ////得到指定图层上距point最近的feature上的最近点

            public IPoint GetNearestPoint(IPoint point, IFeature nearFea)

            {

                IProximityOperator Proximity = (IProximityOperator)point;

     

                IFeatureLayer FeaLyr = queryFeatureLayer("MedianRoadZ");

                IFeatureClass FeaCls = FeaLyr.FeatureClass;

                IQueryFilter queryFilter = null;

                ITopologicalOperator topoOper = (ITopologicalOperator)point;

                IGeometry geo = topoOper.Buffer(1.2);

                ISpatialFilter sf = new SpatialFilterClass();

                sf.Geometry = geo;

                sf.GeometryField = FeaCls.ShapeFieldName;

                sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;

     

     

                IFeatureCursor FeaCur = FeaCls.Search(queryFilter, false);

                IFeature Fea = nearFea = FeaCur.NextFeature();

                double minDistince, Distance;

                if (Fea == null)

                    return null;

                minDistince = Distance = Proximity.ReturnDistance((IGeometry)Fea.Shape);    //最近的距离值

                //保存距离最近的feature

                Fea = FeaCur.NextFeature();

                while (Fea != null)

                {

                    Distance = Proximity.ReturnDistance((IGeometry)Fea.Shape);

                    if (Distance < minDistince)

                    {

                        minDistince = Distance;

                        nearFea = Fea;

                    }

                    Fea = FeaCur.NextFeature();

                }   //end while

                Proximity = (IProximityOperator)nearFea.Shape;

                return Proximity.ReturnNearestPoint(point, esriSegmentExtension.esriNoExtension);

            }

     

            //查找最近的线

            public IFeature GetNearestFeature(IPoint p, double rongcha)

            {

                IFeature nearFea;

                IProximityOperator Proximity = (IProximityOperator)p;

                IFeatureLayer FeaLyr = queryFeatureLayer("MedianRoadZ");

                IFeatureClass FeaCls = FeaLyr.FeatureClass;

                IQueryFilter queryFilter = null;

                        IFeatureCursor FeaCur = FeaCls.Search(queryFilter, false);

                IFeature Fea = nearFea = FeaCur.NextFeature();

                double minDistince, Distance;

                if (Fea == null)

                    return null;

                minDistince = Distance = Proximity.ReturnDistance((IGeometry)Fea.Shape);    //最近的距离值

                //保存距离最近的feature

                Fea = FeaCur.NextFeature();

                while (Fea != null)

                {

                    Distance = Proximity.ReturnDistance((IGeometry)Fea.Shape);

                    if (Distance < minDistince)

                    {

                        minDistince = Distance;

                        nearFea = Fea;

                    }

                    Fea = FeaCur.NextFeature();

                }   //end while

     

                return nearFea;

            }

     

     

            private void MoveToNeaPoint(IFeature feature,IPoint point, IPoint neaPoint)

            {

                IGeometry toGeometry = null;

                IPoint geomType = new PointClass();

                feature.Shape = neaPoint as IGeometry;    

                feature.Store();

            }

     

        }

    }

  • 相关阅读:
    26. Remove Duplicates from Sorted Array
    Luogu1879 [USACO06NOV]玉米田Corn Fields (状压DP)
    Luogu1655 小朋友的球 (组合数学,第二类斯特林数,高精)
    Luogu4408 [NOI2003]逃学的小孩 (树的直径)
    Luogu2574 XOR的艺术 (分块)
    Luogu3740 [HAOI2014]贴海报 (线段树)
    LuoguU72177 火星人plus (逆康拓展开)
    Luogu1919 【模板】A*B Problem升级版(FFT)
    Luogu5367 【模板】康托展开 (康拓展开)
    Luogu1088 火星人 (康托展开)
  • 原文地址:https://www.cnblogs.com/gisoracle/p/3009285.html
Copyright © 2011-2022 走看看