Skip to content

Commit

Permalink
update(exporters.geojson/geojson2): re-implement exporters.geojson as…
Browse files Browse the repository at this point in the history
… exporters.geojson2 using GeoJSONWriter and ParallelWriter
  • Loading branch information
ozekik committed Sep 14, 2024
1 parent 2529b3a commit 90615be
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 54 deletions.
76 changes: 53 additions & 23 deletions plateaukit/cli/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import click

from plateaukit import exporters
from plateaukit.cli.base import cli
from plateaukit.core.dataset import load_dataset
from plateaukit.exporters.cityjson.parallel_writer import ParallelWriter
from plateaukit.exporters.cityjson.writer import CityJSONWriter
from plateaukit.exporters.geojson2.writer import GeoJSONWriter
from plateaukit.exporters.parallel_writer import ParallelWriter
from plateaukit.logger import set_log_level
from plateaukit.readers.citygml.reader import CityGMLReader
from plateaukit.transformers.filter_lod import LODFilteringTransformer
Expand Down Expand Up @@ -141,26 +141,6 @@ def export_cityjson_cmd(
# )


def _export_geojson(
infiles, outfile, dataset_id: str, types: list[str], seq: bool, split: int, **kwargs
):
"""Export GeoJSON from PLATEAU datasets."""

if not infiles and not dataset_id:
raise click.UsageError("Missing argument: infiles or dataset")

if infiles and dataset_id:
raise click.UsageError("Too many arguments")

if dataset_id:
dataset = load_dataset(dataset_id)
dataset.to_geojson(outfile, types=types, seq=seq, split=split, **kwargs)
else:
exporters.geojson.geojson_from_citygml(
infiles, outfile, types=types, seq=seq, split=split, **kwargs
)


# @click.command("generate-geojson")
@cli.command(name="export-geojson", aliases=["generate-geojson"])
@click.argument("infiles", nargs=-1)
Expand All @@ -179,6 +159,10 @@ def _export_geojson(
)
@click.option("--seq", is_flag=True, default=False, help="Export GeoJSONSeq")
@click.option("--split", default=1)
@click.option("--altitude", is_flag=True, default=True, help="Include altitude")
@click.option(
"--target-epsg", default=None, help="EPSG code for the output GeoJSON file"
)
@click.option("-v", "verbose", count=True, default=0, help="Verbose")
def export_geojson_cmd(
infiles,
Expand All @@ -187,6 +171,8 @@ def export_geojson_cmd(
types: list[str],
seq: bool,
split: int,
altitude: bool,
target_epsg: int,
verbose: int,
):
"""Export GeoJSON from PLATEAU datasets.
Expand All @@ -197,7 +183,51 @@ def export_geojson_cmd(
if verbose >= 2:
set_log_level("DEBUG")

_export_geojson(infiles, outfile, dataset_id, types=types, seq=seq, split=split)
# _export_geojson(infiles, outfile, dataset_id, types=types, seq=seq, split=split)

if not infiles and not dataset_id:
raise click.UsageError("Missing argument: infiles or dataset")

if infiles and dataset_id:
raise click.UsageError("Too many arguments")

if dataset_id:
dataset = load_dataset(dataset_id)
dataset.to_geojson(
outfile,
altitude=altitude,
target_epsg=target_epsg,
types=types,
seq=seq,
split=split,
)
else:
reader = CityGMLReader()
readable = reader.scan_files(
infiles,
codelist_infiles=None,
# codelist_infiles=codelist_infiles, # TODO: Fix this
# zipfile=file_path, # TODO: Fix this
)

# TODO: Fix typing
transformers: list = []

if target_epsg:
transformers.append(ReprojectionTransformer(target_epsg=target_epsg))

for transformer in transformers:
readable = transformer.transform(readable)

parallel_writer = ParallelWriter(GeoJSONWriter)
parallel_writer.transform(
readable, str(outfile), seq=seq, split=split, altitude=altitude
)

# NOTE: Old implementation
# exporters.geojson.geojson_from_citygml(
# infiles, outfile, types=types, seq=seq, split=split, **kwargs
# )


@click.command("export-qmesh")
Expand Down
31 changes: 24 additions & 7 deletions plateaukit/core/dataset/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,21 @@ def to_geojson(
self,
outfile: str | PathLike,
*,
types: list[str] = ["bldg"],
altitude: bool = True,
include_type: bool = False,
seq=False,
types: list[str] = ["bldg"],
object_types=None, # TODO: Handle this
include_object_type: bool = True,
ground: bool = False,
seq: bool = False,
split: int = 1,
**kwargs,
selection: list[str] | None = None,
target_epsg: int | None = None,
progress_messages: dict | None = None,
# types: list[str] = ["bldg"],
# altitude: bool = True,
# include_type: bool = False,
# seq=False,
# split: int = 1,
):
"""Export GeoJSON from PLATEAU datasets.
Expand All @@ -211,12 +220,20 @@ def to_geojson(
return to_geojson(
self,
outfile,
types=types,
altitude=altitude,
include_type=include_type,
types=types,
object_types=object_types,
include_object_type=include_object_type,
ground=ground,
seq=seq,
split=split,
**kwargs,
selection=selection,
target_epsg=target_epsg,
progress_messages=progress_messages,
# altitude=altitude,
# include_type=include_type,
# seq=seq,
# split=split,
)

def to_cityjson(
Expand Down
2 changes: 1 addition & 1 deletion plateaukit/core/dataset/_to_cityjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import Literal

from plateaukit.config import Config
from plateaukit.exporters.cityjson.parallel_writer import ParallelWriter
from plateaukit.exporters.cityjson.writer import CityJSONWriter
from plateaukit.exporters.parallel_writer import ParallelWriter
from plateaukit.logger import logger
from plateaukit.readers.citygml.reader import CityGMLReader
from plateaukit.transformers.filter_lod import LODFilteringTransformer
Expand Down
Loading

0 comments on commit 90615be

Please sign in to comment.