Update Point in Polyline. C#

2401
7
Jump to solution
06-11-2012 11:56 PM
RustamTimerbaev
New Contributor II
            int hitPartIndex;             hitPartIndex = gcPolyline.GeometryCount;             hitPartIndex--;               IGeometry geometry = gcPolyline.get_Geometry(hitPartIndex);                var pointCollection = (IPointCollection4)geometry;                int indextransformPoint;               indextransformPoint = pointCollection.PointCount;               indextransformPoint--;                Double zOffset = Convert.ToDouble( textBox3.Text);                MessageBox.Show("zOffset = " + textBox3.Text);                            if (zOffset == 0 )                   return gcPolyline as IPolyline;             IPoint TestPoint;             TestPoint = pointCollection.get_Point(0);             TestPoint.X = pointCollection.get_Point(0).X;             TestPoint.Y = pointCollection.get_Point(0).Y;             TestPoint.Z = pointCollection.get_Point(0).Z + zOffset;              MessageBox.Show("test.z = " + TestPoint.Z.ToString());              var transform3D = (ITransform3D)TestPoint;             transform3D.Move3D(0, 0, zOffset);             pointCollection.UpdatePoint(indextransformPoint, TestPoint);


Here i have 2 message boxes. First: zOffset = 150. Second: test.z = 223. But in selected polyline Z-value not change, why?
0 Kudos
1 Solution

Accepted Solutions
RustamTimerbaev
New Contributor II
richwawr, thank you for help. I found working example for this question.

        IApplication m_application;          public frmSetHeight()         {             InitializeComponent();         }          private void btnCancel_Click(object sender, EventArgs e)         {             this.Close();         }          private void btnOK_Click(object sender, EventArgs e)         {             m_application = AddHeight.ArcScene.Application;             ISxDocument pDoc =  ArcScene.Document;             IFeatureLayer pFtrLyr = GetCurrentFeatyreLayer();             IFeatureSelection pFtrSel = pFtrLyr as IFeatureSelection;                          IQueryFilter pFilter = new QueryFilterClass();             pFilter.WhereClause = "";             ICursor cursor;             pFtrSel.SelectionSet.Search(pFilter, false, out cursor);             IFeatureCursor pFtrCsr = cursor as IFeatureCursor;             IFeature pFtr = pFtrCsr.NextFeature();                          while(pFtr != null)             {                 ITransform3D trans3D = pFtr.Shape as ITransform3D;                 double dx = 0;                 double dy = 0;                 double dz = Convert.ToDouble(textBox1.Text);                  trans3D.Move3D(dx, dy,dz);                 pFtr.Store();                 pFtr = pFtrCsr.NextFeature();                              }                pDoc.Scene.SceneGraph.Invalidate (pFtrLyr, true, true );             pDoc.Scene.SceneGraph.RefreshViewers();         }          private IFeatureLayer GetCurrentFeatyreLayer()         {             var pLayer = ((ISxDocument)m_application.Document).SelectedLayer;             return pLayer as IFeatureLayer;         }

View solution in original post

0 Kudos
7 Replies
RichWawrzonek
Occasional Contributor
You need to cast your TestPoint to the IZAware interface and set the ZAware property = true

Something like this should work:

IZAware zAware = TestPoint as IZAware;
zAware.ZAware = true;
0 Kudos
RustamTimerbaev
New Contributor II
            int hitPartIndex = 0;
            hitPartIndex = gcPolyline.GeometryCount;
            hitPartIndex--;
              IGeometry geometry = gcPolyline.get_Geometry(hitPartIndex);
           
              var pointCollection = (IPointCollection4)geometry;

              int indextransformPoint = 1;
              indextransformPoint = pointCollection.PointCount;
              MessageBox.Show("indexTransformPoint = " + indextransformPoint.ToString() + 
                  "\nhitPartIndex = " + hitPartIndex.ToString());

              indextransformPoint--;

              Double zOffset = Convert.ToDouble( textBox3.Text);

              MessageBox.Show("zOffset = " + textBox3.Text);

              if (zOffset == 0 )
                  return gcPolyline as IPolyline;
            IPoint TestPoint;
            TestPoint = pointCollection.get_Point(indextransformPoint);
            TestPoint.X = pointCollection.get_Point(indextransformPoint).X;
            TestPoint.Y = pointCollection.get_Point(indextransformPoint).Y;
            TestPoint.Z = pointCollection.get_Point(indextransformPoint).Z + zOffset;

            
            var transform3D = (ITransform3D)TestPoint;
            transform3D.Move3D(0, 0, zOffset);

            var newTestPoint = (IPoint)transform3D;

            IZAware zAware = newTestPoint as IZAware;
            zAware.ZAware = true;

            pointCollection.UpdatePoint(indextransformPoint, newTestPoint);

            MessageBox.Show(pointCollection.get_Point(indextransformPoint).Z.ToString());

            m_application.RefreshWindow();


Doesn't work 😞

