Skip to content

Commit

Permalink
Added Endpoint for getting map based upon long lat
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Wiens committed Jun 6, 2024
1 parent 7fca82f commit a68b909
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface ProcessedMapRepository extends DataLoader<ProcessedMap<LineStri
List<IDCount> getMapBroadcastRates(int intersectionID, Long startTime, Long endTime);

List<IDCount> getMapBroadcastRateDistribution(int intersectionID, Long startTime, Long endTime);

List<IntersectionReferenceData> getIntersectionsContainingPoint(double longitude, double latitude);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.bson.Document;
import org.bson.conversions.Bson;
import org.locationtech.jts.geom.CoordinateXY;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -39,6 +41,8 @@
import us.dot.its.jpo.ode.api.ConflictMonitorApiProperties;
import us.dot.its.jpo.ode.api.models.IDCount;
import us.dot.its.jpo.ode.api.models.IntersectionReferenceData;
import us.dot.its.jpo.conflictmonitor.monitor.models.map.MapBoundingBox;
import us.dot.its.jpo.conflictmonitor.monitor.models.map.MapIndex;
import us.dot.its.jpo.geojsonconverter.DateJsonMapper;
import us.dot.its.jpo.geojsonconverter.pojos.geojson.LineString;

Expand Down Expand Up @@ -158,6 +162,54 @@ public List<IntersectionReferenceData> getIntersectionIDs() {
return referenceDataList;
}

public List<IntersectionReferenceData> getIntersectionsContainingPoint(double longitude, double latitude){
MongoCollection<Document> collection = mongoTemplate.getCollection(collectionName);
DistinctIterable<Integer> docs = collection.distinct("properties.intersectionId", Integer.class);
MongoCursor<Integer> results = docs.iterator();
MapIndex index = new MapIndex();
Map<Integer, ProcessedMap<LineString>> mapLookup = new HashMap<>();
while (results.hasNext()) {
Integer intersectionId = results.next();
if (intersectionId != null){


Query query = getQuery(intersectionId, null, null, true, true);

List<ProcessedMap<LineString>> maps = findProcessedMaps(query);

if(maps.size() > 0){
MapBoundingBox box = new MapBoundingBox(maps.getFirst());
index.insert(box);
mapLookup.put(intersectionId, maps.getFirst());
}
}
}

List<MapBoundingBox> mapsContainingPoints = index.mapsContainingPoint(new CoordinateXY(longitude, latitude));

List<IntersectionReferenceData> result = new ArrayList<>();
for(MapBoundingBox box: mapsContainingPoints){
ProcessedMap<LineString> map = mapLookup.get(box.getIntersectionId());
IntersectionReferenceData data = new IntersectionReferenceData();
data.setIntersectionID(map.getProperties().getIntersectionId());
data.setRoadRegulatorID("-1");
data.setRsuIP(map.getProperties().getOriginIp());

if(map.getProperties().getIntersectionName() != null && map.getProperties().getIntersectionName().isEmpty()){
data.setIntersectionName(map.getProperties().getIntersectionName());
}

if (map.getProperties().getRefPoint() != null) {
data.setLatitude(map.getProperties().getRefPoint().getLatitude().doubleValue());
data.setLongitude(map.getProperties().getRefPoint().getLongitude().doubleValue());
}
result.add(data);
}

return result;

}

public List<IDCount> getMapBroadcastRates(int intersectionID, Long startTime, Long endTime) {

String startTimeString = Instant.ofEpochMilli(0).toString();
Expand Down Expand Up @@ -231,6 +283,8 @@ public List<IDCount> getMapBroadcastRateDistribution(int intersectionID, Long st
return results;
}



@Override
public void add(ProcessedMap<LineString> item) {
mongoTemplate.save(item, collectionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,27 @@ public ResponseEntity<List<IntersectionReferenceData>> getIntersections(

}
}

@CrossOrigin(origins = "http://localhost:3000")
@RequestMapping(value = "/intersection/list/location", method = RequestMethod.GET, produces = "application/json")
@PreAuthorize("hasRole('USER') || hasRole('ADMIN')")
public ResponseEntity<List<IntersectionReferenceData>> getIntersectionsByLocation(
@RequestParam(name = "longitude", required = true, defaultValue = "false") Double longitude,
@RequestParam(name = "latitude", required = true, defaultValue = "false") Double latitude,
@RequestParam(name = "test", required = false, defaultValue = "false") boolean testData) {

if (testData) {
IntersectionReferenceData ref = new IntersectionReferenceData();
ref.setRsuIP("10.11.81.12");
ref.setIntersectionID(12109);
ref.setRoadRegulatorID("0");

List<IntersectionReferenceData> refList = new ArrayList<>();
refList.add(ref);

return ResponseEntity.ok(refList);
} else {
return ResponseEntity.ok(processedMapRepo.getIntersectionsContainingPoint(longitude, latitude));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,4 @@ public ResponseEntity<Long> countMaps(

}
}


}

0 comments on commit a68b909

Please sign in to comment.