Update of /cvsroot/genj/dev/geo/src/report/geo
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv15153/src/report/geo
Modified Files:
ReportGoogleMap.java
Log Message:
geo: create google kml for testing as suggested by Kevin
Index: ReportGoogleMap.java
===================================================================
RCS file: /cvsroot/genj/dev/geo/src/report/geo/ReportGoogleMap.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** ReportGoogleMap.java 17 May 2007 17:09:13 -0000 1.19
--- ReportGoogleMap.java 18 Oct 2007 03:46:51 -0000 1.20
***************
*** 114,117 ****
--- 114,118 ----
}
File xml = new File(html.getAbsolutePath().replaceAll("."+suffix, ".xml"));
+ File kml = new File(html.getAbsolutePath().replaceAll("."+suffix, ".kml"));
// write the html file
***************
*** 120,124 ****
// write the xml file
! if (!writeXML(locations, xml))
return;
--- 121,125 ----
// write the xml file
! if (!writeXML(locations, xml, kml))
return;
***************
*** 170,174 ****
* write the xml file
*/
! private boolean writeXML(Collection locations, File xml) {
// <ls>
--- 171,175 ----
* write the xml file
*/
! private boolean writeXML(Collection locations, File xml, File kml) {
// <ls>
***************
*** 176,209 ****
// <l x="37.322" y="-121.213"/>
// </ls>
try {
! BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xml), Charset.forName("UTF8")));
! out.write("<ls>");
for (Iterator it=locations.iterator(); it.hasNext(); ) {
// valid location?
GeoLocation location = (GeoLocation)it.next();
! if (!location.isValid()) continue;
! // start with coordinates
! out.write("<l x=\"" + FORMAT.format(location.getX()) + "\" y=\"" + FORMAT.format(location.getY()) + "\">");
! // place
! out.write(location.toString());
! // add first property's info
! int max = maxEventsPerLocation<=0 ? Integer.MAX_VALUE : maxEventsPerLocation;
! for (int p=0;p<max&&p<location.getNumProperties();p++) {
! out.write(";");
! Property prop = location.getProperty(p);
! Property date = prop.getProperty("DATE", true);
! if (date!=null) {
! out.write(date.toString());
! out.write(" ");
! }
! out.write(Gedcom.getName(prop.getTag()));
! out.write(" ");
! out.write(prop.getEntity().toString());
! }
// next
- out.write("</l>");
}
! out.write("</ls>");
! out.close();
} catch (IOException e) {
getOptionFromUser(translate("ioerror", xml), OPTION_OK);
--- 177,222 ----
// <l x="37.322" y="-121.213"/>
// </ls>
+
+ // <?xml version="1.0" encoding="UTF-8"?>
+ // <kml xmlns="http://earth.google.com/kml/2.2">
+ // <Folder>
+ // <Placemark>
+ // <name>Simple placemark</name>
+ // <description>Attached to the ground. Intelligently places itself
+ // at the height of the underlying terrain.</description>
+ // <Point>
+ // <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
+ // </Point>
+ // </Placemark>
+ // </Folder>
+ // </kml>
try {
! BufferedWriter xmlout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xml), Charset.forName("UTF8")));
! xmlout.write("<ls>");
!
! BufferedWriter kmlout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(kml), Charset.forName("UTF8")));
! kmlout.write("<kml xmlns=\"http://earth.google.com/kml/2.2\">");
! kmlout.write("<Folder>");
!
for (Iterator it=locations.iterator(); it.hasNext(); ) {
+
// valid location?
GeoLocation location = (GeoLocation)it.next();
! if (!location.isValid())
! continue;
!
! writeXML(location, xmlout);
! writeKML(location, kmlout);
!
// next
}
!
! xmlout.write("</ls>");
! xmlout.close();
!
! kmlout.write("</Folder>");
! kmlout.write("</kml>");
! kmlout.close();
!
} catch (IOException e) {
getOptionFromUser(translate("ioerror", xml), OPTION_OK);
***************
*** 214,217 ****
--- 227,280 ----
return true;
}
+
+ private void writeKML(GeoLocation location, BufferedWriter out) throws IOException {
+
+ out.write("<Placemark>");
+ out.write("<name>");
+ out.write(location.toString());
+ out.write("</name>");
+ out.write("<description>");
+ writeProperties(location, out, "\n");
+ out.write("</description>");
+ out.write("<Point>");
+ out.write("<coordinates>");
+ out.write(FORMAT.format(location.getX()));
+ out.write(",");
+ out.write(FORMAT.format(location.getY()));
+ out.write("</coordinates>");
+ out.write("</Point>");
+ out.write("</Placemark>");
+ }
+
+ private void writeXML(GeoLocation location, BufferedWriter out) throws IOException {
+
+ // xml coordinates & place
+ out.write("<l x=\"" + FORMAT.format(location.getX()) + "\" y=\"" + FORMAT.format(location.getY()) + "\">");
+ out.write(location.toString());
+
+ // description (events)
+ writeProperties(location, out, ";");
+
+ // done
+ out.write("</l>");
+ }
+
+ private void writeProperties(GeoLocation location, BufferedWriter out, String delim) throws IOException {
+
+ int max = maxEventsPerLocation<=0 ? Integer.MAX_VALUE : maxEventsPerLocation;
+ for (int p=0;p<max&&p<location.getNumProperties();p++) {
+ out.write(delim);
+ Property prop = location.getProperty(p);
+ Property date = prop.getProperty("DATE", true);
+ if (date!=null) {
+ out.write(date.toString());
+ out.write(" ");
+ }
+ out.write(Gedcom.getName(prop.getTag()));
+ out.write(" ");
+ out.write(prop.getEntity().toString());
+ }
+
+ }
/**
|