MapX系列-- 开源Mitab

 

开源Mitab

 

 

MapX生成图元的效率真的不敢恭维,如果要做动态播放,轨迹跟踪等工作,会让你有股把电脑砸了的冲动!幸好GIS是一门科学,更是一门技术,有好多的热心人士为GIS的发展进步默默地奉献青春,开源Mitab库就是这样一群人做的好东东.废话不多说,开源包里想要的东东都有,这个是vb.net下的API声明,具体怎么用,大家可以自己去研究。。。。。

 


'/*******************************************************************************
'ModuleName:Mitab
'Author:  Contect:
[email protected]
'DateTime: Mar 29, 2010
'Desc:
'        1.API declare For the mass-data low efficiency problem of MapX,in order
'          to appreciate the effort of OpenGIS,please keep the Annotations unchanged
'          below.Look more infomation at
http://mitab.maptools.org/
'History:
'        1.Introduced by Me on  Mar 29, 2010
'Note:
'        1.Need the file of "Mitab.dll"
'CopyRight: XXXXXX TEC.LMT.CO
'**********************************************************************************
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServices

 

Public Module Mitab
    ' **********************************************************************
    ' * $Id: mitab.vb,v 1.11 2005/04/01 16:22:54 dmorissette Exp $
    ' *
    ' * Name:     mitab.vb
    ' * Project:  MapInfo TAB Read/Write library
    ' * Language: Visual Basic
    ' * Purpose:  Visual Basic include file for MITAB API prototypes using STDCALL
    ' *           calling convention. Used with MITAB dll compiled with
    ' *           the /Gz qualifier.
    ' * Author:   Bo Thomsen,
