So I managed to get a point to show up at the center of my line, I'm hoping to convert the point into an arrow pointing in the direction of my line

public static final SimpleFeatureType POINT = createPointType(); 
public static final SimpleFeatureType LINE = createSolidLine(); 

private static SimpleFeature directedPoint(){
    Coordinate start = CoordConverterUtils.getStart; 
    Coordinate end = CoordConverterUtils.getEnd;

    Coordinate mid = (new LineSegment(start,end)).midpoint()); 

    GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
    SimpleFeatureBuilder fb = new SimpleFeatureBuilder(DIRECTED_POINT);
    Point p = gf.createPoint(mid); 
    return fb.buildFeature(null); 

private static SimpleFeatureType createPointType(){
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.add("the_geom", Point.class);
        return builder.buildFeatureType(); 
    catch(Exception e){
        return null; 

Is it possible to convert the Point into a SymbolizedPoint that's an arrow pointing in the direction of LINE - and return it as a SimpleFeature ?
Every time I've tried to make a symbolized point I can't seem to translate the midpoint into its geometry.

  • 1
    how are you visualizing your line/point? the Style you are using is the important part – Ian Turton Feb 27 '20 at 14:28
  • @IanTurton I'm outputting simplefeatures to .shp files and manually opening them on the geotools viewer. – cat_bug Feb 27 '20 at 14:45

You are confusing Features, Geometries and Rendered maps.

In GeoTools Features are objects that contain a Geometry (a Point, Line or Polygon) and other (optional) attributes that describe the real world object being described by the feature.

You want a styled representation of that feature, this is done by providing a Style object to the Renderer that will then take each feature in turn and draw it according to the rules in the style. The style is often serialised as SLD for storage and reloading it.

So to add an arrow at the mid-point of your line you could use something like the SLD provided in this question but based on the midpoint, which you should be able to get using the pointN function. I don't think there is anyway to extract the angle of the line at point in a line (since the line could change direction at a point, it is not obvious what it should be) you might want to calculate it while calculating the point and store it as an attribute of your feature.

  • Can you avoid using SLD with code similar to your solution for stackoverflow.com/questions/45235244/… Is there no way to apply style/rules to a SimpleFeature and pass that SimpleFeature along ? (sorry if the question is redundant - trying to figure this out) The LINE has all the information I need in terms of angle/start/end. – cat_bug Feb 27 '20 at 15:38
  • 1
    You can, of course, make the style programmatically but it will be separate to the feature. The idea being one style can apply to all the features. – Ian Turton Feb 27 '20 at 15:55
  • Ah, because I'm outputting .shp files, I think I need to figure out at what step to apply a style/ rule when converting SimpleFeatures -> .shp. There's no renderer in my project since I'm manually opening the files to view them. – cat_bug Feb 27 '20 at 16:15
  • 1
    You must be rendering them with something (unless you just admire the binary digits by holding them up to the light) – Ian Turton Feb 27 '20 at 16:22
  • 1
    in that question I have added the code shown to the viewer to add the style - you could try providing an SLD file with the same basename as the shapefile - I suspect the basic viewer will pull that in automatically – Ian Turton Feb 27 '20 at 16:48

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.