private void ProcessPolyline(IPolyline polyline, IFeatureClass outFeatureClass, int scale, int frameRate = 60, double lineLengthInPixel = 5, double intervalInPixel = 10, ISpatialReference spatialReference = null)
        {
            if (spatialReference == null)
            {
                spatialReference = Get3857Sr();
            }
            var    pixelLength    = PixelLengthAtScale(polyline.Length, scale, 96);
            double lineLength     = LengthAtScaleOfPixelLength(lineLengthInPixel, scale);
            double intervalLength = LengthAtScaleOfPixelLength(intervalInPixel, scale);

            //too short
            if (pixelLength < intervalInPixel)
            {
            }
            else
            {
                for (int frame = 0; frame < frameRate; frame++)
                {
                    Console.WriteLine($"SCALE:{scale}, FRAME:{frame}");
                    double startLengthOfEachDrawLine = 0 + (((double)frame) / ((double)frameRate)) * intervalLength;
                    while (startLengthOfEachDrawLine < polyline.Length)
                    {
                        var endPointLength = startLengthOfEachDrawLine + lineLength;
                        if (endPointLength >= polyline.Length)
                        {
                            endPointLength = polyline.Length;
                        }
                        polyline.GetSubcurve(startLengthOfEachDrawLine, endPointLength, false, out ICurve curve);
                        IFeature createdFeature = outFeatureClass.CreateFeature();
                        createdFeature.Shape.SpatialReference = spatialReference;
                        createdFeature.Shape = (IPolyline)curve;
                        if (_indexOfFieldFrame >= 0)
                        {
                            try
                            {
                                createdFeature.Value[_indexOfFieldFrame] = frame;
                            }
                            catch (Exception)
                            {
                            }
                        }
                        if (_indexOfFieldScale >= 0)
                        {
                            try
                            {
                                createdFeature.Value[_indexOfFieldScale] = scale;
                            }
                            catch (Exception)
                            {
                            }
                        }
                        createdFeature.Store();
                        startLengthOfEachDrawLine += intervalLength;
                    }
                }
            }
            ;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获得回采多边形点列表,最后点为切眼中心点
        /// </summary>
        /// <params name="pline1"></巷道1>
        /// <params name="pline2"></巷道2>
        /// <params name="pline3"></切眼>
        /// <params name="widthhd"></巷道宽度>
        /// <params name="widthqy"></切眼宽度>
        /// <params name="hcDis"></回采距离>
        /// <params name="direct"></回采方向,pline3 from-to方向,返回1-切眼右侧, 返回-1-切眼左侧(),只在中间回采时使用此参数,开始回采时值为0>
        /// <returns></returns>
        public IPointCollection GetBackPolygonArea(IPolyline pline1, IPolyline pline2, IPolyline pline3, double widthhd, double widthhd1, double widthqy, double hcDis, int direct)
        {
            object obj = Type.Missing;
            //ESRI.ArcGIS.Geometry.IPolyline polylineall = new ESRI.ArcGIS.Geometry.PolylineClass();
            IPolyline offsetqy = null;
            Boolean   bright   = false;
            //交点1(切眼与巷道1交点)
            IPoint point1 = GetIntersectPointExtend(pline3, pline1);

            //交点2(切眼与巷道2交点)
            IPoint point2 = GetIntersectPointExtend(pline3, pline2);

            //CreateFeature(pline3, GetLayerByName("中心线全"));
            int iDirect;     //依据切眼与巷道的关系判断回采方向,切眼为巷道起点时使用

            if (direct != 0) //中心点回采
            {
                IPoint outpnt = new PointClass();
                iDirect  = direct;
                offsetqy = GetExtentQy(pline1, pline2, pline3);
            }
            else
            {
                iDirect  = GetBackDirection(pline3, 200, pline1, pline2);
                offsetqy = ConstructOffset(pline3, widthqy / 2.0 * iDirect);
            } //切眼平移后的线
            IPoint pointCent = ConstructMiddlePoint(offsetqy, offsetqy.Length / 2);//取平移后线的中点
            //平移两侧巷道
            //CreateFeature(pointCent, GetLayerByName("testpoint"));
            //CreateFeature(offsetqy, GetLayerByName("中心线全"));
            IPolyline offsethd1 = GetConstructOffsetHD(pline1, widthhd / 2, pointCent);
            IPolyline offsethd2 = GetConstructOffsetHD(pline2, widthhd1 / 2, pointCent);

            //取两条巷道与切眼交点
            IPoint pnt1 = GetIntersectPoint(offsethd1, offsetqy);
            IPoint pnt2 = GetIntersectPoint(offsethd2, offsetqy);

            ////理顺巷道线的方向
            IPoint    outpoint     = new PointClass();
            IPolyline offsethd1dir = GetPointPos(pline3.FromPoint, pline3.ToPoint, offsethd1, iDirect);
            IPolyline offsethd2dir = GetPointPos(pline3.FromPoint, pline3.ToPoint, offsethd2, iDirect);

            double dishd1 = 0; double alonghd1 = 0;

            offsethd1dir.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt1, false, outpoint, ref alonghd1, ref dishd1, ref bright);

            double dishd2 = 0; double alonghd2 = 0;

            offsethd2dir.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt2, false, outpoint, ref alonghd2, ref dishd2, ref bright);

            ICurve newhd1 = new PolylineClass();

            offsethd1dir.GetSubcurve(alonghd1, hcDis + alonghd1, false, out newhd1);

            ICurve newhd2 = new PolylineClass();

            offsethd2dir.GetSubcurve(alonghd2, hcDis + alonghd2, false, out newhd2);

            IPointCollection pntPolycol = new PolygonClass() as IPointCollection;
            IPointCollection pntlinecol = newhd1 as IPointCollection;
            int    i     = 0;
            IPoint point = null;

            for (i = 0; i < pntlinecol.PointCount; i++)
            {
                point = pntlinecol.get_Point(i);
                pntPolycol.AddPoint(point, ref obj, ref obj);
            }

            pntlinecol = newhd2 as IPointCollection;

            //取回采后切眼的中点
            IPolyline polylineendqy = new PolylineClass();

            if (point == null)
            {
                polylineendqy.FromPoint = point1;
                polylineendqy.ToPoint   = point2;
            }
            else
            {
                polylineendqy.FromPoint = point;
                polylineendqy.ToPoint   = pntlinecol.get_Point(pntlinecol.PointCount - 1);
            }
            IPoint pointendqyCent = ConstructMiddlePoint(polylineendqy, polylineendqy.Length / 2);//终点切眼的中点

            for (i = pntlinecol.PointCount - 1; i >= 0; i--)
            {
                point = pntlinecol.get_Point(i);
                pntPolycol.AddPoint(point, ref obj, ref obj);
            }
            pntPolycol.AddPoint(pointendqyCent, ref obj, ref obj);

            return(pntPolycol);
        }
