[Gdal-dev] Center of polygon

Chapman, Martin MChapman at sanz.com
Fri Apr 16 12:28:15 EDT 2004


Mathieu,

The pExtent parameter is the bounding rect for the polygon you want the center point of.  For instance, if you had a layer of French provinces, each province would be separate polygon.  To calculate the center point of each province polygon you would pass in the vertices of the polygon as the xPoints and yPoints and then also the extents of the province polygon.  The four values in the pExtents vector are the upper left and lower right points of the bounding rect (nUpperLeftLat, nUpperLeftLon, nLowerRightLat, nLowerRightLon).  I use the extents for understanding what quadrant of xy space the polygon is in.  

As far as screen clipping goes I am using OpenGl to render all my vector graphics and it handles clipping objects from the viewport.  What graphics library are you using to display the vectors?  I use OpenGL's glProject() and glUnProject() functions to convert from screen coordinates to world coordinates and vice versa. 

Something to think about is that when calculating the label for a country like Russia (which is spread across most of the x space (-180 - 180), you probably only want to put the label on the large polygons that make up the country (region).  For that, what I do is first call CalculateProjectedArea() for each polygon in a country and then calculate labels for geographic areas that are greater than n size.  That way, for a country like Canada, you don't have a label for every little island, just the main land areas...does this make sense?

Hope this helps.  If I know what graphics library you are using I can give you more specific answers to your problem of rendering labels.  What issues are you experiencing?  Let me know if you have more questions.

Martin

P.S.  Are you in France?  My niece is in Paris right now and she says she loves it there.  


-----Original Message-----
From: Mathieu [mailto:mathieu_gdal at yahoo.fr] 
Sent: Friday, April 16, 2004 3:21 AM
To: gdal-dev at remotesensing.org
Subject: RE : [Gdal-dev] Center of polygon


Martin,

Thank you for the "center of polygon" algorithm.

Could you please describe the pExtents parameter in the GetCenter method? 
In the code, it looks like you expect a 4 elements array. What mean those 4 values?

When displaying a polygon's label, it is important to take care of the position of the polygon in the screen. That's why, I think, the OGRPolygonLabelPoint (MITAB driver) is not enough for displaying a label.

Does your algorithm take accound of this "screen clipping" problem? (maybe pExtent is related with that??)

Mat





-----Message d'origine-----
De : gdal-dev-admin at remotesensing.org [mailto:gdal-dev-admin at remotesensing.org] De la part de Chapman, Martin Envoyé : lundi 5 avril 2004 22:40 À : gdal-dev at remotesensing.org Objet : RE: [Gdal-dev] Center of polygon

Bruce,

No problem, it's not perfect but it is pretty good for a starting point. It will position 99 percent of the labels correctly.  If you improve it or make bug fixes send me the code please.  If you have questions let me know too. 

Martin

-----Original Message-----
From: Clay, Bruce [mailto:bclay at ball.com] 
Sent: Monday, April 05, 2004 2:22 PM
To: gdal-dev at remotesensing.org
Subject: RE: [Gdal-dev] Center of polygon


Martin:
  Many thanks a for the code.

Bruce
_______________________________________________
Gdal-dev mailing list
Gdal-dev at remotesensing.org http://remotesensing.org/mailman/listinfo/gdal-dev
_______________________________________________
Gdal-dev mailing list
Gdal-dev at remotesensing.org http://remotesensing.org/mailman/listinfo/gdal-dev

_______________________________________________
Gdal-dev mailing list
Gdal-dev at remotesensing.org http://remotesensing.org/mailman/listinfo/gdal-dev



More information about the Gdal-dev mailing list