Search in sources :

Example 1 with PointSet

use of org.opentripplanner.analyst.PointSet in project OpenTripPlanner by opentripplanner.

the class PointSetTest method testLoadGeoJson.

public void testLoadGeoJson() {
    PointSet points = PointSet.fromGeoJson(new File("src/test/resources/pointset/population.geo.json"));
    assertNotNull(points);
    assertEquals(points.capacity, 2);
    assertEquals(1, points.getIndexForFeature(points.ids[1]));
    assertEquals(0, points.getIndexForFeature(points.ids[0]));
    assertEquals(-1, points.getIndexForFeature("THIS FEATURE DOES NOT EXIST."));
}
Also used : PointSet(org.opentripplanner.analyst.PointSet) File(java.io.File)

Example 2 with PointSet

use of org.opentripplanner.analyst.PointSet in project OpenTripPlanner by opentripplanner.

the class PointSetTest method testSaveGeoJson.

/**
 * Load a point set from a GeoJson file, save it to a temporary file, then load it again. Assert
 * that both versions are the same. This should test load and save.
 */
public void testSaveGeoJson() throws IOException {
    PointSet points1 = PointSet.fromGeoJson(new File("src/test/resources/pointset/population.geo.json"));
    File tempFile = File.createTempFile("population", "geo.json");
    tempFile.deleteOnExit();
    OutputStream out = new FileOutputStream(tempFile);
    points1.writeJson(out);
    out.close();
    PointSet points2 = PointSet.fromGeoJson(tempFile);
    assertEquals(points1.id, points2.id);
    assertEquals(points1.label, points2.label);
    assertEquals(points1.featureCount(), points2.featureCount());
    for (int i = 0; i < points1.featureCount(); i++) {
        PointFeature p1 = points1.getFeature(i);
        PointFeature p2 = points2.getFeature(i);
        assertEquals(p1.getId(), p1.getId());
        assertEquals(p1.getLat(), p2.getLat());
        assertEquals(p1.getLon(), p2.getLon());
        assertEquals(p1.getProperties().size(), p2.getProperties().size());
        for (Map.Entry<String, Integer> kv : p1.getProperties().entrySet()) {
            assertEquals(kv.getValue(), new Integer(p2.getProperty(kv.getKey())));
        }
    }
}
Also used : PointSet(org.opentripplanner.analyst.PointSet) PointFeature(org.opentripplanner.analyst.PointFeature) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Map(java.util.Map)

Example 3 with PointSet

use of org.opentripplanner.analyst.PointSet in project OpenTripPlanner by opentripplanner.

the class PointSetTest method testPointSets.

public void testPointSets() throws IOException {
    PointSet austin = PointSet.fromCsv(new File("src/test/resources/pointset/austin.csv"));
    assertNotNull(austin);
    assertEquals(austin.capacity, 15922);
    assertEquals(-1, austin.getIndexForFeature("1"));
}
Also used : PointSet(org.opentripplanner.analyst.PointSet) File(java.io.File)

Example 4 with PointSet

use of org.opentripplanner.analyst.PointSet in project OpenTripPlanner by opentripplanner.

the class PointSetTest method testLoadShapefile.

public void testLoadShapefile() throws NoSuchAuthorityCodeException, IOException, FactoryException, EmptyPolygonException, UnsupportedGeometryException {
    PointSet points = PointSet.fromShapefile(new File("src/test/resources/pointset/shp/austin.shp"));
    assertNotNull(points);
    PointFeature ft = points.getFeature(0);
    int pop = ft.getProperty("DEC_10_S_2");
    assertEquals(pop, 42);
}
Also used : PointSet(org.opentripplanner.analyst.PointSet) PointFeature(org.opentripplanner.analyst.PointFeature) File(java.io.File)

Example 5 with PointSet

use of org.opentripplanner.analyst.PointSet in project OpenTripPlanner by opentripplanner.

the class PointSetTest method testBogusCSV.

/**
 * Factory method should return null but not throw an exception on malformed CSV.
 */
public void testBogusCSV() throws IOException {
    PointSet points = PointSet.fromCsv(new File("src/test/resources/pointset/bogus.csv"));
    assertNull(points);
}
Also used : PointSet(org.opentripplanner.analyst.PointSet) File(java.io.File)

Aggregations

PointSet (org.opentripplanner.analyst.PointSet)9 File (java.io.File)7 OutputStream (java.io.OutputStream)3 PointFeature (org.opentripplanner.analyst.PointFeature)3 SampleSet (org.opentripplanner.analyst.SampleSet)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Map (java.util.Map)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 HttpHostConnectException (org.apache.http.conn.HttpHostConnectException)1 ResultSet (org.opentripplanner.analyst.ResultSet)1 TimeSurface (org.opentripplanner.analyst.TimeSurface)1