当前位置:网站首页>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 .

原网站

版权声明
本文为[yelangking1]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230245223505.html