How to read geoJson in Java and separate its attribute

Viewed 11

How to read geoJson in Java and separate its attribute.

I want to read geoJson and I want read its property and geometry with common Id and put in Map.

I am able to read file only.

Here is my code

public void getGeoData(){


    File myObj = new File("/GeoJSON/my.geojson");
            Scanner myReader = new Scanner(myObj);
            while (myReader.hasNextLine()) {
                String data = myReader.nextLine();
                log.info("Inline datax"+ data);
            }
            myReader.close();
    
}

This is reading the data and printing it.

{
    "type": "FeatureCollection",
    "name": "State",
    "features": [
    
    
    { "type": "Feature", "properties": { "State_Name": "Florida", "State_Code": "01" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 0,0 ],[ 0,1] ] ] } },
    
    
    { "type": "Feature", "properties": { "State_Name": "Texas", "State_Code": "02" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 1,2 ],  [ 2,3 ] ] ] } },
    
    
    
    ]
    }

O/p shoyld be like this:

 [{
        "State_Name": "Florida", "State_Code": "01", "geometry": { "type": "Polygon", "coordinates": [ [ [ 0,0 ],  [ 0, 1 ] ] ] }
    },{
        "State_Name": "Florida", "State_Code": "01", "geometry": { "type": "Polygon", "coordinates": [ [ [ 1,2 ],  [ 2,3 ] ] ] }
    }]
0 Answers
Related