ant 1.6.5.jar:mapinfo怎么读取地图节点的坐标?

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 08:57:39

从Mapinfo读取节点或数据坐标信息。可采用3种办法:

.mif/mid文件中读取。在mapinfo中选export file,把地图中的数据信息输出到mif/mid文件中。在程序中打开mif文件读取。可以得到如线段起始和终点坐标等等.

主要是C语言对文件操作。

从地图table表直接读取,读取表中的数据一般用FetcH。具体操作如下:

1. Use a Fetch statement to specify which row in the table you want to query.
This action sets which row is current.
2. Use a table-reference expression (e.g. tablename.columnname) to access a
specific column in the current row.
For example, the following program reads the contents of the Country column from
the first row of the World table:
Dim s_name As String
Open Table ”world” Interactive
Fetch First From world
s_name = world.Country

MapBasic例子程序:读表中FROMLEFT一项的数据

Include "MAPBASIC.DEF"

Dim s_name As Integer

Open Table "D:\aa\street\onhalts1"
Map From onhalts1

Dim i,counter As Integer
Fetch First From onhalts1
Do While Not EOT(onhalts1)
s_name = onhalts1.FROMLEFT
Print "The name: "+ s_name
i = i + 1
Fetch Next From onhalts1
Loop

Print "Number of undeleted records: " + i

读Object信息。
MapBasic程序:读出Object的节点坐标,长度,segment数。
Include "MAPBASIC.DEF"
Dim table_OBJ As String
table_OBJ = "JPN1RAIL.obj"

Dim geogr_length As Float,
x1,y1,x2,y2 As Float
Open Table "D:\aa\japan\JPN1RAIL"
Map From JPN1RAIL
Dim i,counter As Integer
i = 0
Fetch First From JPN1RAIL
Do While Not EOT(JPN1RAIL)

'counter = ObjectInfo(JPN1RAIL.obj, OBJ_INFO_NPNTS)
counter = ObjectInfo(JPN1RAIL.obj, OBJ_INFO_NPOLYGONS)

x1 = ObjectNodeX(JPN1RAIL.obj, 1, 1) ' read longitude
x2 = ObjectNodeX(JPN1RAIL.obj, 1, ObjectInfo(JPN1RAIL.obj, 20)) ' read longitude
y1 = ObjectNodeY(JPN1RAIL.obj, 1, 1) ' read latitude
y2 = ObjectNodeY(JPN1RAIL.obj, 1, ObjectInfo(JPN1RAIL.obj, 20)) ' read latitude

geogr_length = ObjectLen(JPN1RAIL.obj, "km")
Print "The length: "+ geogr_length+"x1:"+ x1+"y1:"+y1
'Print "The length: "+ geogr_length+"Counter:"+ counter

i = i + 1
Fetch Next From JPN1RAIL

Loop
Print "Number of undeleted records: " + i
============================================================================================
float geogr_length;
int nPolygons,Segment,node_Num;
CString strCommand;

mapinfo.Do("Dim i As Integer");

sprintf(str,"Fetch First From %s",Table_name);
mapinfo.Do(str);

num=493;
for(int i=0;i<num;i++)
{
sprintf(str,"ObjectInfo(%s,20)",Table_obj);
node_Num = atoi (mapinfo.Eval(str));//OBJ_INFO_NPNTS
sprintf(str,"ObjectInfo(%s,21)",Table_obj);
Segment = atoi (mapinfo.Eval(str));//OBJ_INFO_NPOLYGONS

sprintf(str,"ObjectNodeX(%s,1,1)",Table_obj);
x1[i] = (float)atof(mapinfo.Eval(str));
sprintf(str,"ObjectNodeY(%s,1,1)",Table_obj);
y1[i] = (float)atof(mapinfo.Eval(str));

sprintf(str,"ObjectNodeX(%s,1,ObjectInfo(%s, 20))",Table_obj,Table_obj);
x2[i] = (float)atof(mapinfo.Eval(str));

sprintf(str,"ObjectNodeY(%s,1,ObjectInfo(%s, 20))",Table_obj,Table_obj);
y2[i] = (float)atof(mapinfo.Eval(str));

geogr_length = atof( mapinfo.Eval("ObjectLen(JPN1RAIL.obj, \"km\") "));
sprintf(str,"Fetch Next From %s",Table_name);
mapinfo.Do(str);
}
mapinfo.Do("Print \"Number of undeleted records: \" + i ");

Fetch First From world
Note world.obj

counter = ObjectInfo(CHINAHWY.obj, OBJ_INFO_NPNTS)表示一个多边形有多少个点(segment+section)。

ObjectNodeX(xxx.obj, 1, counter)

一个polyline Object有line segments 和line sections组成。属性有节点数,长度,节点坐标,segment数和section数。
用函数counter = ObjectInfo(JPN1RAIL.obj, OBJ_INFO_NPOLYGONS)
ObjectNodeX(JPN1RAIL.obj, 1, 1) ' read x
ObjectNodeY(JPN1RAIL.obj, 1, 1) ' read y
ObjectLen(JPN1RAIL.obj, "km")
等求出。