Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon Offset Example #294

Open
nsiatras opened this issue Jun 2, 2022 · 10 comments
Open

Polygon Offset Example #294

nsiatras opened this issue Jun 2, 2022 · 10 comments

Comments

@nsiatras
Copy link

nsiatras commented Jun 2, 2022

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

@randallwhitman
Copy link
Contributor

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

@stolstov
Copy link
Member

stolstov commented Jun 2, 2022

@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
			}
		}
	}

@nsiatras
Copy link
Author

nsiatras commented Jun 2, 2022

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 ?

@nsiatras
Copy link
Author

nsiatras commented Jun 2, 2022

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]]]}

@nsiatras
Copy link
Author

nsiatras commented Jun 2, 2022

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.

@nsiatras
Copy link
Author

nsiatras commented Jun 4, 2022

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

@stolstov
Copy link
Member

stolstov commented Jun 6, 2022

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

@nsiatras
Copy link
Author

nsiatras commented Jun 8, 2022

@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.

@stolstov
Copy link
Member

stolstov commented Jun 8, 2022

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.

@nsiatras
Copy link
Author

nsiatras commented Jun 8, 2022

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants