当前位置:网站首页>GDB data reading in GDAL (III) of GIS
GDB data reading in GDAL (III) of GIS
2022-06-23 05:31:00 【yelangking1】
as everyone knows ,arcgis It is still the most popular gis Data management production platform . stay gis field , Still want to arcgis Vector data reading supported . First , A brief introduction gdb data . stay ArcGIS In software , There are two types of geographic databases ,File Geodatabase( File geographic database ) and Personal Geodatabase( Personal geographic database ).
One 、 Introduction to database contents
1.1 File geographic database GDB
File geographic database (File Geodatabase) The data suffix is expressed as .gdb, The whole organization is folder , Can be stored 、 Query and manage spatial data and ⾮ Spatial data . Without using DBMS It can expand and store a large amount of data . The file geographic database can be used by multiple users at the same time , But a data can only be edited by one user . therefore , A file geographic database can be accessed by multiple editors , But you have to edit different data .
1.2 Personal geographic database MDB
Personal geographic database (Personal Geodatabase) The data suffix is expressed as .mdb, The whole organization is a document , All data sets are stored in Microsoft Access In the data file , stay Microsoft Access Data files are stored and managed .
Two 、gdb Introduction to database format

gdb The data is stored in the directory shown above , Unless you are very familiar with the field of data management , Otherwise, do not edit these files easily .
3、 ... and 、 stay Qgis Open in gdb data , Preview beforehand
If you don't have test data , The demo data can be downloaded from the following website ,http://horizon2021.xyz/,
We download the national administrative division gdb data , After decompressing , take gdb Drag folder to qgis Show in , You can see the following spatial information .
Open any layer attribute table , Take sub provinces as an example :

Four 、 Use Gdal Read parsing gdb data , about gdal See the previous series of articles for general operation gis A sharp weapon Gdal( Two )shp data fetch and windows Next gdal Of java Development environment construction . No more details here .
Read gdb when , Pay attention to the following drivers
// Reading data , Here we use gdb File as an example
String strDriverName = "OpenFileGDB";
// Create a file , according to strDriverName The extension automatically determines the drive type
org.gdal.ogr.Driver oDriver = ogr.GetDriverByName(strDriverName);Other information can be read shp The documents are the same . The detailed code is as follows :
@Test
public void testReadGdb() {
// Specify the name and path of the file
String gdbFile = "F:\\vector_data\\other\\ China's administrative division data .gdb\\ China's administrative division data .gdb";
// Register all drivers
ogr.RegisterAll();
// In order to support Chinese path , Please add the following code
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
// In order to make the property sheet fields support Chinese , Please add the following sentence
gdal.SetConfigOption("SHAPE_ENCODING", "CP936");
// Reading data , Here we use gdb File as an example
String strDriverName = "OpenFileGDB";
// Create a file , according to strDriverName The extension automatically determines the drive type
org.gdal.ogr.Driver oDriver = ogr.GetDriverByName(strDriverName);
if (oDriver == null) {
System.out.println(strDriverName + " The driver is not available !\n");
return;
}
DataSource dataSource = oDriver.Open(gdbFile, 0);
for(int i = 0;i<dataSource.GetLayerCount();i++) {
Layer layerIdx = dataSource.GetLayer(i);
System.out.println(" Layer Name :<==>" + layerIdx.GetName());
}
Layer layer = dataSource.GetLayer(" Province by province ");
String layerName = layer.GetName();
System.out.println(" Layer Name :" + layerName);
SpatialReference spatialReference = layer.GetSpatialRef();
//System.out.println(spatialReference);
System.out.println(" Spatial reference coordinate system :" + spatialReference.GetAttrValue("AUTHORITY", 0)
+ spatialReference.GetAttrValue("AUTHORITY", 1));
double[] layerExtent = layer.GetExtent();
System.out.println(" colour range :minx:" + layerExtent[0] + ",maxx:" + layerExtent[1] + ",miny:" + layerExtent[2]
+ ",maxy:" + layerExtent[3]);
FeatureDefn featureDefn = layer.GetLayerDefn();
int fieldCount = featureDefn.GetFieldCount();
Map<String,String> fieldMap = new HashMap<String,String>();
for (int i = 0; i < fieldCount; i++) {
FieldDefn fieldDefn = featureDefn.GetFieldDefn(i);
// Get the attribute field type
int fieldType = fieldDefn.GetFieldType();
String fieldTypeName = fieldDefn.GetFieldTypeName(fieldType);
// Get the attribute field name
String fieldName = fieldDefn.GetName();
fieldMap.put(fieldTypeName, fieldName);
}
System.out.println(fieldMap);
long featureCount = layer.GetFeatureCount();
System.out.println(" Number of layer elements :" + featureCount);
Feature feature2 = null;
while((feature2 = layer.GetNextFeature()) != null) {
//System.out.println(feature2.GetGeometryRef().ExportToJson());
System.out.println(feature2.GetFieldAsString("Shape_Area") + "\t" + feature2.GetFieldAsString(" provincial area "));
}
oDriver.delete();
gdal.GDALDestroyDriverManager();
}The console outputs the following information :

summary : This paper introduces arcgis Next gdb and mdb Database files , The difference between the two is simply compared . In this paper, the gdb Data download website and data directory display , And USES the qgis Preview the data , Finally, give gdal Of gdb Data parsing complete code .
边栏推荐
- STC 32位8051单片机开发实例教程 一 开发环境搭建
- 数据库连接异常:create connection error, url: jdbc:mysql://ip/数据库名, errorCode 0, state 08S01问题处理
- The weak are as irritable as tigers, the strong are as calm as water, and the really powerful have already given up their emotions
- Ams:startactivity desktop launch application
- JDBC入门学习(二)之封装工具类
- Go language - use of packages
- 基金业绩评价
- Web application security testing guide
- WebRTC[47] - WebRTC 保存 YUV 数据的常用方式
- MCS:离散随机变量
猜你喜欢
随机推荐
Markdown add background color to the picture
Jenkins安装部署以及自动构建和发布jar应用
数学分析_笔记_第1章:集合与映射
CF [1700d] D. River locks (DP, bisection, Mathematics)
A bug in rtklib2.4.3 B34 single point positioning
账号多开是什么意思?为什么要账号多开?如何安全实现?
CF【1700D】D. River Locks(dp、二分、数学)
ES6的Array.from方法创建长度为N的undefined数组
Design and implementation of spark offline development framework
云原生架构(04)-CNCF
About replay attack and defense
View of MySQL introductory learning (III)
弱者易怒如虎,强者平静如水,真正厉害的人早已戒掉了情绪
The weak are as irritable as tigers, the strong are as calm as water, and the really powerful have already given up their emotions
Introduction to MySQL (I) grammar
JDBC入门学习(一)之DML操作
STM32cube CMSIS_ V2 FreeRTOS queue usage
Complete the primary school project in 3 days, and teach you to complete the weather broadcast system hand in hand!
Go language - custom error
1010 Radix









