From fa99fcc6dfff8857c7761376989048d00f163c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Dukai?= Date: Fri, 8 Mar 2024 16:14:59 +0100 Subject: [PATCH 1/3] Add conformsTo to FeatureCollection --- cityjson2jsonfg/convert.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cityjson2jsonfg/convert.py b/cityjson2jsonfg/convert.py index 909d913..479542c 100644 --- a/cityjson2jsonfg/convert.py +++ b/cityjson2jsonfg/convert.py @@ -46,6 +46,7 @@ def to_jsonfg_collection(cm): collection = { "type": "FeatureCollection", + "conformsTo": [ "[ogc-json-fg-1-0.2:core]", "[ogc-json-fg-1-0.2:3d]" ], "features": [], "coordRefSys": None, # CityJSON:metadata:referenceSystem "links": [ From 2fe38a59c75f0f99030a29ecfd7acce726489fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Dukai?= Date: Fri, 8 Mar 2024 16:27:46 +0100 Subject: [PATCH 2/3] Remove links from FeatureCollection and Feature --- cityjson2jsonfg/convert.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/cityjson2jsonfg/convert.py b/cityjson2jsonfg/convert.py index 479542c..18ee7d8 100644 --- a/cityjson2jsonfg/convert.py +++ b/cityjson2jsonfg/convert.py @@ -31,32 +31,11 @@ def to_jsonfg_str(collection): def to_jsonfg_collection(cm): - link_geojson_collection = { - "href": "https://geojson.org/schema/FeatureCollection.json", - "rel": "describedby", - "type": "application/schema+json", - "title": "JSON Schema of GeoJSON FeatureCollection" - } - link_geojson_feature = { - "href": "https://geojson.org/schema/Feature.json", - "rel": "describedby", - "type": "application/schema+json", - "title": "JSON Schema of GeoJSON Feature" - } - collection = { "type": "FeatureCollection", "conformsTo": [ "[ogc-json-fg-1-0.2:core]", "[ogc-json-fg-1-0.2:3d]" ], "features": [], "coordRefSys": None, # CityJSON:metadata:referenceSystem - "links": [ - { - "href": "https://beta.schemas.opengis.net/json-fg/featurecollection.json", - "rel": "describedby", - "type": "application/schema+json", - "title": "JSON Schema of JSON-FG FeatureCollection" - }, - ] } feature_template = { @@ -67,19 +46,10 @@ def to_jsonfg_collection(cm): "properties": None, # CityObject:attributes "geometry": None, # CityObject:geometry if it has 2.5D representation "place": None, # CityObject:geometry mapped - "links": [ - { - "href": "https://beta.schemas.opengis.net/json-fg/feature.json", - "rel": "describedby", - "type": "application/schema+json", - "title": "JSON Schema of JSON-FG Feature" - }, - ] } # Convert CityObject --> Feature geomdim = set() - geojson_added = False feature_time = cm.j.get("metadata", {}).get("referenceDate", None) for coid, co in cm.cityobjects.items(): feature = deepcopy(feature_template) @@ -88,17 +58,11 @@ def to_jsonfg_collection(cm): feature["time"] = {"date": feature_time} if feature_time is not None else None feature["properties"] = co.attributes convert_boundaries(cm, co, feature, geomdim) - if feature["geometry"] is not None: - # A GeoJSON geometry was added by convert_boundaries so we add the schema - feature["links"].append(link_geojson_feature) - geojson_added = True collection["features"].append(feature) # Convert CitJSON --> FeatureCollection collection["coordRefSys"] = cm.j.get("metadata", {}).get("referenceSystem", None) collection["geometryDimension"] = geomdim.pop() if len(geomdim) == 1 else None - if geojson_added: - collection["links"].append(link_geojson_collection) return collection From 324acba69f57b17b16b24dfba3406646daa43593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Dukai?= Date: Fri, 8 Mar 2024 18:08:50 +0100 Subject: [PATCH 3/3] Add conversion script --- .gitignore | 3 +- README.md | 2 +- README_DATA.txt | 67 +++++++++++++++++++ justfile | 62 +++++++++++++++++ pyproject.toml | 4 +- .../cityjson2jsonfg}/__init__.py | 0 .../cityjson2jsonfg}/cli.py | 0 .../cityjson2jsonfg}/convert.py | 0 8 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 README_DATA.txt create mode 100644 justfile rename {cityjson2jsonfg => src/cityjson2jsonfg}/__init__.py (100%) rename {cityjson2jsonfg => src/cityjson2jsonfg}/cli.py (100%) rename {cityjson2jsonfg => src/cityjson2jsonfg}/convert.py (100%) diff --git a/.gitignore b/.gitignore index f654f36..3476183 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .run .tox *.egg-info -tests/data/tmp/*.json \ No newline at end of file +tests/data/tmp/*.json +data \ No newline at end of file diff --git a/README.md b/README.md index af4a885..d29a373 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ CityJSON is a JSON-based encoding for storing 3D city models, also called digita Supported versions: - CityJSON: 1.1 -- JSON-FG: 0.1 +- JSON-FG: 0.2.2 ## Installation diff --git a/README_DATA.txt b/README_DATA.txt new file mode 100644 index 0000000..9ea50fc --- /dev/null +++ b/README_DATA.txt @@ -0,0 +1,67 @@ +====== +README +====== + +3D BAG data converted from CityJSON to JSON-FG with cityjson2jsonfg. + +CityJSON (v1.1): https://cityjson.org +JSON-FG (v0.2.2): https://github.com/opengeospatial/ogc-feat-geo-json + +Date: 2024-03-08 + +cityjson2jsonfg +--------------- + +A command line tool for converting CityJSON files to JSON-FG format. + +https://github.com/3DGI/cityjson2jsonfg + +Author +------ + +The conversion was done by 3DGI (https://3dgi.nl) with the funding from Geonovum (https://www.geonovum.nl/) + +Contents +======== + +jsonfg/: JSON-FG files +source/: CityJSON files + +3D BAG (in 3dbag/source/) +------------------------- + +The 3D BAG is an up-to-date data set containing 3D building models of the Netherlands. The 3D BAG is open data. It contains 3D models at multiple levels of detail, which are generated by combining two open data sets: the building data from the BAG and the height data from the AHN. + +https://3dbag.nl + +Download: https://3dbag.nl/en/download + +License: The 3D BAG by 3D geoinformation research group is licensed under CC BY 4.0, https://docs.3dbag.nl/en/copyright + +3D BAG (in 3dbag/jsonfg/) +------------------------ + +3D BAG data converted from CityJSON to JSON-FG format. + +License: The converted 3D BAG data in JSON-FG format by 3DGI is licensed under CC BY 4.0, https://creativecommons.org/licenses/by/4.0/ + +3D Basisvoorziening (in 3dbasisvoorziening/source/) +--------------------------------------------------- + +The 3D Basisvoorziening is a digital topograpic data set of 3D objects of the Netherlands. It is generated from the Dutch Large Scale Topographic Map (BGT), aerial images and the Dutch National Height Model (AHN). + +https://www.pdok.nl/3D%20Basisvoorziening + +Download: https://3d.kadaster.nl/basisvoorziening-3d/ + +Metadata: https://www.nationaalgeoregister.nl/geonetwork/srv/dut/catalog.search?node=geonetwork#/metadata/2fdeecd0-3d28-43f9-894e-e8444fdffeb3?tab=general + +License: The 3D Basisvoorziening is licensed by the Dutch Kadaster under CC BY 4.0, https://creativecommons.org/licenses/by/4.0/deed.nl + + +3D Basisvoorziening (in 3dbasisvoorziening/jsonfg/) +--------------------------------------------------- + +3D Basisvoorziening data converted from CityJSON to JSON-FG format. + +License: The converted 3D Basisvoorziening data in JSON-FG format is licensed by 3DGI under CC BY 4.0, https://creativecommons.org/licenses/by/4.0/deed.nl diff --git a/justfile b/justfile new file mode 100644 index 0000000..48d93d3 --- /dev/null +++ b/justfile @@ -0,0 +1,62 @@ +datadir := "data" + +prepare: + mkdir -p {{datadir}}"/3dbag/source" + mkdir -p {{datadir}}"/3dbag/jsonfg" + mkdir -p {{datadir}}"/3dbasisvoorziening/source" + mkdir -p {{datadir}}"/3dbasisvoorziening/jsonfg" + +# Download data from the 3DBAG +download-3dbag: prepare + #!/usr/bin/env bash + set -euxo pipefail + version="v20231008" + tiles=("10-260-584" "10-262-584" "10-262-586" "10-260-586") + download_url="https://data.3dbag.nl/"$version"/tiles" + for tile_id in "${tiles[@]}" ; + do + tile_path=${tile_id//[-]//} + tile_filename=$tile_id".city.json.gz" + wget $download_url"/"$tile_path"/"$tile_filename -O {{datadir}}"/3dbag/source/"$tile_filename + gunzip {{datadir}}"/3dbag/source/"$tile_filename + done + wget "https://data.3dbag.nl/"$version"/metadata.json" -O {{datadir}}"/3dbag/source/metadata.json" + +# Download data from the 3D Basivoorziening +download-3dbasisvoorziening: prepare + #!/usr/bin/env bash + set -euxo pipefail + version="2020" + tiles=( "30gz1" ) + download_url="https://download.pdok.nl/kadaster/basisvoorziening-3d/v1_0//"$version"/volledig" + for tile_id in "${tiles[@]}" ; + do + tile_filename=$tile_id"_"$version"_volledig.zip" + wget $download_url"/"$tile_filename -O {{datadir}}"/3dbasisvoorziening/source/"$tile_filename + unzip {{datadir}}"/3dbasisvoorziening/source/"$tile_filename -d {{datadir}}"/3dbasisvoorziening/source" + rm {{datadir}}"/3dbasisvoorziening/source/"$tile_filename + done + +# Download sample data from the 3DBAG and 3D Basisvoorziening +download: download-3dbag download-3dbasisvoorziening + +# Convert the downloaded CityJSON files to JSON-FG +convert-3dbag: + #!/usr/bin/env bash + set -euxo pipefail + parallel "cityjson2jsonfg {} {{datadir}}/3dbag/jsonfg/{/.}.fg.json" ::: {{datadir}}/3dbag/source/*.city.json + +convert-3dbasisvoorziening: + #!/usr/bin/env bash + set -euxo pipefail + parallel --jobs 1 "cjio --suppress_msg {} upgrade save stdout | cityjson2jsonfg - {{datadir}}/3dbasisvoorziening/jsonfg/{/.}.fg.json" ::: {{datadir}}/3dbasisvoorziening/source/*.json + +convert: convert-3dbag convert-3dbasisvoorziening + +upload: + rsync {{datadir}}/* 3dgi-server:/var/www/3dgi-data/jsonfg/ + rsync README_DATA.txt 3dgi-server:/var/www/3dgi-data/jsonfg/README.txt + +# Remove all downloaded and converted files +clean: + rm -rf {{datadir}} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index eaea73b..1409613 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "cityjson2jsonfg" -version = "1.1" +version = "1.2" description = "Convert CityJSON files to JSON-FG format" readme = "README.md" requires-python = ">=3.8" @@ -19,7 +19,7 @@ classifiers = [ ] urls = { github = "https://github.com/3DGI/cityjson2jsonfg" } dependencies = [ - "cjio>=0.7.5", + "cjio==0.8.2", "click>=8.1", "pyproj>=3.1" ] diff --git a/cityjson2jsonfg/__init__.py b/src/cityjson2jsonfg/__init__.py similarity index 100% rename from cityjson2jsonfg/__init__.py rename to src/cityjson2jsonfg/__init__.py diff --git a/cityjson2jsonfg/cli.py b/src/cityjson2jsonfg/cli.py similarity index 100% rename from cityjson2jsonfg/cli.py rename to src/cityjson2jsonfg/cli.py diff --git a/cityjson2jsonfg/convert.py b/src/cityjson2jsonfg/convert.py similarity index 100% rename from cityjson2jsonfg/convert.py rename to src/cityjson2jsonfg/convert.py