Skip to content

Instantly share code, notes, and snippets.

@balazsdukai
Created April 24, 2023 09:14
Show Gist options
  • Save balazsdukai/9b594da08264cc436093e665dd034731 to your computer and use it in GitHub Desktop.
Save balazsdukai/9b594da08264cc436093e665dd034731 to your computer and use it in GitHub Desktop.
# Returns the size of object in bytes
from sys import getsizeof
CityJSON = {
"appearance": {
"materials": [
{
"name": "door",
"ambientIntensity": 0.2000,
"diffuseColor": [0.9000, 0.1000, 0.7500],
"emissiveColor": [0.9000, 0.1000, 0.7500],
"specularColor": [0.9000, 0.1000, 0.7500],
"shininess": 0.2,
"transparency": 0.5,
"isSmooth": False
},
{
"name": "ground",
"ambientIntensity": 0.2000,
"diffuseColor": [0.9000, 0.1000, 0.7500],
"emissiveColor": [0.9000, 0.1000, 0.7500],
"specularColor": [0.9000, 0.1000, 0.7500],
"shininess": 0.2,
"transparency": 0.5,
"isSmooth": False
},
{
"name": "window",
"ambientIntensity": 0.2000,
"diffuseColor": [0.9000, 0.1000, 0.7500],
"emissiveColor": [0.9000, 0.1000, 0.7500],
"specularColor": [0.9000, 0.1000, 0.7500],
"shininess": 0.2,
"transparency": 0.5,
"isSmooth": False
},
{
"name": "roof",
"ambientIntensity": 0.2000,
"diffuseColor": [0.9000, 0.1000, 0.7500],
"emissiveColor": [0.9000, 0.1000, 0.7500],
"specularColor": [0.9000, 0.1000, 0.7500],
"shininess": 0.2,
"transparency": 0.5,
"isSmooth": False
},
{
"name": "wall",
"ambientIntensity": 0.4000,
"diffuseColor": [0.1000, 0.1000, 0.9000],
"emissiveColor": [0.1000, 0.1000, 0.9000],
"specularColor": [0.9000, 0.1000, 0.7500],
"shininess": 0.0,
"transparency": 0.5,
"isSmooth": True
},
{
"name": "dormer",
"ambientIntensity": 0.2000,
"diffuseColor": [0.9000, 0.1000, 0.7500],
"emissiveColor": [0.9000, 0.1000, 0.7500],
"specularColor": [0.9000, 0.1000, 0.7500],
"shininess": 0.2,
"transparency": 0.5,
"isSmooth": False
},
{
"name": "and_one_more_for_good_measure",
"ambientIntensity": 0.2000,
"diffuseColor": [0.9000, 0.1000, 0.7500],
"emissiveColor": [0.9000, 0.1000, 0.7500],
"specularColor": [0.9000, 0.1000, 0.7500],
"shininess": 0.2,
"transparency": 0.5,
"isSmooth": False
},
],
"textures": [],
"vertices-texture": [],
"default-theme-texture": "myDefaultTheme1",
"default-theme-material": "myDefaultTheme2"
}
}
print(f"CityJSON object size (bytes) with materials: {getsizeof(CityJSON['appearance']) + getsizeof(CityJSON['appearance']['materials'])}")
# CityJSON object size (bytes) with materials: 344
# 3D BAG, different texture for each wall and roof surface, whole Netherlands.
# There are 9692978 buildings in the data set.
texture = {
"type": "JPG",
"image": "http://www.someurlthatisverylongandevenmorelongerandsubdomain.andsomeotherdomainthatisalsoverylong.org/filename.jpg",
"wrapMode": "wrap",
"textureType": "unknown",
"borderColor": [0.0, 0.1, 0.2, 1.0]
}
nr_wall_roof_surfaces = 303495171
CityJSON["appearance"]["textures"] = [texture for srf in range(nr_wall_roof_surfaces)]
print(f"CityJSON object size (bytes) with materials, plus different texture for each surface, Netherlands: {getsizeof(CityJSON['appearance']) + getsizeof(CityJSON['appearance']['materials']) + getsizeof(CityJSON['appearance']['textures'])}")
# CityJSON object size (bytes) with materials, plus different texture for each surface, Netherlands: 2481602248
# That's about 2.48Gb
# We add an uv-coordinate for each vertex for mapping the textures.
# This is excessive, because in reality, we probably won't need a uv-coordinate for each vertex.
nr_vertices = 2033913590
uv_coord = [0.0, 0.0]
CityJSON["appearance"]["vertices-texture"] = [uv_coord for vtx in range(nr_vertices)]
print(f"CityJSON object size (bytes) with materials, plus different texture for each surface, plus uv-coordinate for each vertex, Netherlands: {getsizeof(CityJSON['appearance']) + getsizeof(CityJSON['appearance']['materials']) + getsizeof(CityJSON['appearance']['textures']) + + getsizeof(CityJSON['appearance']['vertices-texture'])}")
# CityJSON object size (bytes) with materials, plus different texture for each surface, plus uv-coordinate for each vertex, Netherlands: 18818610480
# That's about 18.81Gb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment