如何将存储在SQLite数据库中的BLOB数据转换为SharpMap.Geometries.Geometry

时间:2018-02-12 12:29:10

标签: c# sqlite sharpmap wkb

我有几何数据存储在SQLite数据库中,列的数据类型是BLOB。

我使用以下方法将BLOB数据转换为锐利的地图几何

  

SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse(< byte array>);

但它引发了异常“字节顺序无法识别

但是如果我使用sql server管理工作室数据库并使用Image数据类型将几何数据保存在表中,那么我得到的几何没有任何错误。

唯一的区别是数据类型,在SQLite中我使用了数据类型“BLOB”,在sql server中我使用了数据类型“Image”。

我还注意到字节数组大小的另一个区别,如果我使用SQLite数据库然后我得到字节数组大小为“3812”,如果我使用sql server数据库然后我得到字节数组大小为“1902 ”

有人知道解决方案吗?

我正在处理以下数据:

  

0x01030000000100000076000000908FC85763BD2D41B5E1CEFAB9385841A8564425CABB2D412642A24FB83858411BFBC2F5D3BA2D4184A995ABBF385841CAD4637804BA2D415C8C795FA4385841F114538DDDB92D41F55448C2AC385841C64F734F30B92D41B249DC25CD385841A3CB7AAD4DB12D4199B5872A3B3858416D582E7839B02D41A9556428F637584143144991BBB02D416A06CFA4D53758417B22EADD21B12D41655331199F375841452E9D966AB12D4166ED16B88B3758419BB6676466B02D413D6180586D375841E89DECDF98B02D4191927111613758411C78DF662DB22D4170EA69F128375841D9D525280FB22D41A078FBDB103758415C485630A6B12D41F3EB2128EC3658419D97CCE77BB22D41C592B7E1CF365841831F9ECFB8B32D41589F8359E8365841A4599CA91AB42D4183458EF6F7365841BD50CAAF3AB42D41D8584F2DF836584115C52BF88AB42D41CB916AC0DF365841C9C54DE07BB32D41EE6958C1BF365841DE5A1651E3B22D415B4704FDA6365841D73CCC798FB22D41CB9E9E17963658415663F51F78B22D41E3403AA988365841B4235ECA76B22D41F0CA34EE7A36584188D446ECB9B32D41FB8ED8B5093658412812E3D8E8B32D41616C0DA2CC3558419DF34042BDB32D41EE235FC17B355841A36F009898B22D41054448484C355841E21AEBA9A FB42D41946B3A2761355841C463E28F4FB52D413FF3CA035F355841461A2E564BB52D4113CAB89257355841D2226CFEF8B62D41B71CC9EC153558419073855FC9B72D410A4B9247E1345841508668C7C4BC2D41E0B9D62FD7345841661D26E68ABE2D410E80C7D7AF34584149753FDA9AC02D418BDAADF075345841B50A90264DC32D41871EDC1F7D345841E0F2F43CA2C62D4107B6748781345841870AC042C0C62D41F61C18959D345841B238413BC0C72D4124BD21B4DC34584180D416141CC82D41E44457B4E934584175CA2F0700C92D4149867508343558414835F68B24CF2D418F8AD232F3345841D200559B07D02D414E65E5D5E1345841065A4DCB6CD02D4185CE4559E2345841254C3A15C5D02D415D1D78A14935584166C96D57F5D02D41C414E543623558415D6312F097D02D41C605342D94355841E65A332103D12D412A5960ABBA3558411194E61042D12D41F97012B6EC35584116DEF2091ED12D4186D8858FF03558412248444320D12D41EFAF11A6FD355841CB79634EEDD12D414275A2982D3658418C67CC2FE2D12D419E5D943153365841A93F65748BD12D418D280AC6643658419D1B2A62C0D12D41B19988E397365841934A32D73DD12D41BA8CCD9FAA365841646BF8D86DD22D414ED7D61EE136584146B4EFBE0DD32D417A3B6E9BE03658419F2A4C7030D32D41F CBCC386E53658413BB53AA930D32D4164780A6D1337584191D463BCD9D12D41B116E437083758419B2461F02CD12D415D301E26073758412FE24D704FD02D41DF24A4CB0C3758416BACD3FE50D02D411FFCC625173758413730503BD0CF2D41AAE124111C3758413061531920CF2D41A0D6E5442A3758411A6E1BE5A4CE2D414619DF4C3837584115D1D11FF4CC2D412A2B02E47B375841B0897DE34ECC2D41F7A6AFD36F3758418831353299CB2D4110590A15B03758414401543C3ACB2D4191DD8968C137584146EBF50830CA2D4158913B28D63758414ED056195EC92D4133420C50EF375841CF6C4EDAAAC82D41A57F0D5BF73758419E80ED363DC82D4120E370DA00385841A0D330BE85C72D4176B51AAC163858418132924D17C42D41ED5B97AB51385841DB1AC747F9C32D4163E87BEE4638584157EEAC6699C42D41C9D1BC2B30385841040137B0EFC42D4119CE642E2A3858417020BF9CB1C52D41BC74946A263858416A3227FE16C72D41489711A10E385841C9151581BDC92D414F1C52F8D637584124EAE0F5F3CA2D413D750DBCB237584147D5911AB2CB2D41B9E3E10F743758417635C66FB1CB2D4140FA886365375841632C30082CCA2D41CE0050B46437584105493CCA11CA2D413CB74FA156375841FE65D622B6CA2D414A1C58C131375841C950F9B0B5CA2D41B4443CB92 B375841AD2913B768CB2D414719112023375841A9A4228E94CA2D4133F15AA90F375841AEE3024BA5C82D41EC089804EA365841F76822311FC82D41CC821BEE01375841DE1EB75E2AC62D418150AD64E0365841C039F774E3C42D41551E26A4CE3658414520FB2E0CC42D415933F721D336584151443641D7C32D41FE09F7AA0437584112C708BA1AC12D41F123AB9F14375841E933DCD86CBF2D412A142AE92A375841A3BBE95204BF2D41538E58422037584179B2EE56F2BD2D416FA23E89EF365841F8B58C69BFBD2D41387D57ABF4365841EABF0EE24EBD2D41C63A39B302375841E83C19224DBC2D410263BB2A333758411530B6EA54BC2D41C672B000853758413E00C81F41BC2D4171582088943758416914F51292BC2D41B3EC88989837584110B8EC661EBD2D41582E965DC13758416CE832F109BD2D41A36943A90C3858419923E1491BBD2D41161BD1B918385841E17A43A53ABD2D4126D39FFB2038584123EF3F59FEBD2D41EC01CAEC313858419D044C88A4BC2D410422669584385841908FC85763BD2D41B5E1CEFAB938584100000000

3 个答案:

答案 0 :(得分:0)

您已将值的十六进制表示形式存储为文本。

CSV文件不能包含blob;您必须以其他格式导出数据。尝试SQL,然后从SQL Server格式转换blob文字,即:

INSERT INTO ... VALUES (... 0x0123...)

进入SQLite格式,即:

INSERT INTO ... VALUES (... x'0123...')

答案 1 :(得分:0)

如果CSV是您的交换格式,则应使用以下方法将几何图形转换为文本表示形式。几何上的.STAsText()函数 当您将CSV文本(通过编写自己的代码)导入到SQLite数据库中时,您应该使用一个知名文本解析器将该文本转换为几何体,然后从那里转换为可由{{处理的“知名二元体blob”。 1}}。这可以使用(例如)NetTopologySuite的Wkt阅读器完成:

SharpMap

答案 2 :(得分:0)

问题已经解决。

当我将sql server几何数据存储在CSV文件中时,它会以十六进制格式存储。当我在SQLite中导入该数据时,它只以十六进制格式存储几何体,而不是BLOB格式。

所以我搜索类似于直接转换SQLite BLOB数据中的sql server几何数据。

所以我找到了这个链接:https://www.codeproject.com/Articles/26932/Convert-SQL-Server-DB-to-SQLite-DB

它直接将sql server表转换为SQLite表,以便sql server中的几何数据自动转换为BLOB,将BLOb数据转换为SharpMap Geometry时没有问题。