forked from ualsg/hdb3d-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.py
145 lines (141 loc) · 6.43 KB
/
metadata.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#-- generate full metadata for hdb3d-data
#-- metadata can be written to the parent file or separately
import json
import uuid
import os
import time
from datetime import date, datetime
def main():
#specify if you want the metadata in the file or separately with inFile = True or inFile = False
inFile = True
in_cm_name = '_data/hdb.json'
with open(in_cm_name, 'r+') as cm:
json_cm = json.load(cm)
full_metadata = generate_metadata(json_cm, cm, in_cm_name)
if inFile:
json_cm['metadata'] = full_metadata
cm.seek(0)
cm.write(json.dumps(json_cm, indent=2))
cm.truncate()
print("Full metadata written to file")
else:
#check if parent file already has unique id, adds it if missing
if not json_cm['metadata'].get("citymodelIdentifier"):
json_cm['metadata']["citymodelIdentifier"] = full_metadata["citymodelIdentifier"]
cm.seek(0)
cm.write(json.dumps(json_cm, indent=2))
cm.truncate()
md_file = os.path.basename(cm.name).split(".")[0] + '_metadata.json'
with open('_data/'+md_file, 'w') as md:
md.write(json.dumps(full_metadata[0], indent=2))
print("Full metadata written to separate file")
def generate_metadata(citymodel,cm_file,cm_file_name):
if not citymodel["metadata"].get("citymodelIdentifier"):
unique_id = str(uuid.uuid4())
else:
unique_id = citymodel["metadata"]["citymodelIdentifier"]
metadata = {
"citymodelIdentifier": unique_id,
"datasetTitle": "3D city model of public housing (HDB) buildings in Singapore",
"datasetReferenceDate": datetime.fromtimestamp(os.path.getmtime(cm_file_name)).strftime('%Y-%m-%d %H:%M:%S'),
"geographicLocation": "Singapore, Republic of Singapore",
"datasetLanguage": "English",
"datasetCharacterSet": "UTF-8",
"datasetTopicCategory": "geoscientificInformation",
"distributionFormatVersion": citymodel["version"],
"referenceSystem": "urn:ogc:def:crs:EPSG::3414",
"spatialRepresentationType": "vector",
"onlineResource": "https://github.com/ualsg/hdb3d-data",
"fileIdentifier": os.path.basename(cm_file.name),
"geographicalExtent": [
11474.615816611371,
28054.808157231186,
0,
45326.44585339671,
48758.78176700817,
141.3
],
"datasetPointOfContact": {
"contactName": "NUS Urban Analytics Lab, National University of Singapore",
"emailAddress": "[email protected]",
"contactType": "organization",
"website": "https://ual.sg/"
},
"metadataStandard": "ISO 19115 - Geographic Information - Metadata",
"metadataStandardVersion": "ISO 19115:2014(E)",
"metadataLanguage": "English",
"metadataCharacterSet": "UTF-8",
"metadataDateStamp": str(date.today()),
"metadataPointOfContact":{
"contactName": "Anna Labetski",
"emailAddress": "[email protected]",
"contactType": "processor",
"website": "https://3d.bk.tudelft.nl/alabetski/"
},
"lineage":[
{
"thematicModels":["Building"],
"source":[{
"description": "2D building footprints from OpenStreetMap",
"sourceCitation": "https://www.openstreetmap.org/#map=12/1.3649/103.8229",
"sourceReferenceSystem": "urn:ogc:def:crs:EPSG::4326"
},
{
"description": "HDB Property Information",
"sourceCitation": "https://data.gov.sg/dataset/hdb-property-information",
}
],
"processStep":{
"description": "Buildings extruded to LoD1.2 based on number of stories.",
"processor":{
"contactName": "NUS Urban Analytics Lab, National University of Singapore",
"emailAddress": "[email protected]",
"contactType": "organization",
"website": "https://ual.sg/"
},
"stepDateTime": datetime.fromtimestamp(os.path.getmtime(cm_file_name)).strftime('%Y-%m-%d %H:%M:%S'),
"reference": "https://github.com/ualsg/hdb3d-code"
}
}],
"temporalExtent":{
"startDate": "2019-07-05",
"endDate": "2019-07-18",
},
"abstract": "A 3D city model of all public housing (HDB) buildings in Singapore, generated by conflating different open datasets. Public housing accommodates the predominant majority of Singapore’s population, so the dataset covers most of the nation’s residential buildings. Generated using extrusion, with the number of storeys of each block utilised as a proxy for the height. Cities around the world are increasingly releasing their 3D city models as open data. Researchers and practitioners in different disciplines are using 3D geoinformation to carry out a variety of spatial analyses. This model is openly available, hopefully benefiting researchers who previously did not have access to such data.",
"specificUsage": "Openly available 3D city model of Singapore",
"keywords":[
"cityJSON",
"3D",
"city model",
"public housing",
"Singapore",
"buildings"
],
"constraints":{
"legalConstraints":"licenceUnrestricted",
"securityConstraints":"unclassified",
"userNote":"open access"
},
"thematicModels":[
"Building"
],
"textures": "absent",
"materials": "absent",
"presentLoDs":{
"1.2": len(citymodel["CityObjects"])
},
"cityfeatureMetadata":{
#Right now only Building but can add other modules in the future
"Building":{
"uniqueFeatureCount": len(citymodel["CityObjects"]),
"aggregateFeatureCount": len(citymodel["CityObjects"]),
"presentLoDs":{
"1.2": len(citymodel["CityObjects"])
}
#TO DO: BuildingParts and BuildingInstallations
}
}
}
return metadata
if __name__ == '__main__':
main()