[email protected]
    ' *
    ' **********************************************************************
    ' * Copyright (c) 2002, Bo Thomsen
    ' *
    ' * Permission is hereby granted, free of charge, to any person obtaining a
    ' * copy of this software and associated documentation files (the "Software"),
    ' * to deal in the Software without restriction, including without limitation
    ' * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    ' * and/or sell copies of the Software, and to permit persons to whom the
    ' * Software is furnished to do so, subject to the following conditions:
    ' *
    ' * The above copyright notice and this permission notice shall be included
    ' * in all copies or substantial portions of the Software.
    ' *
    ' * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    ' * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    ' * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
    ' * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    ' * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    ' * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    ' * DEALINGS IN THE SOFTWARE.
    ' **********************************************************************
    ' *
    ' * $Log: mitab.vb,v $
    ' * Revision 1.11  2005/04/01 16:22:54  dmorissette
    ' * Updated to Libversion = 1004000 for 1.4.0 release
    ' *
    ' * Revision 1.10  2004/07/07 22:10:32  dmorissette
    ' * Update for 1.3.0 release by BVT
    ' *
    ' * Revision 1.10  2004/07/06 18:51:00  bvt
    ' * Added declaration for:
    ' * mitab_c_load_coordsys_table
    ' * mitab_c_get_extended_mif_coordsys_vb
    ' * mitab_c_get_feature_count
    ' * mitab_c_get_field_as_double
    ' *
    ' * Revision 1.9  2003/08/07 18:51:00  dmorissette
    ' * Added mitab_c_getlibversion declaration (BVT - Bug 21)
    ' *
    ' * Revision 1.8  2003/07/29 14:39:26  dmorissette
    ' * Update for v1.2.4 from BVT (mitab_c_add_field declaration changed)
    ' *
    ' * Revision 1.8  2003/07/29 13:53:11  daniel
    ' * Update for v1.2.4 from BVT (mitab_c_add_field declaration changed)
    ' *
    ' * Revision 1.7  2002/09/07 17:57:01  daniel
    ' * Update for version 1.2.2 (from BVT)
    ' *
    ' * Revision 1.6  2002/09/07 13:59:38  daniel
    ' * (Update From BVT) Numerous fixes in the declarations
    ' *
    ' * Revision 1.5  2002/08/01 13:59:38  daniel
    ' * (Update From BVT) Fixed mitab_c_get_vertex_x/y() declarations
    ' *
    ' * Revision 1.4  2002/07/07 22:04:22  bvt
    ' * Added declaration for mitab_c_is_interior_ring
    ' *
    ' * Revision 1.3  2002/05/09 22:04:22  daniel
    ' * Added missing TABFC_MultiPoint=10
    ' *
    ' * Revision 1.2  2002/05/08 20:23:53  daniel
    ' * Update from Bo, and re-re-renamed mitab_vb.dll to mitab.dll (stdcall is default now)
    ' *
    ' * Revision 1.21  2002/05/07 13:43:30  bvt
    ' * changed the dll name to mitab_vb.dll. Changed the vb file name
    ' * to mitab_vb.vb to reflect the new name of the dll.
    ' *
    ' * Revision 1.2  2002/05/05 13:43:30  bvt
    ' * Added mitab_c_get_field_width and mitab_c_get_field_precision to api.
    ' *
    ' * Revision 1.1  2002/02/22 13:43:30  daniel
    ' * Initial Revision from Bo Thomsen
    ' *
    ' * Revision 1.00  2002/02/20 12:35:00  bvt
    ' * New - used in conjunction with mitab_capi.cpp,v 1.15 compiled with
    ' * /Gz (stdcall calling convention)
    ' *
    ' *

    <StructLayout(LayoutKind.Sequential)> Public Structure mitab_projinfo
        <VBFixedArray(255)> Dim ph() As Byte

        Public Sub Initialize()
            ReDim ph(255)
        End Sub
    End Structure

    ' feature type values

    Public Const TABFC_NoGeom As Short = 0
    Public Const TABFC_Point As Short = 1
    Public Const TABFC_FontPoint As Short = 2
    Public Const TABFC_CustomPoint As Short = 3
    Public Const TABFC_Text As Short = 4
    Public Const TABFC_Polyline As Short = 5
    Public Const TABFC_Arc As Short = 6
    Public Const TABFC_Region As Short = 7
    Public Const TABFC_Rectangle As Short = 8
    Public Const TABFC_Ellipse As Short = 9
    Public Const TABFC_MultiPoint As Short = 10

    ' field types

    Public Const TABFT_Char As Short = 1
    Public Const TABFT_Integer As Short = 2
    Public Const TABFT_SmallInt As Short = 3
    Public Const TABFT_Decimal As Short = 4
    Public Const TABFT_Float As Short = 5
    Public Const TABFT_Date As Short = 6
    Public Const TABFT_Logical As Short = 7

    ' text justification

    Public Const TABTJ_Left As Short = 0
    Public Const TABTJ_Center As Short = 1
    Public Const TABTJ_Right As Short = 2

    ' text spacing

    Public Const TABTS_Single As Short = 0
    Public Const TABTS_1_5 As Short = 1
    Public Const TABTS_Double As Short = 2

    ' test linetype

    Public Const TABTL_NoLine As Short = 0
    Public Const TABTL_Simple As Short = 1
    Public Const TABTL_Arrow As Short = 2

    ' version

    Public Const Libversion As Integer = 1004000


    Public Declare Function mitab_c_add_field Lib "mitab.dll" Alias "_mitab_c_add_field@28" (ByVal handle As Integer, ByVal field_name As String, ByVal field_type As Integer, ByVal width As Integer, ByVal precision As Integer, ByVal indexed As Integer, ByVal unique As Integer) As Integer
    Public Declare Sub mitab_c_close Lib "mitab.dll" Alias "
_mitab_c_close@4" (ByVal handle As Integer)
    Public Declare Function mitab_c_create Lib "mitab.dll" Alias "
_mitab_c_create@44" (ByVal filename As String, ByVal mif_or_tab As String, ByVal mif_projectiondef As String, ByVal north As Double, ByVal south As Double, ByVal east As Double, ByVal west As Double) As Integer
    Public Declare Function mitab_c_create_feature Lib "mitab.dll" Alias "
_mitab_c_create_feature@8" (ByVal handle As Integer, ByVal feature_type As Integer) As Integer
    Public Declare Sub mitab_c_destroy_feature Lib "mitab.dll" Alias "
_mitab_c_destroy_feature@4" (ByVal feature As Integer)
    Public Declare Function mitab_c_get_brush_bgcolor Lib "mitab.dll" Alias "
_mitab_c_get_brush_bgcolor@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_brush_fgcolor Lib "mitab.dll" Alias "
_mitab_c_get_brush_fgcolor@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_brush_pattern Lib "mitab.dll" Alias "
_mitab_c_get_brush_pattern@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_brush_transparent Lib "mitab.dll" Alias "
_mitab_c_get_brush_transparent@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_field_as_string_vb Lib "mitab.dll" Alias "
_mitab_c_get_field_as_string_vb@16" (ByVal feature As Integer, ByVal field As Integer, ByVal value As String, ByVal l As Integer) As Integer
    Public Declare Function mitab_c_get_field_count Lib "mitab.dll" Alias "
