Google
Official Google Earth Download Site

Google Earth Community System Reliability: MEDIUM

Support and Answers >> KML Discussions (read only)

slopez
First Post


Reged: 02/21/06
Posts: 1
Re: KML Circle Generator - Java
      02/21/06 03:01 PM

package conversionToKML;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class KMLCircle {

void GenCircle(double centerlat_form, double centerlong_form, int num_points, double radius_form, String outputFile){
double lat1, long1, lat2, long2;
double dlat, dlong, d_rad;
double a, c, d;
double delta_pts;
double radial, lat_rad, dlon_rad, lon_rad;

double degreeToRadian = Math.PI/180.0;

// convert coordinates to radians
lat1 = Math.toRadians(centerlat_form);
long1 = Math.toRadians(centerlong_form);

//Earth measures
//Year Name a (meters) b (meters) 1/f Where Used
//1980 International 6,378,137 6,356,752 298.257 Worldwide
d = radius_form;
d_rad = d/6378137;

try{
File fileOutput = new File(outputFile);
BufferedWriter writer = new BufferedWriter(new FileWriter(fileOutput));

writer.write("<Document>\n<name>$Document</name>\n<Folder>\n<name>$Folder</name>\n<visibility>1</visibility>\n<Placemark>\n<name>$Circle_name</name>\n<visibility>$visibility</visibility>\n<Style>\n<geomColor>$geomColor1$geomColor2</geomColor>\n<geomScale>$geomScale</geomScale></Style>\n<LineString>\n<coordinates>\n");
//System.out.write(c);
//System.out.println(c);

// loop through the array and write path linestrings
for(int i=0; i<=num_points; i++) {
//delta_pts = 360/(double)num_points;
//radial = Math.toRadians((double)i*delta_pts);
radial = Math.toRadians((double)i);

//This algorithm is limited to distances such that dlon <pi/2
lat_rad = Math.asin(Math.sin(lat1)* Math.cos(d_rad) + Math.cos(lat1)* Math.sin(d_rad)* Math.cos(radial));
dlon_rad = Math.atan2(Math.sin(radial)* Math.sin(d_rad)* Math.cos(lat1), Math.cos(d_rad)- Math.sin(lat1)* Math.sin(lat_rad));
lon_rad = ((long1 + dlon_rad + Math.PI) % (2*Math.PI)) - Math.PI;

//write results
writer.write( Math.toDegrees(lon_rad) + ", ");
writer.write( Math.toDegrees(lat_rad) + ", 0");
writer.write('\n');
}
// output footer
writer.write("</coordinates>\n</LineString>\n</Placemark>\n</Folder>\n</Document>");

writer.close();
}catch (IOException e){
return;
}
}
/**
* @param args
*/
public static void main(String[] args) {
KMLCircle myCircle = new KMLCircle();
myCircle.GenCircle(37.422000, -122.084073, 360, 10000, "CircleTest.kml");
}

}

Post Extras Print Post   Remind Me!     Report this Post


Entire topic
Subject Posted by Posted on
* KML Circle Generator ink_polaroidAdministrator 04/19/05 04:17 PM
. * * Re: KML Circle Generator stebi61   09/19/06 12:18 AM
. * * Re: KML Circle Generator barryhunter   09/19/06 02:39 AM
. * * Re: KML Circle Generator stebi61   09/19/06 12:30 PM
. * * Re: KML Circle Generator ink_polaroidAdministrator   09/19/06 12:51 AM
. * * Re: KML Circle Generator svens   09/19/06 01:57 PM
. * * Re: KML Circle Generator: decimal Precision Eliot_Christian   04/17/06 11:25 AM
. * * Re: KML Circle Generator: Polygon vs LineString? Eliot_Christian   04/17/06 03:26 AM
. * * Re: KML Circle Generator - Java slopez   02/21/06 03:01 PM
. * * Re: KML Circle Generator rsgrillo   01/20/06 08:23 AM
. * * Re: KML Circle Generator HookEmHorns   01/19/06 12:44 PM
. * * Re: KML Circle Generator Lon   07/29/05 09:33 AM
. * * Re: KML Circle Generator mcshea98Moderator   07/29/05 09:59 AM
. * * Re: KML Circle Generator Lon   07/29/05 11:17 AM
. * * Re: KML Circle Generator Hulk   07/27/05 05:35 PM
. * * Re: KML Circle Generator gbonny   04/20/05 01:09 AM
. * * Re: KML Circle Generator mcshea98Moderator   04/23/05 04:09 PM
. * * Re: KML Circle Generator ink_polaroidAdministrator   04/24/05 05:19 PM
. * * Random thoughts blt   04/24/05 07:25 PM
. * * Re: Random thoughts ink_polaroidAdministrator   04/24/05 08:24 PM
. * * Re: Random thoughts ink_polaroidAdministrator   04/24/05 09:13 PM
. * * Re: Random thoughts blt   04/24/05 10:31 PM
. * * Re: Random thoughts ink_polaroidAdministrator   04/25/05 12:28 PM
. * * Re: Random thoughts big_hoovie   07/19/05 07:15 AM
. * * Re: Circle Generator mcshea98Moderator   05/07/05 09:01 AM
. * * Re: Circle Generator bfsmith   05/07/05 07:55 PM
. * * Re: Circle Generator mcshea98Moderator   05/07/05 08:41 PM
. * * Re: Circle Generator bfsmith   05/08/05 05:10 PM
. * * Re: Circle Generator mcshea98Moderator   05/09/05 12:15 AM
. * * Re: Circle Generator Steve_Kotleba   06/21/05 01:42 PM
. * * Re: Circle Generator FuNkY_CaPrIcOrN   06/21/05 03:36 PM
. * * Re: Circle Generator bfsmith   06/16/05 10:36 AM
. * * Re: Circle Generator mcshea98Moderator   06/16/05 04:44 PM
. * * Re: Circle Generator glimme   01/19/06 10:02 AM
. * * Re: Circle Generator bfsmith   06/17/05 06:35 PM
. * * Re: Circle Generator bfsmith   05/11/05 11:58 AM
. * * Re: Random thoughts seerAdministrator   04/24/05 07:44 PM
. * * Re: Random thoughts HSaber   07/27/05 05:26 AM


Extra information
0 registered and 2 anonymous users are browsing this forum.

Moderator:  Hill, Jumble, jrohlf, Kempster, mcshea98, jeffryv, dulce, esterrett, regionator, NormB, Frank_McVey, geus, ZeroDeeFeX, LaBelleTerre, vagabondsailor, SupersonicBuddha, DWebb, BeadieJay, TheLedge, Cyclonic, no_stranger, LuciaM, tekgergedan, ManoM, cantarell, toponym2006, Noisette, danescombe, Michal_Drewniak, mutex, marinerfan, Delta102, bebop, MarkAubin 



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating: ****
Thread views: 29217

Rate this thread

Jump to

earth.google.com    bbs.keyhole.com

*
UBB.threads™ 6.5.1.1