0

I am having trouble creating geotools buffers around objects (lines), all objects seem crooked, I think it happens because the difference in CRSs is very noticable on buffers. I figuered out I probably need to set CRS that my app is using, i want it to be EPSG:4326 but i cant get my head on how i can do it.


Reading geotools guide i've seen examples on how to do it knowing the CRS used before via transform but i can only get SRID code and not the CRS. Any help is apreciated


In the code shown below I im trying to constuct buffer over a line and get coordinates of the buffer on the different radiuses. It works just fine, but seems realy uneven on the map. I also tried creating geometry factory specifying SRID assuming the int code would be the same as in CRS, there is no difference in displaying coordinates in different factories whatsoever

GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
GeometryFactory factory = JTSFactoryFinder.getGeometryFactory();
LineString lineString = geometryFactory.createLineString(mapCoords(pipeline));
for (double radius : radiuses){
            Coordinate[] coordinates = lineString.buffer(radius).getCoordinates();
            List<Point> points = mapPoints(coordinates);
            radiusesPoints.add(points);
    }
  • We need to see the code you are using? how are you creating your features? What projection are they in - buffers don't really work with geographic CRS like 4326. – Ian Turton Apr 15 '21 at 07:18
  • @IanTurton I added the code I am using to the question, tell me if you need to se more, Also map methods in the code needed to convert geotools coordinates to localy created class - point (which are pacticaly the same, but with minimized functionality only for 2D) – agingcabbage32 Apr 15 '21 at 07:38
  • we need to see the output of `mapCoords(pipeline)` to see what is actually happening - but this won't work as JTS doesn't make any use of the SRID you add to the factory. – Ian Turton Apr 15 '21 at 07:40
  • 1
    Does this answer your question? [Generate a polygon from a line(GPS coordinate) in a defined distance(km) with geotools in JAVA](https://stackoverflow.com/questions/30426901/generate-a-polygon-from-a-linegps-coordinate-in-a-defined-distancekm-with-ge) – Ian Turton Apr 15 '21 at 07:44
  • @IanTurton the answer in "Generate a polygon..." question seems just what i need, but is there a way to convert a Geometry object to Feature object? since getDefaultGeometryProperty() is available only on feature object – agingcabbage32 Apr 15 '21 at 09:29
  • 1
    you can just use your geometry instead – Ian Turton Apr 15 '21 at 09:30
  • @IanTurton It seems like the last thing that doesn't let the app work is i cannot get coordinates of needed geometry, i can get coordinates of a centroid of a geometry, but can i somehow get the coordinates of geometry? – agingcabbage32 Apr 15 '21 at 12:49
  • `geomertry.getCoordinates()` returns an array of `Coordinates` – Ian Turton Apr 15 '21 at 13:25
  • @IanTurton I am sorry for bombing you with questions, but there is something wierd about the problem. 'geomertry.getCoordinates()' exists when I use Geometry class from com.vividsolutions.jts.geom, but then I cannot 'getCoordinateReferenceSystem()'. When I use 'org.geotools.geometry.' dependency its exactly on the contrary and I cannot use both methods on the one Geometry object. And they seems to be non castable. Meybe important thing is I use geotools version 14.0 and the project runs on java 1.7 – agingcabbage32 Apr 15 '21 at 14:07
  • JTS knows nothing about CRS so you can't but since you did a transform on the geometry you know what the CRS is. – Ian Turton Apr 15 '21 at 14:14

1 Answers1

0

So, as it was said in the comments, since there is no way to getCoordinates and getCoordinateReferenceSystem on the same object I used a workaround, which is basicly using postgresql fucntions to do the same thing, but on db request level. The task was solved a while ago, but if you would like to see a solution tag me in the comments and I'll find the db request for you