Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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);
}    


@Test
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(),
                                                         storeGeoPoint.getLatitude())));
//a circle
    gsFactory.setSize(200);
    Geometry storeCircle = gsFactory.createEllipse();
    geometryList.add(storeCircle);

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

        if(cellSector.intersects(storeCircle)){
            geometryList.add(cellSector);
        }
    }
    LOG.info("geometryList.size {}",geometryList.size());

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

    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.setName("poi");
    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:

http://en.wikipedia.org/wiki/Circular_segment

What do I do wrong?

share|improve this question
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.