I have a complex problem. I'm using geotools 10.*

I have input data:

latitude, longitude (WGS_84), radius in meters, start angle (12 o'clock), end angle (clockwise, i.e. turn to the right). I need to display these data on Google Earth/map using KML format.

I have two problems:

  1. How to correctly convert meters to degrees?
  2. How to export to KML specifying colours,opacity for my objects?

Thanks to guys from nabble, they did help me to move forward. Here is code that does pretty the same what I need but now I have problem with correctly interpreting and displayng geometry objects. Here is the code:

private static Coordinate transformToPlanar(Coordinate source) throws FactoryException, TransformException{
    CoordinateReferenceSystem srcCRS = DefaultGeographicCRS.WGS84;
    CoordinateReferenceSystem destSRC = CRS.decode("EPSG:3576");//CRS.parseWKT(EPSG_3576_STR);
    boolean lenient = true; // allow for some error due to different datums
    MathTransform transform = CRS.findMathTransform(srcCRS, destSRC, lenient);
    return JTS.transform(source, null ,transform);

private static Geometry transformToGeo(Geometry source) throws FactoryException, TransformException{
    CoordinateReferenceSystem srcCRS = CRS.decode("EPSG:3576");
    CoordinateReferenceSystem destCRS = DefaultGeographicCRS.WGS84;
    boolean lenient = true; // allow for some error due to different datums
    MathTransform transform = CRS.findMathTransform(srcCRS, destCRS, lenient);
    return JTS.transform(source, transform);

public void drawRetailStoreMC7700001() throws ParserException, IOException, FactoryException, TransformException {
//read input data
    List<GSMCellLocation> gsmCellLocations = GeoDataSampleHelper.readGSMCellLocationFromMoscowRegion();
    RetailStore retailStore = GeoDataSampleHelper.readRetailStoreByCode(MC7700001);
    GeoPoint storeGeoPoint = retailStore.getStoreLocation().getGeoPoint();

    List<Geometry> geometryList = new LinkedList<Geometry>();

    GeometricShapeFactory gsFactory = new GeometricShapeFactory();
    gsFactory.setCentre(transformToPlanar(new Coordinate(storeGeoPoint.getLongitude(),
//a circle
    Geometry storeCircle = gsFactory.createEllipse();

//check intersection of the circle with each sector
    for(GSMCellLocation cellLoc : gsmCellLocations){
        gsFactory = new GeometricShapeFactory();
        gsFactory.setCentre(transformToPlanar(new Coordinate(cellLoc.getGeoPoint().getLongitude(),
        gsFactory.setSize(cellLoc.getMidDist() * 2);
        Geometry cellSector = gsFactory.createArc(toRadians(cellLoc.getStartAngle()),

    LOG.info("geometryList.size {}",geometryList.size());

//prepare for output
    Encoder encoder = new Encoder(new KMLConfiguration());

    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.add("geometry", Polygon.class, DefaultGeographicCRS.WGS84);//DefaultGeographicCRS.WGS84);

    SimpleFeatureType TYPE = typeBuilder.buildFeatureType();

    DefaultFeatureCollection features  = new DefaultFeatureCollection("test",TYPE);

    for(int i=0; i<geometryList.size(); i++){
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
        featureBuilder.add( transformToGeo(geometryList.get(i)));
        SimpleFeature simpleFeature = featureBuilder.buildFeature(String.valueOf(i + 1));
        features.add( simpleFeature );
    encoder.encode(features, KML.kml, System.out);


The good things: 1. The circle is displayed at right position on the Google earth

  1. Sectors doesn't look like sector http://en.wikipedia.org/wiki/Circular_sector

It looks like segment:


What do I do wrong?

  • 1
    Degrees is a unit for angles, Meters is a unit for length. – Mapperz Feb 13 '13 at 17:20
  • 1
    I do understand. As input I do get: latitude, longitude for the center of the sector (a piece of pie), then I do get radius of sector in meters and start/end angle of the sector. I need to combine all these values and output them to kml for visualization. What is wrong? – Sergey Feb 13 '13 at 17:24

I wrote a program to solve a similar problem some time ago.

Basically, the trick is to use the GeodeticCalculator to work out the coordinates of the curved section of the wedge and the join the start and end to the starting point.

ArrayList<Coordinate> coords = new ArrayList<>();
// start at the tower
// next the edge of the wedge
int nSteps = 10;
// assume width of 10 degrees
double width = 10.0;
double dStep = width/nSteps;
for (int i = -nSteps; i < nSteps; i++) {
  CALC.setStartingGeographicPoint(point.getX(), point.getY());
  CALC.setDirection((azimuth +(i*dStep)), radius);
  Point2D p = CALC.getDestinationGeographicPoint();
  coords.add(new Coordinate(p.getX(), p.getY()));
// end at the tower
poly = GF.createPolygon(coords.toArray(new Coordinate[] {}));

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.