Search code examples
openlayersgeojson

how to read features out of a geojson format


I have the below posted geojson. I want to read the feature out of that geojson so i can do some processing on that feature. please let me know how to read features out of a geojson format

code:

{'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [10.915212708803605, 50.70360315580079]}, 'properties': {'isRepresentative': 'y', 'hasPixelValueSatisfyThreshold': 'y'}}]}

Solution

  • This official example should help you, https://openlayers.org/en/latest/examples/geojson.html

    import GeoJSON from 'ol/format/GeoJSON';
    
    const geojsonObject = {'type': 'FeatureCollection', 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [10.915212708803605, 50.70360315580079]}, 'properties': {'isRepresentative': 'y', 'hasPixelValueSatisfyThreshold': 'y'}}]};
    const features = new GeoJSON().readFeatures(geojsonObject),