主要功能:面积计算,条件查询。
虽然第一次写GIS的二次开发程序,不过感觉上手真的很快。也就是用了1个半小时,就把大概的知识点过了一遍,接着就开始对着Mapbasic开始敲键盘。
不过毕竟没有基础,写出来的程序很丑陋(不会basic语言,所以很多东西写得特别长)
在此把代码贴出,希望路过的朋友,可以看看。
nclude "mapbasic.def"
Include "menu.def"
declare Sub 道路
declare Sub 高薪产业区
declare Sub 工业发展用地
declare Sub 教育科研用地
declare Sub 居住用地
declare Sub 绿地
declare Sub 行政办公用地
declare Sub 文化娱乐用地
declare Sub 面积
Declare Sub duihua
Declare Sub Main
Declare Sub tiaojian
Dim mianji as Float
Dim i as Integer
Dim mianji1 as float
Dim zongmianji1 as float
Dim jilushu as Integer
Sub Main
Create Menu "条件查询" as "请输入条件" Calling tiaojian
Alter Menu Bar Add "条件查询"
Create Menu "统计查询" as "面积" Calling duihua
Alter Menu Bar Add "统计查询"
Create Menu "分类查询" as "道路" Calling 道路,
"高薪产业区" Calling 高薪产业区,
"工业发展用地" Calling 工业发展用地,
"教育科研用地" Calling 教育科研用地,
"居住用地" Calling 居住用地,
"绿地" Calling 绿地,
"行政办公用地" Calling 行政办公用地,
"文化娱乐用地" Calling 文化娱乐用地
Alter Menu Bar Add "分类查询"
End Sub
Sub tiaojian
Dim yongdileixing as String
Dim xiao,da as Integer
Dialog
Title "条件查询"
Control StaticText
Into yongdileixing
Control StaticText
Title "查询的用地类型"
Control EditText
Into yongdileixing
Control StaticText
Title "面积的最小值"
Control EditText
Into xiao
Control StaticText
Title "面积的最大值"
Control EditText
Into da
Control OkButton
Title "确定"
Control CancelButton
Title "取消"
Open Table "c:\shix\" + yongdileixing
If yongdileixing = "教育科研用地" Then
Fetch First From 教育科研用地
Do While Not EOT(教育科研用地)
mianji = Area(教育科研用地.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "教育科研用地id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 教育科研用地
Loop
End If
If yongdileixing = "居住用地" Then
Fetch First From 居住用地
Do While Not EOT(居住用地)
mianji = Area(居住用地.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "居住用地id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 居住用地
Loop
End If
If yongdileixing = "道路" Then
Fetch First From 道路
Do While Not EOT(道路)
mianji = Area(道路.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "道路id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 道路
Loop
End If
If yongdileixing = "高薪产业区" Then
Fetch First From 高薪产业区
Do While Not EOT(高薪产业区)
mianji = Area(高薪产业区.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "高薪产业区id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 高薪产业区
Loop
End If
If yongdileixing = "文化娱乐用地" Then
Fetch First From 文化娱乐用地
Do While Not EOT(文化娱乐用地)
mianji = Area(文化娱乐用地.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "文化娱乐用地id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 文化娱乐用地
Loop
End If
If yongdileixing = "行政办公用地" Then
Fetch First From 行政办公用地
Do While Not EOT(行政办公用地)
mianji = Area(行政办公用地.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "行政办公用地id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 行政办公用地
Loop
End If
If yongdileixing = "工业发展用地" Then
Fetch First From 工业发展用地
Do While Not EOT(工业发展用地)
mianji = Area(工业发展用地.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "工业发展用地id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 工业发展用地
Loop
End If
If yongdileixing = "绿地" Then
Fetch First From 绿地
Do While Not EOT(绿地)
mianji = Area(绿地.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
If mianji>=xiao and mianji<=da Then
i = i + 1
Print "绿地id:" + i + "面积:" + Str$(mianji)
End If
Else
Print "没有您要搜索的对象名称"
End If
Fetch Next From 绿地
Loop
End If
End Sub
Sub duihua
Dim search As String
Dialog
Title "面积查询"
Control StaticText
Title "输入您要查询的用地类型"
Control EditText
Into search
Control OKButton
Title "确定"
Control CancelButton
Title "取消"
Open Table "C:\shix\" + search
If search = "教育科研用地" Then
Dim i,counter as Integer
Fetch First From 教育科研用地
Do While Not EOT(教育科研用地)
mianji1 = Area(教育科研用地.obj,"sq km")
i = i + 1
If CommandInfo (CMD_INFO_DLG_OK) Then
print "教育科研用地id" + i +":" + Str$(mianji1)
Else
print "没有您要搜索的对象名称"
End If
zongmianji1 = zongmianji1 + mianji1
Fetch Next From 教育科研用地
Loop
print "教育科研用地总面积为:" + Str$(zongmianji1)
End If
If search = "高薪产业区" Then
Dim a as Integer
Fetch First From 高薪产业区
Do While Not EOT(高薪产业区)
mianji1 = Area(高薪产业区.obj,"sq km")
a = a + 1
If CommandInfo (CMD_INFO_DLG_OK) Then
print "高薪产业区id" + a + ":"+Str$(mianji1)
Else
print "没有您要搜索的对象名称"
End If
zongmianji1 = zongmianji1 + mianji1
Fetch Next From 高薪产业区
Loop
print "高薪产业区总面积为:" + Str$(zongmianji1)
End If
If search = "居住用地" Then
Dim b as Integer
Fetch First From 居住用地
Do While Not EOT(居住用地)
mianji1 = Area(居住用地.obj,"sq km")
b = b + 1
If CommandInfo (CMD_INFO_DLG_OK) Then
print "居住用地id" +b+ ":" + Str$(mianji1)
Else
print "没有您要搜索的对象名称"
End If
zongmianji1 = zongmianji1 + mianji1
Fetch Next From 居住用地
Loop
print "居住用地总面积为:" + Str$(zongmianji1)
End If
If search = "行政办公用地" Then
Dim c as Integer
Fetch First From 行政办公用地
Do While Not EOT(行政办公用地)
mianji1 = Area(行政办公用地.obj,"sq km")
c = c + 1
If CommandInfo (CMD_INFO_DLG_OK) Then
print "行政办公用地id"+c +":"+ Str$(mianji1)
Else
print "没有您要搜索的对象名称"
End If
zongmianji1 = zongmianji1 + mianji1
Fetch Next From 行政办公用地
Loop
print "行政办公用地总面积为:" + Str$(zongmianji1)
End If
If search = "文化娱乐用地" Then
Dim d as Integer
Fetch First From 文化娱乐用地
Do While Not EOT(文化娱乐用地)
mianji1 = Area(文化娱乐用地.obj,"sq km")
d = d + 1
If CommandInfo (CMD_INFO_DLG_OK) Then
print "文化娱乐用地id" +d+":"+ Str$(mianji1)
Else
print "没有您要搜索的对象名称"
End If
zongmianji1 = zongmianji1 + mianji1
Fetch Next From 文化娱乐用地
Loop
print "文化娱乐用地总面积为:" + Str$(zongmianji1)
End If
If search = "绿地" Then
Dim r as Integer
Fetch First From 绿地
Do While Not EOT(绿地)
mianji1 = Area(绿地.obj,"sq km")
r = r + 1
If CommandInfo (CMD_INFO_DLG_OK) Then
print "绿地id" +r+":"+ Str$(mianji1)
Else
print "没有您要搜索的对象名称"
End If
zongmianji1 = zongmianji1 + mianji1
Fetch Next From 绿地
Loop
print "绿地总面积为:" + Str$(zongmianji1)
End If
If search = "道路" Then
Dim v as Integer
Fetch First From 道路
Do While Not EOT(道路)
v = v + 1
mianji1 = Area(道路.obj,"sq km")
If CommandInfo (CMD_INFO_DLG_OK) Then
print "道路id" +v+":" +Str$(mianji1)
Else
print "没有您要搜索的对象名称"
End If
zongmianji1 = zongmianji1 + mianji1
Fetch Next From 道路
Loop
print "道路总面积为:" + Str$(zongmianji1)
End If
End Sub
Sub 道路
Open Table "C:\shix\道路 "
Add Map
Layer 道路
End Sub
Sub 高薪产业区
Open Table "C:\shix\高薪产业区 "
Add Map
Layer 高薪产业区
Map From 高薪产业区
End Sub
Sub 工业发展用地
Open Table "C:\shix\工业发展用地 "
Add Map
Layer 工业发展用地
Map From 工业发展用地
End Sub
Sub 教育科研用地
Open Table "C:\shix\教育科研用地 "
Add Map
Layer 教育科研用地
Map From 教育科研用地
End Sub
Sub 居住用地
Open Table "C:\shix\居住用地 "
Add Map
Layer 居住用地
Map From 居住用地
End Sub
Sub 绿地
Open Table "C:\shix\绿地 "
Add Map
Layer 绿地
Map From 绿地
End Sub
Sub 行政办公用地
Open Table "C:\shix\行政办公用地 "
Add Map
Layer 行政办公用地
Map From 行政办公用地
End Sub
Sub 文化娱乐用地
Open Table "C:\shix\文化娱乐用地 "
Add Map
Layer 文化娱乐用地
Map From 文化娱乐用地
End Sub