|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "attachments": {}, |
| 5 | + "cell_type": "markdown", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "Geojson2json.py is a simple script that directly converts GeoJSON files extracted using the GPlates GUI to the World Builder-compatible JSON format compatible with .wb . Currently, it supports continental plate geometries. \n", |
| 9 | + "\n", |
| 10 | + "The script reads the GeoJSON file, processes polygon features, and assigns default or provided values for \n", |
| 11 | + "maximum depth and compositions. The output JSON file follows the World Builder structure, making it ready \n", |
| 12 | + "for use in geodynamic modeling applications.\n", |
| 13 | + "\n", |
| 14 | + "Future improvements may integrate this script with GPlate2GWB for a more streamlined workflow.\n", |
| 15 | + "\n", |
| 16 | + "Usage:\n", |
| 17 | + " python geojson2json.py\n" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "code", |
| 22 | + "execution_count": null, |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
| 26 | + "import json\n", |
| 27 | + "\n", |
| 28 | + "# Configuration defined by the user\n", |
| 29 | + "geojson_file = \"reconstructed_400.00Ma.geojson\" # Input GeoJSON file\n", |
| 30 | + "output_file = \"world_builder_model.json\" # Output JSON file\n", |
| 31 | + "default_max_depth = 350e3\n", |
| 32 | + "default_compositions = [0]\n", |
| 33 | + "\n", |
| 34 | + "try:\n", |
| 35 | + " # Load GeoJSON file\n", |
| 36 | + " with open(geojson_file, 'r') as f:\n", |
| 37 | + " geojson_data = json.load(f)\n", |
| 38 | + "\n", |
| 39 | + " features = []\n", |
| 40 | + "\n", |
| 41 | + " for feature in geojson_data.get('features', []):\n", |
| 42 | + " if feature.get('geometry', {}).get('type') == 'Polygon':\n", |
| 43 | + " name = feature.get('properties', {}).get('NAME', 'Unknown')\n", |
| 44 | + " coordinates = [list(coord) for coord in feature['geometry']['coordinates'][0]]\n", |
| 45 | + "\n", |
| 46 | + " # Use provided properties or fall back to defaults\n", |
| 47 | + " max_depth = feature.get('properties', {}).get('MAX_DEPTH', default_max_depth)\n", |
| 48 | + " compositions = feature.get('properties', {}).get('COMPOSITIONS', default_compositions)\n", |
| 49 | + "\n", |
| 50 | + " feature_data = {\n", |
| 51 | + " \"model\": \"continental plate\",\n", |
| 52 | + " \"name\": name,\n", |
| 53 | + " \"max depth\": max_depth,\n", |
| 54 | + " \"coordinates\": coordinates,\n", |
| 55 | + " \"composition models\": [\n", |
| 56 | + " {\n", |
| 57 | + " \"model\": \"uniform\",\n", |
| 58 | + " \"compositions\": compositions,\n", |
| 59 | + " \"max depth\": max_depth\n", |
| 60 | + " }\n", |
| 61 | + " ]\n", |
| 62 | + " }\n", |
| 63 | + " features.append(feature_data)\n", |
| 64 | + "\n", |
| 65 | + " output_data = {\n", |
| 66 | + " \"version\": \"1.1\",\n", |
| 67 | + " \"interpolation\": \"continuous monotone spline\",\n", |
| 68 | + " \"coordinate system\": {\n", |
| 69 | + " \"model\": \"spherical\",\n", |
| 70 | + " \"depth method\": \"starting point\"\n", |
| 71 | + " },\n", |
| 72 | + " \"features\": features\n", |
| 73 | + " }\n", |
| 74 | + "\n", |
| 75 | + " # Save output to JSON file\n", |
| 76 | + " with open(output_file, 'w') as out_f:\n", |
| 77 | + " json.dump(output_data, out_f, indent=4)\n", |
| 78 | + "\n", |
| 79 | + " print(f\"Conversion successful! Output saved to {output_file}\")\n", |
| 80 | + "\n", |
| 81 | + "except Exception as e:\n", |
| 82 | + " print(f\"Error processing file: {e}\")\n" |
| 83 | + ] |
| 84 | + } |
| 85 | + ], |
| 86 | + "metadata": { |
| 87 | + "kernelspec": { |
| 88 | + "display_name": "extra_postprocess", |
| 89 | + "language": "python", |
| 90 | + "name": "python3" |
| 91 | + }, |
| 92 | + "language_info": { |
| 93 | + "codemirror_mode": { |
| 94 | + "name": "ipython", |
| 95 | + "version": 3 |
| 96 | + }, |
| 97 | + "file_extension": ".py", |
| 98 | + "mimetype": "text/x-python", |
| 99 | + "name": "python", |
| 100 | + "nbconvert_exporter": "python", |
| 101 | + "pygments_lexer": "ipython3", |
| 102 | + "version": "3.10.15" |
| 103 | + }, |
| 104 | + "orig_nbformat": 4 |
| 105 | + }, |
| 106 | + "nbformat": 4, |
| 107 | + "nbformat_minor": 2 |
| 108 | +} |
0 commit comments