_mitab_c_get_field_count@4" (ByVal handle As Integer) As Integer
    Public Declare Function mitab_c_get_field_name_vb Lib "mitab.dll" Alias "
_mitab_c_get_field_name_vb@16" (ByVal handle As Integer, ByVal field As Integer, ByVal name As String, ByVal l As Integer) As Integer
    Public Declare Function mitab_c_get_field_type Lib "mitab.dll" Alias "
_mitab_c_get_field_type@8" (ByVal handle As Integer, ByVal field As Integer) As Integer
    Public Declare Function mitab_c_get_font_vb Lib "mitab.dll" Alias "
_mitab_c_get_font_vb@12" (ByVal feature As Integer, ByVal font As String, ByVal l As Integer) As Integer
    Public Declare Function mitab_c_getlibversion Lib "mitab.dll" Alias "
_mitab_c_getlibversion@0" () As Integer
    Public Declare Function mitab_c_get_mif_coordsys_vb Lib "mitab.dll" Alias "
_mitab_c_get_mif_coordsys_vb@12" (ByVal dataset As Integer, ByVal coordsys As String, ByVal l As Integer) As Integer
    Public Declare Function mitab_c_get_extended_mif_coordsys_vb Lib "mitab.dll" Alias "
_mitab_c_get_extended_mif_coordsys_vb@12" (ByVal dataset As Integer, ByVal coordsys As String, ByVal l As Integer) As Integer
    Public Declare Function mitab_c_get_parts Lib "mitab.dll" Alias "
_mitab_c_get_parts@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_pen_color Lib "mitab.dll" Alias "
_mitab_c_get_pen_color@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_pen_pattern Lib "mitab.dll" Alias "
_mitab_c_get_pen_pattern@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_pen_width Lib "mitab.dll" Alias "
_mitab_c_get_pen_width@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_projinfo Lib "mitab.dll" Alias "
_mitab_c_get_projinfo@4" (ByVal dataset As Integer) As mitab_projinfo
    Public Declare Function mitab_c_get_symbol_color Lib "mitab.dll" Alias "
_mitab_c_get_symbol_color@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_symbol_no Lib "mitab.dll" Alias "
_mitab_c_get_symbol_no@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_symbol_size Lib "mitab.dll" Alias "
_mitab_c_get_symbol_size@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_text_vb Lib "mitab.dll" Alias "
_mitab_c_get_text_vb@12" (ByVal feature As Integer, ByVal text As String, ByVal l As Integer) As Integer
    Public Declare Function mitab_c_get_text_angle Lib "mitab.dll" Alias "
_mitab_c_get_text_angle@4" (ByVal feature As Integer) As Double
    Public Declare Function mitab_c_get_text_bgcolor Lib "mitab.dll" Alias "
_mitab_c_get_text_bgcolor@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_text_fgcolor Lib "mitab.dll" Alias "
_mitab_c_get_text_fgcolor@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_text_height Lib "mitab.dll" Alias "
_mitab_c_get_text_height@4" (ByVal feature As Integer) As Double
    Public Declare Function mitab_c_get_text_justification Lib "mitab.dll" Alias "
_mitab_c_get_text_justification@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_text_linetype Lib "mitab.dll" Alias "
_mitab_c_get_text_linetype@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_text_spacing Lib "mitab.dll" Alias "
_mitab_c_get_text_spacing@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_text_width Lib "mitab.dll" Alias "
_mitab_c_get_text_width@4" (ByVal feature As Integer) As Double
    Public Declare Function mitab_c_get_type Lib "mitab.dll" Alias "
_mitab_c_get_type@4" (ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_vertex_count Lib "mitab.dll" Alias "
_mitab_c_get_vertex_count@8" (ByVal feature As Integer, ByVal part As Integer) As Integer
    Public Declare Function mitab_c_get_vertex_x Lib "mitab.dll" Alias "
_mitab_c_get_vertex_x@12" (ByVal feature As Integer, ByVal part As Integer, ByVal vertex As Integer) As Double
    Public Declare Function mitab_c_get_vertex_y Lib "mitab.dll" Alias "
