-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preliminary openstreetmaps data sources
- Loading branch information
SeH
committed
Aug 30, 2011
1 parent
0b8aa88
commit 972b667
Showing
8 changed files
with
172 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters