2025-11-20 15:13:53 -08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
|
|
|
|
Dubai Metaverse - OpenStreetMap Data Import Script
|
|
|
|
|
Imports OpenStreetMap data for Dubai Marina and converts to Unreal-compatible format
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import json
|
|
|
|
|
import argparse
|
|
|
|
|
from typing import List, Dict, Tuple
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import overpy
|
|
|
|
|
import geojson
|
|
|
|
|
except ImportError:
|
|
|
|
|
print("Error: Required packages not installed.")
|
|
|
|
|
print("Install with: pip install overpy geojson")
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_marina_buildings(api: overpy.Overpass) -> List[Dict]:
|
|
|
|
|
"""
|
|
|
|
|
Query OpenStreetMap for buildings in Dubai Marina area.
|
|
|
|
|
|
|
|
|
|
Note: Coordinates should be adjusted based on actual Dubai Marina location.
|
|
|
|
|
"""
|
|
|
|
|
# Dubai Marina approximate bounding box
|
|
|
|
|
# These coordinates should be verified and adjusted
|
|
|
|
|
query = """
|
|
|
|
|
[out:json][timeout:25];
|
|
|
|
|
(
|
|
|
|
|
way["building"](25.0750,55.1350,25.0850,55.1450);
|
|
|
|
|
);
|
|
|
|
|
out geom;
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
result = api.query(query)
|
|
|
|
|
buildings = []
|
|
|
|
|
|
|
|
|
|
for way in result.ways:
|
|
|
|
|
building = {
|
|
|
|
|
'id': way.id,
|
|
|
|
|
'nodes': [(node.lat, node.lon) for node in way.nodes],
|
|
|
|
|
'tags': way.tags
|
|
|
|
|
}
|
|
|
|
|
buildings.append(building)
|
|
|
|
|
|
|
|
|
|
return buildings
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"Error querying OpenStreetMap: {e}")
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def buildings_to_geojson(buildings: List[Dict], output_file: str):
|
|
|
|
|
"""Convert buildings to GeoJSON format."""
|
|
|
|
|
features = []
|
|
|
|
|
|
|
|
|
|
for building in buildings:
|
|
|
|
|
# Create polygon from nodes
|
|
|
|
|
coordinates = [[node[1], node[0]] for node in building['nodes']] # GeoJSON uses [lon, lat]
|
|
|
|
|
coordinates.append(coordinates[0]) # Close polygon
|
|
|
|
|
|
|
|
|
|
feature = {
|
|
|
|
|
'type': 'Feature',
|
|
|
|
|
'geometry': {
|
|
|
|
|
'type': 'Polygon',
|
|
|
|
|
'coordinates': [coordinates]
|
|
|
|
|
},
|
|
|
|
|
'properties': {
|
|
|
|
|
'id': building['id'],
|
|
|
|
|
'tags': building['tags']
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
features.append(feature)
|
|
|
|
|
|
|
|
|
|
geojson_data = {
|
|
|
|
|
'type': 'FeatureCollection',
|
|
|
|
|
'features': features
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with open(output_file, 'w') as f:
|
|
|
|
|
json.dump(geojson_data, f, indent=2)
|
|
|
|
|
|
|
|
|
|
print(f"✓ Exported {len(features)} buildings to {output_file}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
parser = argparse.ArgumentParser(description='Import OpenStreetMap data for Dubai Marina')
|
|
|
|
|
parser.add_argument('--output', '-o', default='data/processed/dubai_marina_buildings.geojson',
|
|
|
|
|
help='Output GeoJSON file path')
|
|
|
|
|
parser.add_argument('--area', help='Custom bounding box (lat1,lon1,lat2,lon2)')
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
# Create output directory if it doesn't exist
|
|
|
|
|
os.makedirs(os.path.dirname(args.output), exist_ok=True)
|
|
|
|
|
|
|
|
|
|
print("==========================================")
|
|
|
|
|
print("Dubai Metaverse - OSM Data Import")
|
|
|
|
|
print("==========================================")
|
|
|
|
|
print("")
|
|
|
|
|
print("Connecting to OpenStreetMap API...")
|
|
|
|
|
|
|
|
|
|
api = overpy.Overpass()
|
|
|
|
|
|
|
|
|
|
print("Querying Dubai Marina buildings...")
|
|
|
|
|
buildings = get_marina_buildings(api)
|
|
|
|
|
|
|
|
|
|
if not buildings:
|
|
|
|
|
print("⚠ No buildings found. Check coordinates and query.")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
print(f"Found {len(buildings)} buildings")
|
|
|
|
|
print("")
|
|
|
|
|
print("Converting to GeoJSON...")
|
|
|
|
|
buildings_to_geojson(buildings, args.output)
|
|
|
|
|
|
|
|
|
|
print("")
|
|
|
|
|
print("==========================================")
|
|
|
|
|
print("Import Complete")
|
2025-11-20 15:14:40 -08:00
|
|
|
print("==========================================")
|
2025-11-20 15:13:53 -08:00
|
|
|
print("")
|
|
|
|
|
print("Next steps:")
|
|
|
|
|
print("1. Review GeoJSON file in GIS software (QGIS)")
|
|
|
|
|
print("2. Import to Unreal Engine using GIS import tools")
|
|
|
|
|
print("3. Generate building meshes from footprints")
|
|
|
|
|
print("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|
|
|
|
|
|