Database storage solution for MapInfo Annotation

Source: Internet
Author: User

Database storage solution for MapInfo Annotation

Http://www.gissky.net/Article/mapinfo/200611/354.htm

【Abstract]Since mapinfo5.5 supports Oracle Spatial, it greatly facilitates the sharing, management, and maintenance of geospatial data, and also promotes its own applications in various GIS industries. However, MapInfo has not been able to store notebooks in the database from the first version 5.5 to the current version 7.0. This defect has caused great inconvenience to MapInfo users in system application and development. This article is based on this reason and uses MapBasic, the second development language of Mapinfo, to better solve this problem.

【Key words]MapBasic, Oracle Spatial, spatial database, text Note

I. Question proposal

MapInfo is an easy-to-use and popular GIS desktop software. It has basic GIS functions such as storage, management, display, query, analysis, and drawing of geospatial data, it has a large user group in China. MapInfo uses the traditional file method to manage GIS spatial data, which cannot meet the needs of Multi-User Sharing and concurrent operations of GIS data, and is difficult to implement enterprise-level GIS applications. With the development of Oracle Spatial, MapInfo supports using oralce spatial to manage spatial data from 5.5, which can better solve enterprise application problems. Since ODBC is no longer used between Mapinfo and Oracle, spatial data processing is built on powerful servers, at the same time, it implements a very efficient spatial index technology (R-tree), so it can easily process massive data; oracle can be used to establish a real spatial information system with the client/server and Browser/Server structures, which not only solves the storage and management of massive data, but also the access speed of massive data, it also solves many problems such as multi-user editing, data integrity, and data security mechanisms.

However, because the spatial data models of Oracle Spatial and MapInfo are inconsistent, the most prominent problem is that the Mapinfo Enterprise GIS application solution based on Oracle Spatial is noted. Since Oracle Spatial itself does not support the annotation data type, MapInfo only supports database storage of point, line, and area space data from Version 5.5, note databases are not stored in the latest version 7.0. As we all know, in addition to points, lines, and surfaces, geographic space data should also contain notes. Note has the ability to identify various objects, indicate the attributes of objects, and translate the objects. It plays a very important role in geospatial data. A map without a note cannot express the spatial concept of a thing, nor the name or quality or quantity of a thing. The defect that MapInfo cannot store a note in the database not only makes the distributed application, update, Consistency Maintenance, and data security of the NOTE Information inconvenient, it also affects the overall effect of other point, line, and surface geospatial data applications.

Ii. Solutions

Since MapInfo does not support the storage of the annotated database, is there any other way to solve this problem? The answer is obviously yes. This article provides three solutions and their respective advantages and disadvantages.

The first solution uses the restore attribute for restoration. The specific method is to first read the attributes of the annotation object in the Mapinfo graphic file, including the coordinates of the annotation, the text content of the annotation, And the font, size, color, and style of the annotation, store it in the Oracle relational database on the server. When the client application is used, the notes are restored and displayed based on these attributes. The advantage of this method is that the attributes of the annotation can be directly stored in the relational database without the support of the spatial database. The disadvantage is that the spatial analysis capability of the spatial database cannot be used to perform spatial query and topology analysis on the annotation.

The second method is to display the note by marking the vertex attributes. The method is to create a corresponding vertex element for each annotation Based on the positioning point of the annotation center, and store the text content of the annotation as an attribute field value of the vertex to the corresponding vertex, finally, upload the point space data (upload) to the Oracle Spatial space database. When using a client application, you can use the annotation option in the layer control tool to mark the annotation attribute field of the vertex to display the annotation. The advantage of this method is that the client does not need to do any programming processing, in addition, the powerful management and analysis functions of spatial data can be used for spatial query and analysis like other points, lines, and surface elements. Because these annotations follow a corresponding vertex element, spatial query and topology analysis of these vertex elements are similar to spatial query and topology analysis of their corresponding annotations. The disadvantage of this method is that the style of a note is restricted by its own function, and the style of a note on the same layer must be consistent.

The third method is a combination of the first two methods. First, the attributes of the annotation (including the coordinate of the annotation, the text content of the annotation, And the font, size, color, and style of the annotation) it is also stored in the attribute field of the vertex created with the center point of the note as the coordinate, and then uploaded to the Oracle Spatial space database (upload. When a client application is used, the display of the annotation is restored and displayed by the information stored in the vertex attribute, rather than by the annotation; on the other hand, we can use these generated point-to-point annotations for space analysis. This method draws on the advantages of the previous two methods. It not only achieves diversified note display, but also makes full use of the spatial database function to perform spatial query and Analysis on notes. This method integrates the advantages of the previous two methods. Therefore, this method is implemented by MapBasic, the second development language of MapInfo.

Iii. source code for MapBasic Programming

Before programming, we first introduce two very important MapBasic functions. One is used to read the annotation attribute, and the other is used to restore the annotation during client application. In MapBasic, objectgeography (object, attribute) can be used to read the attribute information of the annotation object, such as objectinfo (objtxt. OBJ, obj_info_textstring) can read the string information in the objtxt (Object for note) object. The most complete statement for creating a note in MapBasic is as follows:

Create text

[Into {window window_id | variable var_name}]

Text_string

(X1, Y1) (X2, Y2)

[Font...]

[Label line {simple | arrow} (label_x, label_y)]

[Spacing {1.0 | 1.5 | 2.0}]

[Justify {left | center | right}]

[Angle text_angle]

In this sentence, the parameters marked with [] are optional. (x1, Y1) and (X2, Y2) Specify the positions in the lower left and upper right corner of the note, respectively, the actual size of the Notes displayed in the future is determined only by (x, y) and is irrelevant to the font size defined in makefont. For example, the example of creating a note in the current window is as follows:

Create text into window frontwindow () "China Great Wall)

Font makefont ("", 1, 12, black, white)

In the above sentence, 12 refers to the font size to be created, and the actual size of the characters to be displayed in the future is only controlled by (x, y, in fact, 12 can be set to any value not equal to 0.

After introducing the two important MapBasic functions, the following describes the complete source code of the application instance. There are two programs in total, a Conversion Program that reads the annotation attribute and saves it to a temporary file (this temporary file can be directly uploaded to Oracle Spatial for storage management using the easy upload tool of MapInfo, one is the client restoration program. The source program has been debugged in Windows2000, mapinfo6.5, and mapbasic6.5.

<1> source program for reading the annotation attribute: the main function of the Program on the server side is to read the parameters used in the restoration of the Annotation on the client side, and put it in the attribute field of the corresponding vertex. The point space data with annotation attributes can be uploaded directly to the Oracle spatial database through the upload tool of MapInfo for management and distributed applications.

'The program is used to store the text in the Mapinfo layer as an attribute to another new layer,

'Then, the new layer can be transferred to the Oracle database to solve the problem that the MapInfo database does not support text objects.

'Developer: Yu yinggang time: 2002.9.5

Declare sub txt2newfile (byval oldfilename as string, byval newfilename as string)

Declare sub main

Sub main ()

Dim stroldfile as string

Dim strnewfile as string

Stroldfile = "C:" Temp "data" oldzj"

Strnewfile = "C:" Temp "data" tempzj"

Call txt2newfile (stroldfile, strnewfile)

Note "the note is converted successfully! "

End program

End sub

Sub txt2newfile (byval oldfilename as string, byval newfilename as string)

'Oldfilename, the annotation file name to be stored in Oracle Spatial

'Newfilename, a temporary new file name used to store Properties

Include "MapBasic. Def"

Dim obj_type as integer object type

Dim strtxt as string' text note string

Dim obj_font as font

Dim fnt_name as string 'font name

Dim fnt_style as integer Font Style

Dim fnt_pointsize as integer 'font size

Dim fnt_forecolor as integer

Dim fnt_backcolor as integer font background color

Dim f_x, f_y as float 'text Center Coordinate (x, y)

Dim f_minx, f_miny, f_maxx, f_maxy as float 'External rectangular coordinates of the text

Dim f_angle as float 'Angle

'Create a new table to store text note attributes

Create Table newtxt (txt char (50), fontname char (20), fontstyle integer, fontpointsize integer,

Fontforecolor integer, fontbackcolor integer, Minx decimal (9,5), miny decimal (9,5 ),

Maxx decimal (9, 5), Maxy decimal (9, 5), fangle decimal (6, 2 ))

File newfilename type DBF

Commit table newtxt

Close table newtxt

'Open the note file to be stored in Oracle Spatial

Open Table oldfilename as oldtxt

Set paper units "cm"

'Open a temporary file used to store the annotation attribute

Open Table newfilename as newtxt

Create map for newtxt

Fetch first from oldtxt

Do while not EOT (oldtxt)

Obj_type = objectinfo (oldtxt. OBJ, obj_info_type)

Do case obj_type

Case obj_type_text only processes text objects

Strtxt = objectinfo (oldtxt. OBJ, obj_info_textstring)

Obj_font = objectinfo (oldtxt. OBJ, obj_info_textfont)

Fnt_name = styleattr (obj_font, font_name)

Fnt_style = styleattr (obj_font, font_style)

Fnt_pointsize = styleattr (obj_font, font_pointsize)

Fnt_forecolor = styleattr (obj_font, font_forecolor)

Fnt_backcolor = styleattr (obj_font, font_backcolor)

F_x = objectgeography (oldtxt. OBJ, obj_geo_textlinex)

F_y = objectgeography (oldtxt. OBJ, obj_geo_textliney)

F_minx = objectgeography (oldtxt. OBJ, obj_geo_minx)

F_miny = objectgeography (oldtxt. OBJ, obj_geo_miny)

F_maxx = objectgeography (oldtxt. OBJ, obj_geo_maxx)

F_maxy = objectgeography (oldtxt. OBJ, obj_geo_maxy)

F_angle = objectgeography (oldtxt. OBJ, obj_geo_textangle)

'Insert the vertex element and store the annotation information in the attribute field.

Insert into newtxt (OBJ, txt, fontname, fontstyle, fontpointsize,

Fontforecolor, fontbackcolor, Minx, miny, Maxx, Maxy, fangle)

Values (createpoint (f_x, f_y), strtxt, fnt_name, fnt_style, fnt_pointsize,

Fnt_forecolor, fnt_backcolor, f_minx, f_miny, f_maxx, f_maxy, f_angle)

End case

Fetch next from oldtxt

Loop

Commit table newtxt

End sub

<1> restoration source program on the client: This program is mainly used to restore the vertex files containing the annotation information to the display form of the annotation. To obtain this file, you can use MapInfo to directly open the vertex element layer that was previously uploaded to Oracle Spatial. MapInfo will automatically download it to the local device.

'The program restores the property information to text display based on the annotation.

'Developer: Yu yinggang time: 2002.9.5

Declare sub file2newtxt (byval oldfilename as string, byval newfilename as string)

Declare sub main

Sub main ()

Dim stroldfile as string

Dim strnewfile as string

Stroldfile = "C:" Temp "data" tempzj"

Strnewfile = "C:" Temp "data" newzj"

Call file2newtxt (stroldfile, strnewfile)

Note "the note is restored successfully! "

End program

End sub

Sub file2newtxt (byval oldfilename as string, byval newfilename as string)

'Oldfilename, stores the name of the annotation file with the annotation attribute

'Newfilename, used to store the temporary new file name of the text note object

Include "MapBasic. Def"

Dim obj_type as integer object type

Dim strtxt as string' text note string

Dim obj_font as font

Dim fnt_name as string 'font name

Dim fnt_style as integer Font Style

Dim fnt_pointsize as integer 'font size

Dim fnt_forecolor as integer

Dim fnt_backcolor as integer font background color

Dim f_minx, f_miny, f_maxx, f_maxy as float 'External rectangular coordinates of the text

Dim f_angle as float 'Angle

Number of records selected by dim selnum as integer

'Create a new table to store text note objects

Create Table newtxt (txt char (30 ))

File newfilename type DBF

Commit table newtxt

Close table newtxt

'Open the file with annotation attributes

Open Table oldfilename as oldtxt

'Open a temporary file used to store the annotation object

Open Table newfilename as newtxt

Create map for newtxt

Map from newtxt

Set map layer 1 editable on

Select * From oldtxt

Selnum = selectioninfo (sel_info_nrows)

If selnum <1 then

Exit sub

End if

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.