楼主: sysuxiaogui
2126 10

[数据管理求助] 請問在Stata中如何根據座標計算任意多邊形的面積和中心 [推广有奖]

  • 2关注
  • 0粉丝

等待验证会员

大专生

8%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
320 点
帖子
29
精华
0
在线时间
34 小时
注册时间
2011-7-17
最后登录
2015-6-26

楼主
sysuxiaogui 发表于 2014-2-12 22:22:39 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
各位前輩,
      最近遇到一個比較棘手的問題,我現有一個省份的鄉鎮市區的boundary的座標(經緯度),希望通過stata來計算這些鄉鎮市區的面積和中心,請問各位前輩具體的語法應該怎麼寫。我之前在網路查過一個Pro.Nick寫的Program ,試著運行但是數據沒有什麽變化,即是我的data當中并沒有產生一個新的叫area的變項。
      以下是語法
      *! NJC 1.0.0 15 August 2003
program polyarea, rclass
version 12
syntax varlist(min=2 max=2 numeric) [in]

tokenize `varlist'
args x y

marksample touse, novarlist
qui count if `touse' & (missing(`x') | missing(`y'))
if r(N) {
di as err "missing values in data"
exit 198
}

tempvar order area

gen long `order' = _n
su `order' if `touse', meanonly

qui gen `area' = `touse' * ///
(`x'[_n + 1] - `x') * (`y'[_n + 1] + `y') / 2
qui replace `area' =       ///
(`x'[`r(min)'] - `x') * (`y'[`r(min)'] + `y') / 2 in `r(max)'
su `area', meanonly

di as res %9.0g abs(r(sum))
return scalar area = abs(r(sum))
end


謝謝各位前輩,希望斑竹不要再刪除我的帖子。謝謝。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Stata tata marksample meanonly Boundary 如何 中心

沙发
jjjj6666 发表于 2014-2-13 05:19:02
it looks like the program return the area in scalar, not a variable in data.  If you do

sca list area

does it show anything?

藤椅
sysuxiaogui 发表于 2014-2-13 13:54:50
jjjj6666 发表于 2014-2-13 05:19
it looks like the program return the area in scalar, not a variable in data.  If you do

sca list  ...
thanks a lot for your concern ,I have tried your suggestion"sca list area"but failed    Stata showed the result below
sca list area
scalar area not found
r(111);

板凳
jjjj6666 发表于 2014-2-14 01:07:52
sorry, it return the sca in return list, using "di r(area)" instead.

also, when calling this program, did you get any error?

报纸
sysuxiaogui 发表于 2014-2-14 03:20:23
jjjj6666 发表于 2014-2-14 01:07
sorry, it return the sca in return list, using "di r(area)" instead.

also, when calling this prog ...
hello,so grateful for your help.I have tried "di r(area)"but nothing showed in the scree.That is the trouble it seems that the program runs successfully without any erro ,but I can't get the value of area.

地板
jjjj6666 发表于 2014-2-14 04:27:17
can you post the data with the x y variables only if it's not big? It seems the program will output something, at least.

7
sysuxiaogui 发表于 2014-2-14 14:07:29
jjjj6666 发表于 2014-2-14 04:27
can you post the data with the x y variables only if it's not big? It seems the program will output  ...
yes I post my data named "data sample.xlsx" in the appendix at the end of my question .do you notice it .

8
h3327156 发表于 2014-2-14 19:57:13
测试的结果,请参考
polyarea_test.JPG

9
jjjj6666 发表于 2014-2-14 21:51:54
thanks.  So, it does show the result in r(area), and I think sysuxiaogui can get the result from r(area) easily.

10
sysuxiaogui 发表于 2014-2-18 14:35:13
jjjj6666 发表于 2014-2-14 21:51
thanks.  So, it does show the result in r(area), and I think sysuxiaogui can get the result from r(a ...
Dear J,I have tried di r(area) but get nothing .you use Stata version12.0 or others?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-18 16:21