寻找多边形的中点 [英] Finding Middle point of Polygon

查看:503
本文介绍了寻找多边形的中点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
请帮助我,我想使用SQL Server或C#或javascripts在gmap中查找多边形的中间纬度和经度,请帮助

在此先感谢

hi to all
Please help me, i want to find the middle lattitude and longitude of a polygon in gmap using sql server or C# or javascripts please help

thanks in advance

推荐答案

首先根据数学概念定义中间点".
如果您是指多边形的中心:
常规多边形案例:
在规则多边形的情况下,中心是与每个顶点或角等距的点.它也是多边形的内切圆和外切圆的中心.
不规则多边形盒
不规则多边形不被视为具有中心,因为每个顶点不太可能有一个等距的点.但是,不规则多边形可以具有质心或重心.
如果您是指多边形的质心,请参见此文章: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ [ ^ ].
您还可以通过分别计算经度和纬度值的平均值来计算向量平均值.
First of all define the "middle point" in terms of mathematical concepts.
If you mean the center of a polygon:
Regular Polygon case:
In the case of regular polygons the center is the point that is equidistant from each vertex or corner. It is also the center of the polygon''s incircle and circumcircle.
Irregular Polygon case
Irregular polygons are not considered as having a center, since there is unlikely to be any one point equally distant form each vertex. However, an irregular polygon can have a centroid, or center of gravity.
If you mean the centroid of a polygon see this article: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/[^].
You can also calculate a vector mean, by calculating a mean for longitude and latitude values respectively.


这是一个JavaScript函数,可以获取多边形并返回Point .您可以使用此功能来计算多边形的中心.

功能:
this is a JavaScript function who get a Polygon and return a Point. you can use this function to calculate center of a Polygon.

Function:
function getCenterOfPolygon(polygon){
	var PI=22/7
	var X=0;
	var Y=0;
	var Z=0;
	polygon.getPath().forEach(function (vertex, inex) {
		lat1=vertex.lat();
		lon1=vertex.lng();
		lat1 = lat1 * PI/180
		lon1 = lon1 * PI/180
		X += Math.cos(lat1) * Math.cos(lon1)
		Y += Math.cos(lat1) * Math.sin(lon1)
		Z += Math.sin(lat1)
	})
	Lon = Math.atan2(Y, X)
	Hyp = Math.sqrt(X * X + Y * Y)
	Lat = Math.atan2(Z, Hyp)
	Lat = Lat * 180/PI
	Lon = Lon * 180/PI 
	return new google.maps.LatLng(Lat,Lon);
}



用途:



Use:

var pt=getCenterOfPolygon(mapPolygon);
alert(pt.lat()+","+pt.lng());


解决方案1非常详细,谢谢Zoltan

下面是简化版

考虑坐标为(x1,y1)的多边形(五角大楼); (x2,y2); (x3,y3); (x4,y4); (x5,y5),则质心应为

重心X坐标=(x1 + x2 + x3 + x4 + x5)/5
重心Y坐标=(y1 + y2 + y3 + y4 + y5)/5

您可以将X用作纬度,将Y用作经度,并可以指向质心.

如果您使用任何映射工具/库,则该库本身应具有此功能以创建具有质心的多边形.

如果您要在DigitalMap上创建任何功能,则附加的公式将来可能会帮助您 http://williams.best.vwh.net /avform.htm [ ^ ].


也是 http://www.geog.ubc.ca/course/klink/gis.notes/ncgia/u33.html#SEC33.4.1 [
Solution 1 is well detailed and thank you Zoltan

Below is simplified version

Consider polygon (Pentagon) with co-ordinates (x1,y1); (x2,y2); (x3,y3); (x4,y4); (x5,y5) then centroid should be

Centroid X coord = (x1+x2+x3+x4+x5) / 5
Centroid Y coord = (y1+y2+y3+y4+y5) / 5

You can use X as latitude and Y as longitude and can point Centroid.

If you are using any mapping tool/library then that library itself should have this functionality to create a polygon with centroid.

If you are creating any functionality on a DigitalMap then attached formulas might help you in future http://williams.best.vwh.net/avform.htm[^].


Also this http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u33.html#SEC33.4.1[^] might help you to generate source code for your formulas.

Cheers and best of luck!

Thanks
Rushikesh Joshi


这篇关于寻找多边形的中点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