gisgeotoolsosgeo

GeoTools: How to build a point? (imports issue)


I'm following the GeoTools documentation and found this:

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
Coordinate coord = new Coordinate(45, 15);
Point point = geometryFactory.createPoint(coord);

When I put it in intellij IDE, for each class there are several suggested imports to use. What import I need to select?

Alternative way (with same issue) is:

GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
Point point = builder.createPoint(45, 15);

Solution

  • When in doubt you can always read the documentation, for example JTSFactoryFinder returns a com.vividsolutions.jts.geom.GeometryFactory, once you know that the other pieces fall into place as:

    import com.vividsolutions.jts.geom.Coordinate;
    import com.vividsolutions.jts.geom.GeometryFactory;
    import com.vividsolutions.jts.geom.Point;
    

    Meanwhile your GeometryBuilder is an org.geotools.geometry.GeometryBuilder which leads to the following imports:

    import org.geotools.geometry.GeometryBuilder;
    import org.geotools.referencing.crs.DefaultGeographicCRS;
    import org.opengis.geometry.primitive.Point;