2

I have table in PostGIS with lon, lat, distance and azimuth columns. I want to make Geoserver draw a line through first point with given length and direction. I can turn lon and lat to geometry in PostGIS with ST_MakePoint command.

Is it possible to draw line using only SLD with first point and attribute values or do I need to calculate second point manually and turn it to geometry too?

  • SLD is exclusively for styling, so you will need to make the other point, yes. – John Powell Jun 22 '15 at 9:18
  • Thank you for the answer. I've got an idea that SLD can do something like this. May be, there is some code, that can draw line with length, depending on attrubute value. – Andrew Jun 24 '15 at 7:38
3

Use the GeoServer SQL view feature, and SQL's ST_Project like,

SELECT id, 
  ST_SetSRID(ST_MakeLine(
    ST_MakePoint(lon,lat),
    ST_Project(
       ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, 
       distance, 
       pi()*azimuth/180.0)::geometry
  ),4326) AS geom
FROM mytable;

If you have long lines and want to plot them as great circles on a flat map, you might want to densify them with ST_Segmentize in geographic space to show them as great circles.

SELECT id, 
  ST_Segmentize(ST_SetSRID(ST_MakeLine(
    ST_MakePoint(lon,lat),
    ST_Project(
       ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, 
       distance, 
       pi()*azimuth/180.0)::geometry
  ),4326)::geography,100000)::geometry AS geom
FROM mytable;

Added

SELECT id, 
  ST_SetSRID(ST_MakeLine(
    ST_SetSRID(ST_MakePoint(lon,lat),4326),
    ST_Project(
       ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, 
       distance, 
       pi()*azimuth/180.0)::geometry
  ),4326) AS geom
FROM mytable
  • thank you very much, this is exactly what I need. I've added to your answer my version of SQL statement that work for me. – Andrew Jun 24 '15 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.