4

I am creating BaseTool using ArcObjects with C#. The tool should reduce the polygon and move along the coordinate axis. I managed to reduce the polygon. When I want to use the PutCoords() function to offset a polygon, it will move very much to the bottom left corner. This happens with any parameter values for the PutCoords() function.

private void ExtendPolygon(ref IFeature pPolygonFt)
    {            
        IMxDocument pDoc = m_application.Document as IMxDocument;
        IMap pMap = pDoc.Maps.get_Item(0);
        IArea pArea;
        pArea = pPolygonFt.Shape as IArea;            
        IPoint Center = pArea.Centroid; 
        Center.PutCoords(-1, -1);
        ITransform2D pTrans = pPolygonFt.Shape as ITransform2D;
        pTrans.Scale(Center, 0.5, 0.5);
        IEnvelope pPolyEnvelope = pPolygonFt.Extent;
        IFeatureLayer pFtLayer = pMap.get_Layer(1) as FeatureLayer;
        IFeatureClass pOutClass = pFtLayer.FeatureClass;
        IFeature ExtFt = pOutClass.CreateFeature();
        ExtFt.Shape = pPolygonFt.Shape; 
        pArea = ExtFt.Shape as IArea;
        ExtFt.set_Value(2, pArea.Area);
        ExtFt.Store();
        pDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        pMap.SelectFeature(pMap.get_Layer(1), ExtFt);
        pDoc.ActivatedView.Extent = pPolyEnvelope;
        pDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
    }

I am use Visual Studio 2015, ArcMap 10.5, ArcObjects 10.5.

How can I fix this situation? Or how else can you shift the polygon along the coordinate axis?

When i use Move (-dx, -dy). the polygon is displaced a very large distance from the original position and not what I want. I enter different values, but nothing changes.

enter image description here

6
  • What command are you using to offset the polygon? pTrans.Move(dx, dy) should work. Also be careful with your order of operations, if you calculated the center, then moved the polygon, then scaled the polygon, the result is probably not what you intend.
    – danielm
    Oct 12 '20 at 17:10
  • What do you mean by coordinate axis? Could you please add a screenshot showing what you are trying to do? before and after. If your data has geographic coordinates, it is possible you get unintended results. Oct 12 '20 at 18:14
  • It's hard to tell from your image. Is the shape still the same in the new location or is it deformed? Also what distance is it moving in the after image and how far do you intend to move it?
    – danielm
    Oct 12 '20 at 18:53
  • What is the unit of coordinate, lat/long or meter/inch etc.? I suggest you to add a base map to see where the polygon is displaced. Oct 12 '20 at 18:55
  • @KadirŞahbaz I want to manage polygon layers. These layers are in the WGS_1984 coordinate system. The problem is that these are geographic coordinate systems?
    – Nolu
    Oct 12 '20 at 19:08
3

Setting the coordinates for Center doesn't mean displacing the polygon to those coordinates. A centroid doesn't represent the polygon itself, it is just a point. Center.PutCoords(-1, -1); means just setting (-1, -1) coordinates for a point which has the same coordinates as the polygon's centroid.

Use that way:

private void ExtendPolygon(ref IFeature pPolygonFt)
    {
        ...         
        ...           
        IPoint Center = pArea.Centroid; 
        ITransform2D pTrans = pPolygonFt.Shape as ITransform2D;
        dx = Center.X - 1
        dy = center.Y - 1
        pTrans.Scale(Center, 0.5, 0.5);
        pTrans.Move(-dx, -dy)
        ...
        ...
    }
2
  • Thank you! This helped me to offset the X and Y axis. Unfortunately, the polygon is displaced a very large distance from the original position and not what I want. I enter different values, but nothing changes.
    – Nolu
    Oct 12 '20 at 18:09
  • I edited the question and attach a picture.
    – Nolu
    Oct 12 '20 at 18:44
3

The correct solution turned out to be that Move shifts by a relative number of units. It is necessary to immediately transfer to the parameters by how much to shift (do not set relative to the center) For example pTrans.Move(0, 0.2);

private void ExtendPolygon(ref IFeature pPolygonFt)
    {
        ...         
        ...           
        IPoint Center = pArea.Centroid; 
        ITransform2D pTrans = pPolygonFt.Shape as ITransform2D;
        pTrans.Scale(Center, 0.5, 0.5);
        pTrans.Move(0, 0.2);
        ...
        ...
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.