Hi,
One of my requirement is like I plot one polygon. With that polygon one more polygon I want to plot polygon with 2 degree expansion. I thought buffer will work for it. But because of more difference in distance it is giving more round edges shape. Where I want proper straight line polygon shape. Please suggest any other functionality can help to achieve this.
For reference I have attached image file of drawing of polygons.
Thanks & Regards,
Goral
Expand and redraw polygon
Hi Goral,
The “ScaleUp” is proper to this scenario as following statements:
MultipolygonShape multipolygon1 = new MultipolygonShape(@"MULTIPOLYGON(((-62.6910512132511 5.96891783124271,-41.5592361957667 36.9622465235532,-15.8488612578273 20.9372868019608,12.3268920988186 45.4149725305469,42.0875315817758 22.3460744697931,-16.0249597163063 -6.5340727207689,-16.0249597163063 -6.5340727207689,-62.6910512132511 5.96891783124271)))");
multipolygon1.ScaleUp(2.0);
Thanks,
Casper
Hi,
Thanks for reply. Its working fine. One more doubt. Can you please give some relationship of percentage with degree or distance ? Because how to judge how much percentage should I give if I want to scaleup feature by 2 degree.
Thanks,
Goral
Hi Goral,
I think that you will iterate all vertices of the polygon’s outer ring, and scale every point to specified length as following statements:
static void ScaleOneRing(RingShape targetRingShape, double specifiedLength, double centerX, double centerY)
{
for (int i = 0; i < targetRingShape.Vertices.Count; i++)
{
double newX = ((targetRingShape.Vertices[i].X - centerX) + specifiedLength) + centerX;
double newY = ((targetRingShape.Vertices[i].Y - centerY) + specifiedLength) + centerY;
targetRingShape.Vertices[i] = new Vertex(newX, newY);
}
}
Thanks,
Hi,
Thanks for reply. I have tried given solution. I don’t know I am doing something wrong or not. In result I am getting whole polygon shifted two degree. Due to this two polygons drawn at two different places. Please suggest where is the problem.
Thanks,
Goral
Hi Goral,
I’m sorry for missing some condition about this scenario, I rewrite a function to implement this issue as following statements:
private void ScaleOneRing(RingShape targetRingShape, double specifiedLength, double centerX, double centerY)
{
for (int i = 0; i < targetRingShape.Vertices.Count; i++)
{
double distance = Math.Sqrt((targetRingShape.Vertices[i].X - centerX) * (targetRingShape.Vertices[i].X - centerX) + (targetRingShape.Vertices[i].Y - centerY) * (targetRingShape.Vertices[i].Y - centerY));
double ratio = (distance + specifiedLength) / distance;
double newX = ((targetRingShape.Vertices[i].X - centerX) * ratio) + centerX;
double newY = ((targetRingShape.Vertices[i].Y - centerY) * ratio) + centerY;
targetRingShape.Vertices[i] = new Vertex(newX, newY);
}
}
Thanks,
Hi,
Thanks for reply. Its working as per requirement. If any further clarification required I will get back to you.
Thanks,
Goral
Hi Goral,
Very glad to hear it works.
Any question please feel free to let us know.
Regards,
Kevin.
Hi,
One question is if I want to enter specified length in Nautical mile instead of Degrees what to change in code? Please guide.
Thanks,
Goral
Hi Goral,
You should want to convert Natuical mile to Decimal Degree before calculate it.
The wikipedia said: The nautical mile is nearly equal to a minute of latitude on a chart. So I think if you don’t need very precise result, you can easily convert between them. If you need better result please find a algorithm for conversion.
Regards,
Don