tt.py
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# coding=utf-8
#author: 4N
#createtime: 2021/7/15
#email: nheweijun@sina.com
from osgeo import gdal,osr,ogr
from osgeo.gdal import *
from osgeo.ogr import *
import os
import json
def getInfo( path):
# driver: Driver = ogr.GetDriverByName("OpenFileGDB")
# ds: DataSource = driver.Open(path, 0)
#
#
# layer:Layer = ds.GetLayerByName("LM51130251998341HAJ00_B2")
#
# count = layer.GetFeatureCount()
#
# dd:Feature = layer.GetNextFeature()
# dd.
#
# for i in range(dd.GetFieldCount()):
# print(dd.GetField(i))
# ff = dd.GetField(1)
image: Dataset = gdal.Open(path)
geo = image.GetGeoTransform()
# print(image.GetSpatialRef())
origin: osr.SpatialReference = osr.SpatialReference()
origin.ImportFromWkt(image.GetProjection())
authority_code = origin.GetAuthorityCode(None)
band_count = image.RasterCount
band: Band = image.GetRasterBand(1)
count = band.GetOverviewCount()
nodatavalue = band.GetNoDataValue()
left_top = (geo[0], geo[3])
right_buttom = (geo[0] + geo[1] * image.RasterXSize, geo[3] + geo[5] * image.RasterYSize)
origin_extent = [left_top[0], right_buttom[1], right_buttom[0], left_top[1]]
info = {"band_count": band_count,
"overview_count": count,
"xy_size": [image.RasterXSize, image.RasterYSize],
"origin_extent": origin_extent,
"null_value": nodatavalue,
"crs_wkt": image.GetProjection(),
"crs": authority_code,
"crs_proj4": origin.ExportToProj4(),
"size": os.path.getsize(path),
"path": path,
"cell_x_size": geo[1],
"cell_y_size": geo[5]}
del image
return json.dumps(info)
if __name__ == '__main__':
data_path = r"E:\Data\矢量数据\广州\广州\dataset.gdb"
driver: Driver = ogr.GetDriverByName("OpenFileGDB")
ds: DataSource = driver.Open(data_path, 0)
layer : Layer = ds.GetLayer(0)
print(layer.GetMetadata())
print(layer.GetDescription())
print(layer.GetStyleTable())
print(ds.GetStyleTable())