Skip to content

Commit

Permalink
preliminary openstreetmaps data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
SeH committed Aug 30, 2011
1 parent 0b8aa88 commit 972b667
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 6 deletions.
Binary file added lib/commons-compress/commons-compress-1.2.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dist.jar=${dist.dir}/gss.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.commons-compress-1.2.jar=lib/commons-compress/commons-compress-1.2.jar
file.reference.gdal.jar=lib/worldwind/gdal.jar
file.reference.gluegen-rt.jar=lib/worldwind/gluegen-rt.jar
file.reference.guava-r09.jar=lib/guava/guava-r09.jar
Expand All @@ -40,7 +41,8 @@ javac.classpath=\
${file.reference.gluegen-rt.jar}:\
${file.reference.jogl.jar}:\
${file.reference.worldwind.jar}:\
${file.reference.guava-r09.jar}
${file.reference.guava-r09.jar}:\
${file.reference.commons-compress-1.2.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down
5 changes: 4 additions & 1 deletion src/gss/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import gss.geo.LocationsCache;
import gss.data.DataEmpty;
import gss.data.DataKML;
import gss.data.iaea.NuclearFacilities;
import gss.data.osm.AmenitiesCSV;
import gss.data.un.HomicideRate;
import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -58,6 +58,9 @@ public void run() {

addSource(new NuclearFacilities(getDataFile("IAEA_Nuclear_Facilities.csv") ));

addSource(new AmenitiesCSV("mexicoHospital", "Hospitals (Mexico)", "people.png", "Number", "/home/me/mexico_amenities.csv", "hospital"));
addSource(new AmenitiesCSV("mexicoPharmacy", "Pharmacy (Mexico)", "people.png", "Number", "/home/me/mexico_amenities.csv", "pharmacy"));

/*
addSource(new DataKML("/work/survive/cache/epa_airquality.kml", "Air Quality", "Pollution", "icon.xyz", "Units"));
*/
Expand Down
59 changes: 59 additions & 0 deletions src/gss/data/osm/AmenitiesCSV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gss.data.osm;

import gss.Event;
import gss.Event.RadialEvent;
import gss.data.DataPointsList;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Date;
import java.util.logging.Logger;

/**
*
* @author seh
*/
public class AmenitiesCSV extends DataPointsList {
private static final Logger logger = Logger.getLogger(AmenitiesCSV.class.toString());

public AmenitiesCSV(String name, String category, String iconURL, String unit, String csvPath, String whichAmenity) {
super(name, category, iconURL, unit);

File f = new File(csvPath);
Date lastModified = new Date(f.lastModified());

try {
BufferedReader reader = new BufferedReader(new FileReader(f));

int lines = 0;
while (reader.ready()) {
String line = reader.readLine().trim();

String[] tokens = line.split(",");

double lat = Double.parseDouble(tokens[0]);
double lon = Double.parseDouble(tokens[1]);
String amenity = tokens[2];

System.out.println(amenity + " " + lat + " " + lon);

if (amenity.equalsIgnoreCase(whichAmenity)) {
double radius = 100;
Event e = new RadialEvent( amenity, lastModified, lat, lon, radius, 1.0 );
add(e);
}


}
}
catch (Exception e) {
logger.severe(e.toString());
}
}


}
44 changes: 44 additions & 0 deletions src/gss/data/osm/OSMDocument.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gss.data.osm;

import java.io.FileInputStream;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
*
* @author seh
*/
abstract public class OSMDocument extends DefaultHandler {

double minLat = 19.22;
double minLon = -99.08;
double maxLat = 19.24;
double maxLon = -99.10;
public double lat, lon;


public OSMDocument(String filePath) {

try {

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();

final BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new FileInputStream(filePath));

saxParser.parse(bz, this);

} catch (Exception ex) {
ex.printStackTrace();
}
}

}
60 changes: 60 additions & 0 deletions src/gss/data/osm/OSMXmlToAmenitiesCSV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gss.data.osm;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/**
*
* @author seh
*/
public class OSMXmlToAmenitiesCSV extends OSMDocument {

public OSMXmlToAmenitiesCSV(String filePath) {
super(filePath);
}


@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {

// System.out.println(localName + " " + qName + " " + attributes.getLength());

if (qName.equalsIgnoreCase("node")) {

lat = Double.parseDouble(attributes.getValue("lat"));
lon = Double.parseDouble(attributes.getValue("lon"));

//TODO timestamp


// for (int i = 0; i < attributes.getLength(); i++) {
// String key = attributes.getQName(i);
// String value = attributes.getValue(i);
// System.out.println(" " + key + " " + value);
// }
}

//if ((lat >= minLat) && (lat <= maxLat) && (lon >= minLon) && (lon <= maxLon)) {
if (qName.equalsIgnoreCase("tag")) {
//System.out.println(node.keySet().toString() + " " + attributes.keySet().toString());

if (attributes.getValue("k").equalsIgnoreCase("amenity")) {
System.out.println(lat + ", " + lon + "," + attributes.getValue("v"));
}
}
//}


//System.out.println(bz.getBytesRead());

}

public static void main(String[] args) {
new OSMXmlToAmenitiesCSV("/home/me/Downloads/mexico.osm.bz2");
}

}
2 changes: 0 additions & 2 deletions src/gss/gui/ControlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ public ControlPanel(MapPanel mp, Environment d) {
DataSourcePanel dsp = new DataSourcePanel(map, ds);
dsp.setBorder(new EmptyBorder(spacing, 0, 0, 0));
cSub.add(dsp);

dsp.setBackground((ic++) % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gss/gui/MapWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) {
final Environment env = new Environment();

int mapWidth = 1000;
int controlWidth = 200;
int controlWidth = 350;
int height = 850;

final Dimension s = new Dimension(mapWidth, height);
Expand Down Expand Up @@ -73,7 +73,7 @@ public static void _main(String[] args) {
final Environment env = new Environment();

int mapWidth = 1000;
int controlWidth = 200;
int controlWidth = 350;
int height = 850;

final Dimension s = new Dimension(mapWidth, height);
Expand Down

0 comments on commit 972b667

Please sign in to comment.