question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.from_features does not retrieve feature 'id'

See original GitHub issue

Problem

geopandas: 0.6.1

The GeoJSON spec says a feature object can include an id property. Ref Section 3.3.3:

If a feature has a commonly used identifier, that identifier should be included as a member of the feature object with the name “id”.

However, when loading data into a GeoDataFrame using from_features, this data is not retrieved.

Example:

df = gpd.GeoDataFrame.from_features(
        {
            "type": "FeatureCollection",
            "features": [
                {
                    "id": "ST0",
                    "type": "Feature",
                    "properties": {
                        "atco_code": "300000492FZ",
                        "bearing": 8,
                        "feature_name": "Demand Responsive Area",
                        "type": "BCT",
                    },
                    "geometry": {
                        "type": "Point",
                        "coordinates": (-1.1372773238238423, 52.346655194010665),
                    },
                },
                {
                    "id": "ST1",
                    "type": "Feature",
                    "properties": {
                        "atco_code": "0600CR19133",
                        "bearing": 2,
                        "feature_name": "Station View (E-bound)",
                        "type": "BCT",
                    },
                    "geometry": {
                        "type": "Point",
                        "coordinates": (-2.518177475249135, 53.063122731640604),
                    },
                },
            ],
        }
    )

Output:

Out[8]: 
                    geometry    atco_code  bearing            feature_name type
0  POINT (-1.13728 52.34666)  300000492FZ        8  Demand Responsive Area  BCT
1  POINT (-2.51818 53.06312)  0600CR19133        2  Station View (E-bound)  BCT

Expected

The id property is returned as a column in the GeoDataFrame:

Out[10]: 
                    geometry    atco_code  bearing            feature_name type   id
0  POINT (-1.13728 52.34666)  300000492FZ        8  Demand Responsive Area  BCT  ST0
1  POINT (-2.51818 53.06312)  0600CR19133        2  Station View (E-bound)  BCT  ST1

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gregbrowndevcommented, Dec 3, 2019

Hi @jorisvandenbossche No problem at all!

Ah I see, that is a potential issue! I would be happy to help and contribute a pull request if a decision could be made on how to proceed.

How about having an additional function parameter to extract the ID? E.g.

def from_features(cls, features, crs=None, columns=None, use_feature_id=False):
    ...

This wouldn’t help making it work with all file formats but could provide an opt-in, best-try attempt.

0reactions
guibarcommented, Mar 17, 2021

I too would like the ‘id’ to get read by .from_features.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to find references to missing features during upgrade
My question is: how do I clean this up? "Select" from Features table based on these GUIDs does not return anything since these...
Read more >
OpenLayers can't get feature by key, undefined error
I stored every info I need under info key. I tried to get data in console and I can see that a point...
Read more >
How to get feature id for particular ... - GIS Stack Exchange
You just need to call for the feature id, the same way you would for the feature geometry: changed_polygon_id = ev.feature.id;.
Read more >
How to find a Feature ID in SharePoint using IE Developer ...
Feature Name Feature Definition Id Scope DocumentRoutingResources 0c8a9a47‑22a9‑4798‑82f1‑00e62a96006e Site PublishingPrerequisites a392da98‑270b‑4e85‑9769‑04c0fde267aa Site HelpCollectionRemoveDefault 232b3f94‑9d6e‑4ed6‑8d55‑04d5a44ac449 Site
Read more >
How to group features based on ID in gff - Biostars
So what I want to do is remove IDs from features with the same IDs and create a parent feature that appears before...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found