Search code examples
hibernateformatspatialgeojsongeotools

geojson coordinate conversion to the format of the data coming from PostgreSQL?


this is save to vector code :

 if (vectorType.equalsIgnoreCase("Point")) {
            Point point = new GeometryJSON().readPoint(item.getData());
            lineString.setSRID(3857);
            theEvent.setGeom(point);
            theEvent.setVectorType(vectorType);
        }

after I want to read data from the database format geojson but I need to do the shortcut

I did the following code :

   if(entity.getVectorType().trim().equalsIgnoreCase("Point"))
        {
            JSONObject point = new JSONObject();
            point.put("type", "Point");
            JSONArray coord = new JSONArray("["+entity.getGeom().getX()+","+entity.getGeom().getY()+"]");
            point.put("coordinates", coord);
            geoJson.setData(point.toString());                
        }

but I must do shortcut . how can I do. I think do with geotools. we can use FeatureJson but how ?


Solution

  • I did stackoverflow users solution as the following :

     if(entity.getVectorType().trim().equalsIgnoreCase("Point"))
            {
                GeometryJSON gjson = new GeometryJSON();
                Object obj = JSONValue.parse(gjson.toString(entity.getGeom()));
                System.out.println(obj);
            }
    

    Thank you.