Exemplo n.º 3
0
        private void btnok_Click(object sender, EventArgs e)
        {
            try
            {
                ILayer       pLayer    = null;
                IRasterLayer pRlayer   = null;
                ITinLayer    pTinlayer = null;
                ISurface     pSurface  = null;

                for (int i = 0; i < pMapControl.LayerCount; i++)
                {
                    if (pMapControl.get_Layer(i).Name == cmblayer.SelectedItem.ToString())
                    {
                        pLayer = pMapControl.get_Layer(i);
                    }
                }
                if (pLayer is IRasterLayer)
                {
                    pRlayer = pLayer as IRasterLayer;
                    IRasterSurface rasterSurf = new RasterSurfaceClass();
                    rasterSurf.PutRaster(pRlayer.Raster, 0);
                    pSurface = rasterSurf as ISurface;
                }
                else if (pLayer is ITinLayer)
                {
                    pTinlayer = pLayer as ITinLayer;
                    ITin ptin = pTinlayer.Dataset;
                    pSurface = (ISurface)ptin;
                }
                IPolyline pPolyline = pFeature.ShapeCopy as IPolyline;
                IGeometry pProfLine;
                IPoint    m_StartPoint = pPolyline.FromPoint;
                IPoint    m_EndPoint   = pPolyline.ToPoint;
                object    size         = new object();

                pSurface.GetProfile(pPolyline, out pProfLine, ref size);

                IPolyline     pNewLine      = pProfLine as IPolyline;
                double        iii           = pPolyline.Length;
                List <double> ZValue        = new List <double>();
                List <double> DistanceValue = new List <double>();
                DistanceValue.Add(0);
                ZValue.Add(pNewLine.FromPoint.Z);

                for (int i = 1; i < (int)pNewLine.Length; i++)
                {
                    DistanceValue.Add(i);
                    ICurve pCurve;
                    pNewLine.GetSubcurve(0, DistanceValue[i], false, out pCurve);
                    ZValue.Add(pCurve.ToPoint.Z);
                }
                DistanceValue.Add(pNewLine.Length);
                ZValue.Add(pNewLine.ToPoint.Z);

                double    roffset = inoffset.Value / 2;  //右轮偏移
                double    loffset = -inoffset.Value / 2; //左轮偏移
                IPolyline pRLine  = ConstructOffset(pPolyline, roffset);
                IPolyline pLLine  = ConstructOffset(pPolyline, loffset);
                IGeometry pLProfLine;
                IGeometry pRProfLine;
                pSurface.GetProfile(pRLine, out pRProfLine, ref size);
                pSurface.GetProfile(pLLine, out pLProfLine, ref size);
                IPolyline     pRNewline      = pRProfLine as IPolyline;
                IPolyline     pLNewline      = pLProfLine as IPolyline;
                List <double> ZRValue        = new List <double>();
                List <double> ZLValue        = new List <double>();
                List <double> RDistanceValue = new List <double>();
                List <double> LDistanceValue = new List <double>();
                RDistanceValue.Add(0);
                LDistanceValue.Add(0);
                ZRValue.Add(pRNewline.FromPoint.Z);
                ZLValue.Add(pLNewline.FromPoint.Z);
                for (int j = 1; j < (int)pRNewline.Length; j++)
                {
                    RDistanceValue.Add(j);
                    ICurve pCurve;
                    pRNewline.GetSubcurve(0, RDistanceValue[j], false, out pCurve);
                    ZRValue.Add(pCurve.ToPoint.Z);
                }
                RDistanceValue.Add(pRNewline.Length);
                ZRValue.Add(pRNewline.ToPoint.Z);
                for (int k = 1; k < (int)pLNewline.Length; k++)
                {
                    LDistanceValue.Add(k);
                    ICurve pCurve;
                    pLNewline.GetSubcurve(0, LDistanceValue[k], false, out pCurve);
                    ZLValue.Add(pCurve.ToPoint.Z);
                }
                LDistanceValue.Add(pLNewline.Length);
                ZLValue.Add(pLNewline.ToPoint.Z);

                FrmprofileGraph frmgraph = new FrmprofileGraph(ZValue, DistanceValue, pNewLine, ZRValue, RDistanceValue, ZLValue, LDistanceValue);
                frmgraph.ShowDialog();
                frmgraph.ShowInTaskbar = false;
                frmgraph.StartPosition = FormStartPosition.CenterScreen;
                #region ///

                ////用ISurface的 InterpolateShape方法,得到这条直线做剖面后的Geometry,方法说明详见帮助

                //IGeometry OutShape;

                //object size = new object();
                //pSurface.InterpolateShape(pPolyline, out OutShape, ref size);

                ////将结果QI为 PointCollection,QI成功显示结果是直线上单一的几个离散点,InterpolateShape会自动将分析的结果直线上选取六个等分的离散点,以这六个点的值来作曲线图
                //IPointCollection pointCollection = OutShape as IPointCollection;
                //IMAware maware = pointCollection as IMAware;
                //maware.MAware = true;
                //IZAware zaware = pointCollection as IZAware;
                //zaware.ZAware = true;
                //IMSegmentation mseg = pointCollection as IMSegmentation;
                ////设置M的值为距离
                //mseg.SetMsAsDistance(false);

                //IPointCollection newPointColl = new PolylineClass();
                //int count = pointCollection.PointCount;
                //for (int i = 0; i < count; i++)
                //{
                //    IPoint point = pointCollection.get_Point(i);
                //    IPoint newPoint = new PointClass();
                //    newPoint.X = point.M;
                //    newPoint.Y = point.Z;
                //    object missing = Type.Missing;
                //    newPointColl.AddPoint(newPoint, ref missing, ref missing);
                //}

                //#region

                ////IWorkspaceFactory wsFactory = new ShapefileWorkspaceFactoryClass();

                ////IWorkspaceName workspaceName = wsFactory.Create("F:", "temp", null, 0);

                //IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
                //IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
                //IName name = workspaceName as IName;
                //IWorkspace workspace = name.Open() as IWorkspace;

                //IFields fields = new FieldsClass();
                //IFieldsEdit fieldsEdit = fields as IFieldsEdit;
                //IField field = new FieldClass();
                //IFieldEdit fieldEdit = field as IFieldEdit;
                //fieldEdit.Name_2 = "OID";
                //fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                //fieldsEdit.AddField(field);

                //IGeometryDef geometryDef = new GeometryDefClass();
                //IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;
                //geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                //ISpatialReference spatialRef = new UnknownCoordinateSystemClass();
                //geometryDefEdit.SpatialReference_2 = (pRlayer as IGeoDataset).SpatialReference;


                //field = new FieldClass();
                //fieldEdit = field as IFieldEdit;
                //fieldEdit.Name_2 = "Shape";
                //fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //fieldEdit.GeometryDef_2 = geometryDef;
                //fieldsEdit.AddField(field);

                //IFieldChecker fieldChecker = new FieldCheckerClass();
                //IEnumFieldError enumFieldError = null;
                //IFields validatedFields = null;
                //fieldChecker.ValidateWorkspace = workspace;
                //fieldChecker.Validate(fields, out enumFieldError, out validatedFields);


                //IFeatureClass featureClass = (workspace as IFeatureWorkspace).CreateFeatureClass("test",
                //    validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                //IFeatureCursor featureCursor = featureClass.Insert(true);
                //IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
                //featureBuffer.Shape = pFeature as IGeometry;
                //featureCursor.InsertFeature(featureBuffer);
                //featureCursor.Flush();

                //#endregion

                //IFeatureLayer featureLayer = new FeatureLayerClass();
                //featureLayer.FeatureClass = featureClass;
                //featureLayer.Name = featureClass.AliasName;

                //pMapControl.AddLayer(featureLayer as ILayer);
                //pMapControl.Refresh();



                ////建立featureClass,为后面曲线图提供数据

                //IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
                //IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
                //IName name = (IName)workspaceName;
                //IWorkspace inmemWor = (IWorkspace)name.Open();

                //IFields fields = new FieldsClass();
                //IFieldsEdit fieldsEdit = fields as IFieldsEdit;
                //IField oidField = new FieldClass();
                //IFieldEdit oidFieldEdit = oidField as IFieldEdit;
                //oidFieldEdit.Name_2 = "OID";
                //oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                //fieldsEdit.AddField(oidField);

                //IGeometryDef geometryDef = new GeometryDefClass();
                //IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;
                //geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;
                //geometryDefEdit.HasM_2 = true;
                //geometryDefEdit.HasZ_2 = true;
                //ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
                //ISpatialReference spatialReference = pMapControl.SpatialReference;//spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                //ISpatialReferenceResolution spatialReferenceResolution = (ISpatialReferenceResolution)spatialReference; spatialReferenceResolution.ConstructFromHorizon();
                //ISpatialReferenceTolerance spatialReferenceTolerance = (ISpatialReferenceTolerance)spatialReference; spatialReferenceTolerance.SetDefaultXYTolerance();
                //geometryDefEdit.SpatialReference_2 = spatialReference;

                //IField geometryField = new FieldClass();
                //IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField;
                //geometryFieldEdit.Name_2 = "Shape";
                //geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //geometryFieldEdit.GeometryDef_2 = geometryDef;
                //fieldsEdit.AddField(geometryField);

                //IField mField = new FieldClass();
                //IFieldEdit mFieldEdit = (IFieldEdit)mField;
                //mFieldEdit.Name_2 = "M";
                //mFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                //mFieldEdit.Length_2 = 8;
                //fieldsEdit.AddField(mField);

                //IField zField = new FieldClass();
                //IFieldEdit zFieldEdit = (IFieldEdit)zField;
                //zFieldEdit.Name_2 = "Z";
                //zFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                //zFieldEdit.Length_2 = 8;
                //fieldsEdit.AddField(zField);

                //IFieldChecker fieldChecker = new FieldCheckerClass();
                //IEnumFieldError enumFieldError = null;
                //IFields validatedFields = null;
                //fieldChecker.ValidateWorkspace = inmemWor;
                //fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                //IFeatureClass featureClass = (inmemWor as IFeatureWorkspace).CreateFeatureClass("test", validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                //IFeatureCursor cursor = featureClass.Insert(true);
                //IFeatureBuffer buffer = featureClass.CreateFeatureBuffer();
                //int count = pointCollection.PointCount;
                //for (int i = 0; i < count; ++i)
                //{
                //    IPoint p = pointCollection.get_Point(i);
                //    buffer.Shape = p as IGeometry;
                //    buffer.set_Value(buffer.Fields.FindField("M"), p.M);
                //    buffer.set_Value(buffer.Fields.FindField("Z"), p.Z);
                //    cursor.InsertFeature(buffer);
                //}

                //cursor.Flush();

                ////开始做曲线图

                #endregion
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("该图像不能做剖面分析", "提示", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// clip a polyline at the specified lengths
        /// </summary>
        public static IPolyline ClipContour(IPoint npsPoint, IPolyline npsPolyline, double RangeLeft, double RangeRight)
        {
            ICurve NewPolyline = null, pl2, pl1;
            IPoint npsExactPoint;
            double PolylineLength, DistanceFromStart = 0, DistanceFromCurve = 0, NewLineEnd,
                AmountOver, start1 = 0, start2 = 0, end1 = 0, end2 = 0, NewLineStart;
            bool npsRightSide = false, IsOutOfBoundsLeft, IsOutOfBoundsRight;
            ISegmentCollection newpl = null;

            if (npsPolyline == null) return null;

            PolylineLength = npsPolyline.Length;

            //get the distance of the point from the start of the contour
            npsExactPoint = new PointClass();
            npsPolyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, npsPoint, false,
                npsExactPoint, ref DistanceFromStart, ref DistanceFromCurve, ref npsRightSide);

            //if (contour)polyline is not a closed line
            if (npsPolyline.IsClosed == false)
            {

                IsOutOfBoundsLeft = false;
                IsOutOfBoundsRight = false;

                NewLineStart = DistanceFromStart - RangeLeft;
                NewLineEnd = DistanceFromStart + RangeRight;

                if (NewLineStart < 0) IsOutOfBoundsLeft = true;

                if (NewLineEnd > PolylineLength) IsOutOfBoundsRight = true;

                //if contour is outbound to the left, then try to shift it to the right
                if (IsOutOfBoundsLeft == true && IsOutOfBoundsRight == false)
                {

                    AmountOver = (DistanceFromStart - RangeLeft) * -1;

                    if (((DistanceFromStart + RangeRight) + AmountOver) < PolylineLength)
                    {
                        NewLineStart = 0;
                        NewLineEnd = (DistanceFromStart + RangeRight) + AmountOver;
                    }
                    else
                    {
                        NewLineStart = -1;
                        NewLineEnd = -1;
                    }
                }

                //if contour is out of bounds to the right, then try to shift it to the left
                if (IsOutOfBoundsLeft == false && IsOutOfBoundsRight == true)
                {
                    AmountOver = (DistanceFromStart + RangeRight) - PolylineLength;

                    if (((DistanceFromStart - RangeLeft) - AmountOver) >= 0)
                    {

                        NewLineStart = (DistanceFromStart - RangeLeft) - AmountOver;
                        NewLineEnd = PolylineLength;
                    }
                    else
                    {
                        NewLineStart = -1;
                        NewLineEnd = -1;
                    }
                }

                //since the contour is to short on both ends to create the new polyline,abound operation
                if (IsOutOfBoundsLeft == true && IsOutOfBoundsRight == true)
                {
                    NewLineStart = -1;
                    NewLineEnd = -1;
                }

                if (NewLineStart != -1 && NewLineEnd != -1)
                {

                    NewPolyline = new PolylineClass();
                    npsPolyline.GetSubcurve(NewLineStart, NewLineEnd, false, out NewPolyline);

                }
            }
            else //if polyline is closed
            {
                if ((RangeLeft + RangeRight) < PolylineLength)
                {

                    pl1 = new PolylineClass();
                    pl2 = new PolylineClass();
                    newpl = new PolylineClass();

                    //if desired subcurve does not cross the start/end point of the closed polyline(circular) then get
                    //a sub curve as normal
                    if ((DistanceFromStart - RangeLeft) >= 0 && (DistanceFromStart + RangeRight) < PolylineLength)
                    {

                        NewLineStart = DistanceFromStart - RangeLeft;
                        NewLineEnd = DistanceFromStart + RangeRight;

                        NewPolyline = new PolylineClass();
                        npsPolyline.GetSubcurve(NewLineStart, NewLineEnd, false, out NewPolyline);

                    }
                    else
                    {
                        //if desired subcurve does cross the start/end point of the closed polyline(circular)
                        //then two subcurves will have to be formed each ending at the start/end point of the circle

                        //if left range oversteps start/end then...
                        if ((DistanceFromStart - RangeLeft) < 0)
                        {

                            start1 = PolylineLength - ((DistanceFromStart - RangeLeft) * -1);
                            end1 = PolylineLength;
                            start2 = 0;
                            end2 = DistanceFromStart + RangeRight;

                        }

                        //if right range oversteps start/end then...
                        if ((DistanceFromStart + RangeRight) > PolylineLength)
                        {

                            start1 = DistanceFromStart - RangeLeft;
                            end1 = PolylineLength;
                            start2 = 0;
                            end2 = (DistanceFromStart + RangeRight) - PolylineLength;

                        }

                        //combine sub curves
                        npsPolyline.GetSubcurve(start1, end1, false, out pl1);
                        npsPolyline.GetSubcurve(start2, end2, false, out pl2);
                        newpl.AddSegmentCollection(pl1 as ISegmentCollection);
                        newpl.AddSegmentCollection(pl2 as ISegmentCollection);
                        NewPolyline = newpl as ICurve;

                    }
                }
            }

            return NewPolyline as IPolyline;
        }