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:
- How to correctly convert meters to degrees?
- 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 displaying 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
- 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?