Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost Geometry and GOES::Geom conflict in Spatialindex #55

Open
ctieben opened this issue Sep 18, 2018 · 11 comments
Open

Boost Geometry and GOES::Geom conflict in Spatialindex #55

ctieben opened this issue Sep 18, 2018 · 11 comments
Assignees

Comments

@ctieben
Copy link
Contributor

ctieben commented Sep 18, 2018

Hi,

currently if you try to add a 2D Geometry to the core with an active SpatialIndex module you will receive following runtime error from the Boost rtree:
[ctest] sempr_spatial_conclusion_tests: /usr/include/boost/geometry/index/rtree.hpp:1445: void boost::geometry::index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator>::raw_insert(const value_type&) [with Value = std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> >, std::shared_ptr<sempr::entity::Geometry> >; Parameters = boost::geometry::index::quadratic<16ul>; IndexableGetter = boost::geometry::index::indexable<std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> >, std::shared_ptr<sempr::entity::Geometry> > >; EqualTo = boost::geometry::index::equal_to<std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> >, std::shared_ptr<sempr::entity::Geometry> > >; Allocator = std::allocator<std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> >, std::shared_ptr<sempr::entity::Geometry> > >; boost::geometry::index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator>::value_type = std::pair<boost::geometry::model::box<boost::geometry::model::point<double, 3ul, boost::geometry::cs::cartesian> >, std::shared_ptr<sempr::entity::Geometry> >]: Assertion(detail::is_valid(m_members.translator()(value)))&&("Indexable is invalid")' failed.
`

The reason for this is, that geos::geom coordinates stores X, Y, NaN for 2D coordinate and the boost rtree expect valid 3D points without a NaN value.

So how to handle 2D and 3D in the same context? ( set z to 0 instead of NaN)?

@niniemann
Copy link
Collaborator

So you say that findEnvelope(min, max) returns NaN in the min.zand max.z? This is something we can check for in the SpatialIndex, and overwrite it. No big deal.

The only real question is: What to overwrite it with? Project everything that is 2D into the x-y plane (i.e., set it to 0)? Or make the z value "arbitrary, everything matches", and thus set the bounds to +/- max double?

@ctieben
Copy link
Contributor Author

ctieben commented Sep 18, 2018

Yes also the findEnvelope method will set Z to NaN if there are no Z values to compare. So its comform with geos::geom.
I think the most correct way in the SpatialIndex for 2D surfaces is to set the max. possible height ( [- max double; + max double] ). If there is a 2D surface it will define a region and the height will not matter. Otherwise its possible to define a surface in 3D space with a specific height information.

@niniemann
Copy link
Collaborator

Yes, but in some cases this might be unintuitve: E.g. If you make a "contains"-query: Given some Volume, return everything that is contained in it. With the min/max values you won't get any 2D-geometries. But since it's basically 2D I'd expect it to be included in the results.

@ctieben
Copy link
Contributor Author

ctieben commented Sep 18, 2018

Mhhh yes even the contains query of one 2D surface to another will be different than expected in this case.
see: http://edndoc.esri.com/arcsde/9.1/general_topics/understand_spatial_relations.htm#Contains

@ctieben
Copy link
Contributor Author

ctieben commented Sep 18, 2018

This could be solved by query with min/max vales and storing 2d geometries with min-1 / max-1.
But its a bit hacky.

@niniemann
Copy link
Collaborator

I think in that case it is better to project all 2D geometries into the x-y plane, which is easily documented and understood.

@ctieben
Copy link
Contributor Author

ctieben commented Sep 19, 2018

As long as we are in a 3D space the within and contains query will not match even if we project the geometry to plane at a specific height (e.g. z=0) because the z coordinate will be checked for this condition.

@niniemann
Copy link
Collaborator

Yes. That's the point. Just document the fact that the index assumes 2D geometries to lie in the x-y plane, so if he wants to include them he needs to adjust his query accordingly.

The alternative would be to not add 2D-geometries to the index at all, and implement a 2D variation of it.

@ctieben
Copy link
Contributor Author

ctieben commented Oct 2, 2018

To fix this I have changed the SpatialIndex to contain only 2D or 3D elements. See: 796867f

@ctieben ctieben closed this as completed Oct 12, 2018
@niniemann
Copy link
Collaborator

(Shouldn't the issue only be closed when the branch you fixed this in is merged into master?)

@ctieben
Copy link
Contributor Author

ctieben commented Oct 12, 2018

(yes ok, I had seen this more like a discussion than as a fixing issue)

@ctieben ctieben reopened this Oct 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants