-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.py
More file actions
62 lines (47 loc) · 1.29 KB
/
metadata.py
File metadata and controls
62 lines (47 loc) · 1.29 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
"""
metadata.py
-- process anns to geojson
-- update meta data
"""
import os, json
import pandas as pd
import geopandas as gpd
import settings
from anntool import extract_meta
def extract_uid(ann):
"""return uid from ann file name"""
#uid1540@SanAnd_08503_12023-008_13095-013_0387d_s01_L090HH_01.ann
if not "uid" in ann:
return "0000"
uid = ann.split("@")[0][3:]
return uid
def ann2json():
"""ann files to geojson"""
os.chdir(settings.ANN_DIR)
anns = [x for x in os.listdir() if x[-4:]=='.ann']
metalist = []
uidlist = []
for ann in anns:
annuid = extract_uid(ann)
uidlist.append(annuid)
print(annuid)
meta_dict = extract_meta(ann)
meta_dict['UID']= annuid
metalist.append(meta_dict)
df = pd.DataFrame(metalist)
#df['geom'] = df['geom'].apply(wkt.loads)
df['geometry']=gpd.GeoSeries.from_wkt(df['geom'])
df.drop('geom', axis=1, inplace=True)
#df.to_csv('anns.csv')
gdf = gpd.GeoDataFrame(df,geometry='geometry')
gdf.crs = 'epsg:4326'
uidlist.sort()
metajson = "{}_{}.geojson".format(uidlist[0],uidlist[-1])
gdf.to_file(metajson, driver='GeoJSON')
df = None
gdf = None
return
def main():
ann2json()
if __name__ == "__main__":
main()