_mitab_c_get_vertex_y@12" (ByVal feature As Integer, ByVal part As Integer, ByVal vertex As Integer) As Double
    Public Declare Function mitab_c_getlasterrormsg_vb Lib "mitab.dll" Alias "
_mitab_c_getlasterrormsg_vb@8" (ByVal errormsg As String, ByVal l As Integer) As Integer
    Public Declare Function mitab_c_getlasterrorno Lib "mitab.dll" Alias "
_mitab_c_getlasterrorno@0" () As Integer
    Public Declare Function mitab_c_next_feature_id Lib "mitab.dll" Alias "
_mitab_c_next_feature_id@8" (ByVal handle As Integer, ByVal last_feature_id As Integer) As Integer
    Public Declare Function mitab_c_open Lib "mitab.dll" Alias "
_mitab_c_open@4" (ByVal filename As String) As Integer
    Public Declare Function mitab_c_read_feature Lib "mitab.dll" Alias "
_mitab_c_read_feature@8" (ByVal handle As Integer, ByVal feature_id As Integer) As Integer
    Public Declare Sub mitab_c_set_arc Lib "mitab.dll" Alias "
_mitab_c_set_arc@52" (ByVal feature As Integer, ByVal center_x As Double, ByVal center_y As Double, ByVal x_radius As Double, ByVal y_radius As Double, ByVal start_angle As Double, ByVal end_angle As Double)
    Public Declare Sub mitab_c_set_brush Lib "mitab.dll" Alias "
_mitab_c_set_brush@20" (ByVal feature As Integer, ByVal fg_color As Integer, ByVal bg_color As Integer, ByVal pattern As Integer, ByVal transparent As Integer)
    Public Declare Sub mitab_c_set_field Lib "mitab.dll" Alias "
_mitab_c_set_field@12" (ByVal feature As Integer, ByVal field_index As Integer, ByVal value As String)
    Public Declare Sub mitab_c_set_font Lib "mitab.dll" Alias "
_mitab_c_set_font@8" (ByVal feature As Integer, ByVal font_name As String)
    Public Declare Sub mitab_c_set_pen Lib "mitab.dll" Alias "
_mitab_c_set_pen@16" (ByVal feature As Integer, ByVal width As Integer, ByVal pattern As Integer, ByVal color As Integer)
    Public Declare Sub mitab_c_set_points Lib "mitab.dll" Alias "
_mitab_c_set_points@20" (ByVal feature As Integer, ByVal part As Integer, ByVal vertex_count As Integer, ByRef x As Double, ByRef y As Double)
    Public Declare Function mitab_c_set_projinfo Lib "mitab.dll" Alias "
_mitab_c_set_projinfo@8" (ByVal dataset As Integer, ByVal projinfo As mitab_projinfo) As Integer
    Public Declare Sub mitab_c_set_symbol Lib "mitab.dll" Alias "
_mitab_c_set_symbol@16" (ByVal feature As Integer, ByVal symbol_no As Integer, ByVal symbol_size As Integer, ByVal symbol_color As Integer)
    Public Declare Sub mitab_c_set_text Lib "mitab.dll" Alias "
_mitab_c_set_text@8" (ByVal feature As Integer, ByVal text As String)
    Public Declare Sub mitab_c_set_text_display Lib "mitab.dll" Alias "
_mitab_c_set_text_display@48" (ByVal feature As Integer, ByVal angle As Double, ByVal height As Double, ByVal width As Double, ByVal fg_color As Integer, ByVal bg_color As Integer, ByVal justification As Integer, ByVal spacing As Integer, ByVal linetype As Integer)
    Public Declare Function mitab_c_write_feature Lib "mitab.dll" Alias "
_mitab_c_write_feature@8" (ByVal handle As Integer, ByVal feature As Integer) As Integer
    Public Declare Function mitab_c_get_field_width Lib "mitab.dll" Alias "
_mitab_c_get_field_width@8" (ByVal handle As Integer, ByVal field As Integer) As Integer
    Public Declare Function mitab_c_get_field_precision Lib "mitab.dll" Alias "
_mitab_c_get_field_precision@8" (ByVal handle As Integer, ByVal field As Integer) As Integer
    Public Declare Function mitab_c_is_interior_ring Lib "mitab.dll" Alias "
