Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Find center of a polygon

This is a discussion on Find center of a polygon within the MapPoint Desktop Discussion forums, part of the Map Forums category; Does anyone know how, given the lat,lon coordinates of all the points around a polygon shape I can then find ...

  1. #1
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Find center of a polygon

    Does anyone know how, given the lat,lon coordinates of all the points around a polygon shape I can then find the center of that shape. I'm trying to do this in VB .net but if anyone knows the equation or how this should be down in the real world it may help

  2. #2
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    The centre of a polygon is called the polygon's centroid.
    In Euclidean space, a centroid is calculated by converting the vectors to cartesian vectors (if they aren't already), summing them together, and dividing by N, where N is the number of points.

    Eg. the centre of a triangle with points (x1,y1); (x2,y2); (x3,y3) is:

    Centroid X coord = (x1+x2+x3) / 3
    Centroid Y coord = (y1+y2+y3) / 3

    Depending on the size of your polygon and the acceptable errors, you could do this with longitudes and latitudes. I wouldn't even think about doing this near the poles, or anything bigger than about 100 miles. Your tolerances for errors might be greater or less though.

    To do it "properly", you might be able to find a weighted addition for lat,long. Or you could convert each coordinate into 3d cartesian coords relative to the Earth's centre (this is simple trigonometry).
    Do the add/divide, then convert back again.
    Just before converting back, you may have normalise to bring the centroid onto the Earth's surface.


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  3. #3
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Thanks for your help, this appears to work well and we don't really need a huge degree of accuracy, however I might try it as you suggested with 3d catesian coords, doesn't appear too much more work and if its going to increase the level of accuracy then I may as well put it in.

    Thanks again for your help.

  4. #4
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Sorry just one more thing, given the lat, lon coords of both ends of two straight lines how can I determine if the lines cross or not. (I really should have paid more attention in Maths class!)

  5. #5
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    In Cartesian coordinates, you with a cross product I think. I'd have to look it up (the Graphics Gems series are good for that type of thing).

    For "on a sphere", the Aviation Forumlary is a good source:

    http://williams.best.vwh.net/avform.htm

    The "Intersecting Radials" formula looks like it would be a good start, although it defines the lines as bearings from start points.


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  6. #6
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Thanks for your help, just had a quick look at the link you sent and I think it covers a lot of the areas i'm looking for.

    Thanks again for your help

  7. #7
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    Yes, I find it a useful reference - probably one of my most useful "reference" bookmarks.


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  8. #8
    andrem is offline Junior Member White Belt
    Join Date
    Apr 2003
    Posts
    7
    Quote Originally Posted by Winwaed
    The centre of a polygon is called the polygon's centroid.
    In Euclidean space, a centroid is calculated by converting the vectors to cartesian vectors (if they aren't already), summing them together, and dividing by N, where N is the number of points.

    Eg. the centre of a triangle with points (x1,y1); (x2,y2); (x3,y3) is:

    Centroid X coord = (x1+x2+x3) / 3
    Centroid Y coord = (y1+y2+y3) / 3

    Depending on the size of your polygon and the acceptable errors, you could do this with longitudes and latitudes. I wouldn't even think about doing this near the poles, or anything bigger than about 100 miles. Your tolerances for errors might be greater or less though.
    Richard
    Hi Richard. Are you saying that the formula for a polygon with n points in decimal degrees is close to :

    X = (x1 + x2 + x3 + ... + xn)/n ?

    I found some other formula, but I'm not sure is this applies to geographic coordinates as it requires an A (area) calculation:

    // X = SUM[(Xi + Xi+1) * (Xi * Yi+1 - Xi+1 * Yi)] / 6 / A
    // Y = SUM[(Yi + Yi+1) * (Xi * Yi+1 - Xi+1 * Yi)] / 6 / A
    // Here A is the area of the polygon and the sum is taken over all points 0 to n-1 where n = number of polypoints.
    // BUT A is then in square hours ?

    Couldn't find anything on polygons on the link you sent
    Cheers

    André

  9. #9
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    The link was with reference to the second question about crossing lines.

    The formula I gave for a centre-of-a-polygon is based on 2d Euclidean coordinates. It can be easily extended to 3 (or more) dimensions by performing the same calculation for the extra ordinates.

    For longitude and latitude with some accuracy, I would consider converting your longitude,latitudes into Earth-centred Cartesian coordinates, finding the centroid, and then projecting back to the Earth's surface (the centre of a polygon on the Earth's surface will be inside the Earth).
    Note that this might become unstable if you have coordinates over a wide area - ie. if the calculated centroid is near the centre of the Earth.

    I'm not sure what the formula that you give, does. With an area calculation, does it measure somekind of point density????


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  10. #10
    andrem is offline Junior Member White Belt
    Join Date
    Apr 2003
    Posts
    7
    Hi,

    Got it from here: http://www.geog.ubc.ca/courses/klink...html#SEC33.4.1

    (this also mentions: some programs calculate the centroid by averaging the x and y coordinates of the polygon vertices
    this does not give the centroid)

    maybe your formula only works for regular polygons (octagons, etc)?

    I'm still clueless.
    Cheers

    André

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Center Point
    By colin_turner99 in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 07-14-2006, 02:38 PM
  2. Finding a geoevent in a polygon
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 03-15-2005, 03:33 AM
  3. Information within polygon
    By Dazzer in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-28-2004, 09:50 AM
  4. Distance from Polygon
    By random0000 in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-14-2003, 10:18 PM
  5. Query by shape / polygon
    By blackmap in forum MapPoint Desktop Discussion
    Replies: 7
    Last Post: 02-12-2003, 04:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27