And, for example, i use IGeometryBridge:
IPoint[] array = new IPoint[1];

            array[0] = newTestPoint;

            IGeometryBridge testBridge = new GeometryEnvironmentClass();
            //MessageBox.Show("until testBridge");
            try
            {
                testBridge.ReplacePoints(pointCollection, 0, 1, array);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            //MessageBox.Show("after testBridge"); 

But here i see only Exception errors...
0 Kudos
RichWawrzonek
Occasional Contributor
I would have put the zaware code before you set the z value of TestPoint
0 Kudos
RustamTimerbaev
New Contributor II
Hmm, doesn't work too. And another question, how to use IGeometryBridge? Please see code in previous post. It's correct?
I think, i may use this method.
0 Kudos
RichWawrzonek
Occasional Contributor
In your geometry bridge code you create a new testBridge object but don't add any geometries to it. So when you try to use ReplacePoints method there are no points to replace.
0 Kudos
RustamTimerbaev
New Contributor II
Oh, ok, IGeometryBridge more hardest. Please see that, i think, error in function call.
            IPolyline pl = null;
            IFeature feature;
            pl = (IPolyline)feature.Shape;
            feature.Shape = ModifyVertexOfAPolyline((IGeometryCollection)pl);

ModifyVertexOfAPolyline:
        private IPolyline ModifyFirstVertexOfAPolyline(IGeometryCollection gcPolyline)
        {
            int hitPartIndex = 0;
            hitPartIndex = gcPolyline.GeometryCount;
            hitPartIndex--;
              IGeometry geometry = gcPolyline.get_Geometry(hitPartIndex);

              var pointCollection = (IPointCollection4)geometry;

              int indextransformPoint = 1;
              indextransformPoint = pointCollection.PointCount;
              MessageBox.Show("indexTransformPoint = " + indextransformPoint.ToString() + 
                  "\nhitPartIndex = " + hitPartIndex.ToString());

              indextransformPoint--;

              Double zOffset = Convert.ToDouble( textBox3.Text);
              if (zOffset == 0 )
                  return gcPolyline as IPolyline;
            IPoint TestPoint;
            TestPoint = pointCollection.get_Point(indextransformPoint);
            IZAware zAware = TestPoint as IZAware;
            zAware.ZAware = true;
            TestPoint.X = pointCollection.get_Point(indextransformPoint).X;
            TestPoint.Y = pointCollection.get_Point(indextransformPoint).Y;
            TestPoint.Z = pointCollection.get_Point(indextransformPoint).Z + zOffset;
            var transform3D = (ITransform3D)TestPoint;
            transform3D.Move3D(0, 0, zOffset);
            TestPoint = (IPoint)transform3D;
            var newTestPoint = (IPoint)transform3D;
            pointCollection.UpdatePoint(indextransformPoint, TestPoint);
            MessageBox.Show(pointCollection.get_Point(indextransformPoint).Z.ToString());
            m_application.RefreshWindow();
            return pointCollection as IPolyline;
        }


I am so stupid in this SDK, sorry...

-------------------Added-------------------
Top code example updated. This is "new" version:
            IPolyline pl = null;
            IFeature feature;
            pl = (IPolyline)feature.Shape;
            feature.Shape = ModifyVertexOfAPolyline((IGeometryCollection)pl);
            feature.Store();

After execute this, all selected shapes rewrited to this: [ATTACH=CONFIG]15185[/ATTACH]
In identify window: [ATTACH=CONFIG]15186[/ATTACH]
0 Kudos
RustamTimerbaev
New Contributor II
richwawr, thank you for help. I found working example for this question.

        IApplication m_application;          public frmSetHeight()         {             InitializeComponent();         }          private void btnCancel_Click(object sender, EventArgs e)         {             this.Close();         }          private void btnOK_Click(object sender, EventArgs e)         {             m_application = AddHeight.ArcScene.Application;             ISxDocument pDoc =  ArcScene.Document;             IFeatureLayer pFtrLyr = GetCurrentFeatyreLayer();             IFeatureSelection pFtrSel = pFtrLyr as IFeatureSelection;                          IQueryFilter pFilter = new QueryFilterClass();             pFilter.WhereClause = "";             ICursor cursor;             pFtrSel.SelectionSet.Search(pFilter, false, out cursor);             IFeatureCursor pFtrCsr = cursor as IFeatureCursor;             IFeature pFtr = pFtrCsr.NextFeature();                          while(pFtr != null)             {                 ITransform3D trans3D = pFtr.Shape as ITransform3D;                 double dx = 0;                 double dy = 0;                 double dz = Convert.ToDouble(textBox1.Text);                  trans3D.Move3D(dx, dy,dz);                 pFtr.Store();                 pFtr = pFtrCsr.NextFeature();                              }                pDoc.Scene.SceneGraph.Invalidate (pFtrLyr, true, true );             pDoc.Scene.SceneGraph.RefreshViewers();         }          private IFeatureLayer GetCurrentFeatyreLayer()         {             var pLayer = ((ISxDocument)m_application.Document).SelectedLayer;             return pLayer as IFeatureLayer;         }
0 Kudos