_mitab_c_is_interior_ring@8" (ByVal feature As Integer, ByVal requestedringindex As Integer) As Integer
    Public Declare Function mitab_c_load_coordsys_table Lib "mitab.dll" Alias "
_mitab_c_load_coordsys_table@4" (ByVal filename As String) As Integer
    Public Declare Function mitab_c_get_feature_count Lib "mitab.dll" Alias "
_mitab_c_get_feature_count@4" (ByVal handle As Integer) As Integer
    Public Declare Function mitab_c_get_field_as_double Lib "mitab.dll" Alias "
_mitab_c_get_field_as_double_vb@8" (ByVal feature As Integer, ByVal field As Integer) As Double
End Module

 

 

以下代码随机生成点,经测试100万个点耗时约1分40秒,大概1秒1万个点,这与MapX 100个点耗时1秒相比,兼职就是拖拉机和动车的区别。

 

    Public Function CreateTraceLayer(ByVal sLayerName As String) As String
        Try
            Dim sPath As String = My.Application.Info.DirectoryPath & "/temp"
            If Not My.Computer.FileSystem.DirectoryExists(sPath) Then
                My.Computer.FileSystem.CreateDirectory(sPath)
            End If
            sPath = sPath & "/" & TraceLayerName & ".tab"

 

            Dim Feature, Dataset, Field_Index As Integer
            Dim x As Double
            Dim y As Double
            Dim sTmp As String
            Dim clor As Integer
            Dataset = mitab_c_create(sPath, "tab", "CoordSys Earth Projection 1, 0", 90, -90, 180, -180)

 

            If (Dataset = 0) Then
                sTmp = Space(255)
                i1 = mitab_c_getlasterrormsg_vb(sTmp, 255)
                MsgBox("Failed to create " & "tab" & " file: " & sPath & vbCrLf & Left(sTmp, i1))
                CreateTraceLayer = ""
                Exit Function
            End If

            Field_Index = mitab_c_add_field(Dataset, "Index", TABFT_Integer, 0, 0, 1, 1)
            Field_Index = mitab_c_add_field(Dataset, "Longitude", TABFT_Decimal, 10, 6, 0, 0)
            Field_Index = mitab_c_add_field(Dataset, "Latitude", TABFT_Decimal, 10, 6, 0, 0)

            Dim counter As Integer = 0
            Randomize()

 

            Do While counter < 10000  '颜色设置值越界引起内存溢出错误   生成1百万个点约1分40秒
                Feature = mitab_c_create_feature(Dataset, TABFC_Point)
                x = 180 * Rnd()
                y = 90 * Rnd()
                Call mitab_c_set_points(Feature, 0, 1, x, y)
                clor = Color.Red.R * 65536 + Color.Red.G * 256 + Color.Red.B 'i1 * i2
                Call mitab_c_set_symbol(Feature, 36, 15, clor)  

 

                Call mitab_c_set_field(Feature, 0, counter.ToString)
                Call mitab_c_set_field(Feature, 1, Format(x, "##0.##0000"))
                Call mitab_c_set_field(Feature, 2, Format(y, "##0.##0000"))
                Call mitab_c_write_feature(Dataset, Feature)
                Call mitab_c_destroy_feature(Feature)
                counter += 1
            Loop

            mitab_c_close((Dataset))

            If (mitab_c_getlasterrorno() <> 0) Then
                sTmp = Space(255)
                i1 = mitab_c_getlasterrormsg_vb(sTmp, 255)
                MsgBox("Last Error: " & Left(sTmp, i1))
            End If

            CreateTraceLayer = sPath
        Catch Ex As Exception

        Finally

        End Try

    End Function

 

完成加载图层的代码

 

            Dim sTabPath As String
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '出错或者崩毁问题都来自用mitab库生成图元时参数不正确。一定注意不要溢出,参数都要格式化输入
            '方案1:
            sTabPath = CreateTraceLayer(TraceLayerName)
            Map.Refresh()

 

 

 

 

 

脚注:一开始我就对MapX这个东东不太支持,似乎他真的是过时了。接触一段时间后发现其实不然,技术在革新,但科学只是在进步而已。无论用什么技术,只要拥有足够的智慧,任何能想到的东西基本都是可以实现地。

但是我还是更喜欢ESRI,ArcGIS真的很强大!另外对SupMap充满了希望!

你可能感兴趣的:(c,function,String,Integer,vb,dataset)