cityjson / cjio

CityJSON/io: Python CLI to process and manipulate CityJSON files
MIT License
126 stars 32 forks source link

Subset operation fails when used on a filtered file #183

Open AkshayPatil1994 opened 7 months ago

AkshayPatil1994 commented 7 months ago

cjio <myfile> subset --radius <sx> <sy> <radius> save <outfile>

The above command returns an empty file when is obtained from

cjio <oldfile> lod_filter 2.2 save <myfile>

However, if I use the original file containing the entire dataset and then use the subset operation it returns the right result. A bit puzzeled as to why this is the case. I would have expected it to work eitherway, but perhaps I misunderstood something. Perhaps the right order of using cjio would be to

  1. Subset first (always)
  2. Then use the filter operation

What I used that returns empty data

  1. Filter for lod2.2
  2. Subset

cjio version cjio version 2.0

To Reproduce Steps detailed above

Expected behavior I was expecting that that since the subset operation yanks the chunk that is of interest it should have worked irrespective of the contents of the file. However, it seems that subset operations can only work on the original file with all the contents and do not work when a filtered file is used as shown above.

Screenshots NA

Desktop (please complete the following information):

Additional context NA

hugoledoux commented 7 months ago

It should work either way.

Can you provide the file, or a subset of it so that I can reproduce the bug? Is it the 3dbag?

AkshayPatil1994 commented 7 months ago

subset.city.json

This is the subset that breaks things when the order is not followed!

hugoledoux commented 7 months ago

okay so I can reproduce this bug with any 3dbag.nl files.

Both functions are okay and work, this is the good news.

The reason nothing is returned is that if you lod_filter "2.2" then the geometry having lod=0 which is in the parent Building gets removed, and the Building has no geometry itself, the geometries are in the BuildingPart which contains the lod=2.2

We decided a while ago that the subset operator should not include the parents of selected city objects (https://github.com/cityjson/cjio/blob/develop/cjio/subset.py#L8), only the children of the selected ones. This was to avoid adding the parents if one ID of a BuildingPart is selected for instance: we cannot add only the child since we would create invalid files (a CityObject having a parent must have its parent in the file), and we thought that including the parents was somehow not the behaviour we wanted.

But clearly your example breaks this, so I am not sure what we should do.

@balazsdukai any thoughts?

balazsdukai commented 6 months ago

In case of spatial subsets the whole hierarchy should be included for a CityObject. As you say Hugo, the risk is that we include dangling children in the output, because the parent object does not overlap the area of interest. I think we could resolve this by keeping an account of child-->parent in the output, and at the end remove all children that does not have a parent.