use of org.opentripplanner.analyst.PointFeature 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())));
}
}
}
use of org.opentripplanner.analyst.PointFeature 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);
}
use of org.opentripplanner.analyst.PointFeature in project OpenTripPlanner by opentripplanner.
the class PointSetTest method testGetFeature.
public void testGetFeature() {
PointSet points = PointSet.fromGeoJson(new File("src/test/resources/pointset/population.geo.json"));
PointFeature pt = points.getFeature(0);
assertNotNull(pt);
assertEquals(pt.getId(), "XYZ0001");
Map<String, Integer> attrs = pt.getProperties();
assertEquals(attrs.size(), 2);
assertEquals(pt.getProperty("age"), 10);
}
Aggregations