Skip to content

Commit

Permalink
Merge pull request #2 from 3DGI/json-fg-0.2.2
Browse files Browse the repository at this point in the history
Json fg 0.2.2
  • Loading branch information
balazsdukai authored Mar 8, 2024
2 parents 777e254 + 324acba commit 569579c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.run
.tox
*.egg-info
tests/data/tmp/*.json
tests/data/tmp/*.json
data
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
67 changes: 67 additions & 0 deletions README_DATA.txt
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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}}
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
]
Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 1 addition & 36 deletions cityjson2jsonfg/convert.py → src/cityjson2jsonfg/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +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 = {
Expand All @@ -66,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)
Expand All @@ -87,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

Expand Down

0 comments on commit 569579c

Please sign in to comment.