Commit 8d2e0e34 authored by Julian Zobel's avatar Julian Zobel
Browse files

JSON Attraction Generator now takes in an upper limit for attraction points

parent 6906943a
......@@ -36,6 +36,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Generates attraction points out of real data from osm
......@@ -43,13 +44,18 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
*
* @author Martin Hellwig
* @version 1.0, 02.07.2015
*
* Added an upper limit for the number of attraction points. Use 0 to allow all APs in the JSON file.
* @author Julian Zobel
* @version 1.1, November 2018
*
*
*/
public class JSONAttractionGenerator implements IAttractionGenerator {
private PositionVector worldDimensions;
private List<AttractionPoint> attractionPoints;
private int numberOfAttractionPoints;
private String placementJsonFile;
private double latLeft; //Values from -90 to 90; always smaller than latRight
private double latRight; //Values from -90 to 90
......@@ -61,11 +67,12 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
* Sample-query for "bar"-POIs in Darmstadt (Bounding Box from [49.4813, 8.5590] to [49.9088, 8,7736]:
http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=bar%5D%2849%2E4813%2C8%2E5590%2C49%2E9088%2C8%2E7736%29%3Bout%3B
*/
public JSONAttractionGenerator() {
@XMLConfigurableConstructor({"numberOfAttractionPoints"})
public JSONAttractionGenerator(int numberOfAttractionPoints) {
this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
attractionPoints = new LinkedList<AttractionPoint>();
this.numberOfAttractionPoints = numberOfAttractionPoints;
latLeft = GPSCalculation.getLatLower();
latRight = GPSCalculation.getLatUpper();
lonLeft = GPSCalculation.getLonLeft();
......@@ -105,7 +112,16 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
}
if(allPOI != null) {
for(int i = 0; i < allPOI.length(); i++) {
int limit = 0;
if(numberOfAttractionPoints == 0) {
limit = allPOI.length();
}
else {
limit = numberOfAttractionPoints;
}
for(int i = 0; i < limit; i++) {
try {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
......@@ -132,5 +148,9 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
public void setPlacementJsonFile(String placementJsonFile) {
this.placementJsonFile = placementJsonFile;
//System.out.println(placementJsonFile);
if(attractionPoints.isEmpty()) {
this.getAttractionPoints();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment