Skip to content

Polygon Offset Example #294

Open
Open

Description

@nsiatras

Hello,

I am wondering if there is any example on how to perform polygon offsetting.

I have a double[][] array with the polygon vertices points in clockwise order and I want to inflate it by 2mm.
Is there any example code on how to perform the offseting ?

Thank you in advance

Activity

  1. randallwhitman commented on Jun 2, 2022

    @randallwhitman
    Contributor

    Hi @nsiatras - take a look at GeometryEngine.buffer / OperatorBuffer .

  2. stolstov commented on Jun 2, 2022

    @stolstov
    Member

    @nsiatras Is this the behavior that you want? http://esri.github.io/geometry-api-java/doc/Buffer.html
    If yes, then this is a sample code:

    	{
    		Polygon polygon = new Polygon();
    		//added one exterior ring (must be clockwise)
    		polygon.startPath(-10, -10);
    		polygon.lineTo(-10, 10);
    		polygon.lineTo(10, 10);
    		polygon.lineTo(10, -10);
    		//added one hole (must be counterclockwise)
    		polygon.startPath(-5, -5);
    		polygon.lineTo(5, -5);
    		polygon.lineTo(5, 5);
    		polygon.lineTo(-5, 5);
    
    		//buffer with the distance of 2
    		Geometry resultGeom = OperatorBuffer.local().execute(polygon, null, 2, null);
    		Polygon resultPolygon = (Polygon)resultGeom;
    		Point2D pt = new Point2D();
    		//Extract each vertex of the polygon
    		//loop over rings
    		for (int ipath = 0, npaths = resultPolygon.getPathCount(); ipath < npaths; ++ipath) {
    			//loop over vertices in each ring
    			for (int ivert = resultPolygon.getPathStart(ipath), 
    					endVertex = resultPolygon.getPathEnd(ipath); ivert < endVertex; ++ivert) {
    				resultPolygon.getXY(ivert, pt);
    				//The x,y coordinates are pt.x, pt.y
    			}
    		}
    	}
    
  3. nsiatras commented on Jun 2, 2022

    @nsiatras
    Author

    Thank you all for your replies.

    @stolstov I tried your example. For a 16 vertices polygon I get 104vertices after I inflate it :)
    Is there a way to make the inflated polygon a bit... smaller ?

  4. nsiatras commented on Jun 2, 2022

    @nsiatras
    Author

    PS this is my polygon
    (com.esri.core.geometry.Polygon) {"rings":[[[25,20],[20,25],[20,55],[25,60],[55,60],[60,55],[60,25],[55,20],[25,20]]]}

  5. nsiatras commented on Jun 2, 2022

    @nsiatras
    Author

    Perhaps I have to use the OperatorOffset.local().execute instead of OperatorBuffer.local().execute. All I want is to make an outline border outside of a polygon.

  6. nsiatras commented on Jun 4, 2022

    @nsiatras
    Author

    Hello again,

    I managed to buffer a polygon.
    Screenshot

    On the left you can see the buffer in blue color. On the right I marked the initial curves as they were "extended".
    Is it possible to get the X,Y start and X,Y end of the initial curves after I buffer a polygon ?
    I do not need the other points.

    Thank you in advance

  7. stolstov commented on Jun 6, 2022

    @stolstov
    Member

    @nsiatras Buffer operation does not remember the original vertices, so there is no way to obtain those directly from the buffer polygon.

  8. nsiatras commented on Jun 8, 2022

    @nsiatras
    Author

    @stolstov I see.. The reason I need the original vertices after they are buffered is because some polygons has Arcs.
    I was hopping to split the arc to 3 points and after the buffering, recovering the arc from the 3 initial points.

  9. stolstov commented on Jun 8, 2022

    @stolstov
    Member

    In some more complicated cases the arcs intersect with each other and only partial. That happens when the polygon border has a lot of details and the buffer width is large.

  10. nsiatras commented on Jun 8, 2022

    @nsiatras
    Author

    I managed to inflate a polygon with arcs. I split arc into small linear segments and I use the points to form a polygon.
    It works fine on all of my tests. Do you think there is a way to convert points back to arcs ?

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions