sql-server - 如何在 SQL Server 数据库中存储地理文件,例如 shapefile (.shp)?
问题描述
我的电脑中有一些扩展名为 (.shp) 的 shapefile。但我知道任何单个 shapefile 都由三个强制性文件组成,即 .shp、.shx 和 .dbf。这些文件使 shapefile 被识别为 shapefile。
我想在 Visual Studio 中编写一些代码,使我能够浏览计算机位置并找到此类文件,然后如果找到文件,我想将它们保存在 SQL Server 数据库中。
如何检查所选文件是否真的是 shapefile?我应该编写什么代码才能在 SQL Server 中使用这些地理数据?
我听说 SQL Server 支持地理数据。
我已经创建了 Windows 窗体应用程序和一个按钮来浏览文件。
代码如下所示
Private Sub BtnBrowse_Click(sender As System.Object, e As
System.EventArgs) Handles BtnBrowse.Click
OpenFileDialog1.InitialDirectory = "E:\"
OpenFileDialog1.Filter = "shapefile files (*.shp)|*.|All files
(*.*)|*.*"
OpenFileDialog1.ShowDialog()
txtFileName.Text = OpenFileDialog1.FileName
End Sub
Private Sub BtnSave_Click(sender As System.Object, e As
System.EventArgs) Handles BtnSave.Click
Try
'code to check if it is a shapefile
'code to save shapefile in database
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
我希望单击 BtnSave 时,代码应检查所选文件是否为 shapefile,如果为 true,则应将文件保存到 sql server,否则应抛出所选文件不是 shapefile 的异常。
解决方案
shapefile的基本理解1:
1) shapefile 的所有支持文件具有完全相同的名称和不同的扩展名。2).shp,.shx 和 .dbf 是强制性的,.prj,.sbn 和.sbx,.fbn 和 .fbx,.ain 等是附加文件
带有有效性检查代码的代码片段:
Try
if(abc.shp)
{
if ((abc.shx) && (abc.dbf)) `This is the condition for valid shapefile`
{
//code should fetch all the files with exactly same name and different possible extensions of supporting files. You can get the list in link mentioned below
return valid_shapefile
}
}
推荐阅读
- ios - 如何使用 Swift 扫描非 LE 设备?
- python - 不可能在 QTextBrowser 中显示作者、记录者、翻译者
- python - 使用 python 从盈透证券获取买卖价
- google-apps-script - UrlFetchApp.fetch 由 Sheets 事件触发,因缺少权限而失败,但在直接运行时有效
- xml - 使用 XSLT 根据属性修改数据
- php - 作曲家更新给出错误说插件无法初始化,没有为每个包找到类
- ios - SwiftUI SecureField 跟踪活动/非活动状态
- python - 如何添加脚本任务以在 Bamboo 中运行 pytest
- android - 如何从android中的“MainActivity”更新片段内的Listview?
- python - Python Selenium - 在未找到预期值时尝试使测试失败