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

Line Features pick #2701

Open
reservoi opened this issue Feb 6, 2025 · 4 comments
Open

Line Features pick #2701

reservoi opened this issue Feb 6, 2025 · 4 comments
Labels
support Support questions

Comments

@reservoi
Copy link

reservoi commented Feb 6, 2025

Hello everyone!
I'm trying to implement a pointer function that allows the user to pick features from the map.
Here is how it looks like:

osgEarth::ObjectIDPicker::Function pick = [&](osgEarth::ObjectID id) 
{
    if(id > 0)
    {
        // Got a pick:
        osgEarth::FeatureIndex* index =
            osgEarth::Registry::objectIndex()->get<osgEarth::FeatureIndex>(id).get();
        osgEarth::Feature* feature = index ? index->getFeature(id) : 0L;

        if(feature != nullptr)
        {
            osgEarth::Geometry* featureGeometry = feature->getGeometry();

            if (featureGeometry->getType() == osgEarth::Geometry::TYPE_POINT)
            {
                // DO SOME THINGS
            }
            else if (featureGeometry->getType() == osgEarth::Geometry::TYPE_LINESTRING)
            {
                // DO SOME THINGS
            }
        }
    
    }
}

Now, this code works perfectly fine for Point Features but it doesn't for Line Features.
In particular, the pick function is called while hovering a custom map cursor over a feature.

With Point Features, I can correctly retrieve the ObjectID for the feature while with Line Features, the ObjectID that gets retrieved is always equal to 0, meaning that the feature is not recognized.

Would anyone have a solution for this or any hint that could possibly put me on the right track?

Thank you very much.
Best Regards

@gwaldron
Copy link
Owner

gwaldron commented Feb 6, 2025

Don't forget the answer the questions in the Issue Template.
What version of osgEarth?
Are you loading your features from an earth tile? If so are you marking the layer as pickable?
If it's in code, are you tagging your drawables to register them with the object index?
Do you have an earth file or standalone piece of code we could use to try and reproduce the problem?

@reservoi
Copy link
Author

reservoi commented Feb 7, 2025

Hi!
I'm using osgEarth 3.5.0 build 149.
I'm loading my feature inside the .earth file and inside the FeatureModel section I have the following line to index the feature:
<feature_indexing enabled="true" />

While inside the OGR Feature definition I have the following line to enable pickability:
< pickable > true < / pickable>

Nevertheless, I'm not tagging my drawables, what is that about?

I'm applying the feature through a shapefile that contains different segments, each segment has a unique attribute called segment_id.

Thank you again for the support.

@gwaldron
Copy link
Owner

gwaldron commented Feb 7, 2025

<pickable>true</pickable> is just a synonym for <feature_indexing enabled="true"/> so you are in good shape there. (Either way, it goes on the FeatureModel layer itself, not the OGR feautre source.)

Since you're using an earth file, there is no tagging required; that's an API thing.

You may need to tell osgEarth that you want your segment_id attribute to be used as a feature ID:

<OGRFeatures>
    <fid_attribute>segment_id</fid_attribute>
    ....

@gwaldron gwaldron added the support Support questions label Feb 18, 2025
@fcdalgic
Copy link

You probably forget to register the geometry in objectid pool before trying to pick (i did it also), otherwise it would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Support questions
Projects
None yet
Development

No branches or pull requests

3 participants