I m new to geotools and i find bit difficult to plot a point using the latitude and longitude values. can any one heple me out to solve my problem.

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory():
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE); 
Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude));

but this code is not working properly. could any one explain why..?

1 Answer 1


In your code, you miss to define a feature type: In GeoTools (and not only), you will first need to define the structure of your data, ie the Feature type (~ schema). For this you have to use SimpleFeatureTypeBuilder that will help to build the feature type, afterwhat you will be able to construct properly the SimpleFeatureBuilder based on the featuretype you defined before (the TYPE argument in your code)

Create the Simple Feature Type (structure of your data):

SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();

//set the name
b.setName( "MyFeatureType" );

//add a geometry property
b.setCRS( DefaultGeographicCRS.WGS84 ); // set crs first
b.add( "location", Point.class ); // then add geometry

//build the type
final SimpleFeatureType TYPE = b.buildFeatureType();

Create the feature(s) using the feature type previously defined

SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
SimpleFeature feature = featureBuilder.buildFeature( "fid.1" ); // build the 1st feature

Next step, you can create a feature collection, using the feature(s) you defined before:

DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal",TYPE);
featureCollection.add(feature); //Add feature 1
// Add feature 2, 3, etc

I recommend you to follow examples from http://docs.geotools.org/latest/userguide/library/main This will also help to understand how geospatial data is structured in Geotools

For the plotting part, i suggest you to familiarize with the geotools rendering module: http://docs.geotools.org/latest/userguide/library/render/map.html.

  • Could u be more specific. since i am new to geotools i don't know what is TYPE. for creating a point can u give me a clear coding..?? Commented Sep 22, 2014 at 7:21
  • 1
    I've added few code to explain you the 1st step you need to follow that is to define the structure of your data, named FeatureType. The SimpleFeatureBuilder will use the featureType you defined, afterwhat you can create each of the features you need. I highly recommend you to look more to the geotools documentation which provides good examples, also for rendering/ploting the data once is prepared.
    – eblondel
    Commented Sep 22, 2014 at 7:41
  • i tried your code. i am getting error on this line.. SimpleFeatureType TYPE = b.buildFeatureType(); Commented Sep 22, 2014 at 9:07
  • but i am clear with your explanation. Commented Sep 22, 2014 at 9:08
  • my apologies, they were some typos in the code i've sent. Now you can check it works!
    – eblondel
    Commented Sep 22, 2014 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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