# [R-sig-Geo] get the centroids of the polygones

Jianhua Huang jh.eco.cas at gmail.com
Tue Apr 12 19:30:48 CEST 2011

```Hi Danlin:

Jianhua

-----Original Message-----
From: Danlin Yu [mailto:yud at mail.montclair.edu]
Sent: 2011年4月12日 13:10
To: Jianhua Huang
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] get the centroids of the polygones

Jianhua:

Well, I happen to have ArcGIS as well, so I did the feature to point and
add xy coordinates routine and compared the obtained coordinates with
what R coordinates() function returns. They match. So I would say
coordinates() certainly returns the centroids of the polygons (it makes
more sense if it is the centroids returned, right? otherwise, the
algorithm for coordinates() would be rather complex and tedious).

Hope this helps.

Cheers,
Danlin

On 2011-4-12 12:51, Jianhua Huang wrote:
> Hi Danlin:
>
> Thanks much for your help. This is really a very useful function. Does the
> coordinates() function returns the coordinate value of the polygon's
> centroids, or other value within or on the polygon?
>
> I have check the function, but the introduction is not detailed enough for
> me to tell whether the returned value is exactly the one I need. Here is
the
> introduction: http://127.0.0.1:27343/library/sp/html/coordinates.html
>
> Thanks again for your help.
>
> Jianhua
>
> -----Original Message-----
> From: Danlin Yu [mailto:yud at mail.montclair.edu]
> Sent: 2011年4月12日 12:36
> To: Jianhua Huang
> Cc: r-sig-geo at r-project.org
> Subject: Re: [R-sig-Geo] get the centroids of the polygones
>
> Jianhua:
>
> Looks like get.Pcent was legacy now based on the error.
>
> But since you've already read the shapefile into a spatial polygon
> dataframe, why not just use coordinates() to get the centroids? Such as:
>
> ....
> centroids<-coordinates (cte)
>
> Hope this helps.
>
> Cheers,
> Dr. Danlin Yu
>
> On 2011-4-12 12:11, Jianhua Huang wrote:
>> Hi Everyone:
>>
>>
>>
>> I am trying to get the centroids of all the polygons in the shape file.
>>
>>
>>
>> I use the following code:
>>
>>
>>
>> library(spdep)
>>
>> library(maptools)
>>
>>
>> get.Pcent(cte)
>>
>>
>>
>> But there is an error when I run get.Pcent (Error: could not find
function
>> "get.Pcent")
>>
>>
>>
>> My R version is 2.12.2
>>
>>
>>
>> Anybody knows why the function doesn't work?
>>
>>
>>
>> Thanks
>>
>>
>>
>> Robert
>>
>>
>> 	[[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

--
___________________________________________
Danlin Yu, Ph.D.
Associate Professor of GIS and Urban Geography
Department of Earth & Environmental Studies
Montclair State University
Montclair, NJ, 07043
Tel: 973-655-4313
Fax: 973-655-4072
email: yud at mail.montclair.edu
webpage: csam.montclair.edu/~yu

```