Skip to content

Commit

Permalink
Use new trimmed/buffered factory methods
Browse files Browse the repository at this point in the history
Trimming when handling possibly recycled WGS84 bounds.
Buffering when supplying tight fit opportunity bounding boxes.
  • Loading branch information
abyrd committed Oct 16, 2023
1 parent e5afeaa commit 1eaa461
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ public void populateTask (AnalysisWorkerTask task, UserPermissions userPermissio
task.maxFare = maxFare;
task.inRoutingFareCalculator = inRoutingFareCalculator;

// TODO define class with static factory function WebMercatorGridBounds.fromLatLonBounds().
// Also include getIndex(x, y), getX(index), getY(index), totalTasks()
WebMercatorExtents extents = WebMercatorExtents.forWgsEnvelope(bounds.envelope(), zoom);
WebMercatorExtents extents = WebMercatorExtents.forTrimmedWgsEnvelope(bounds.envelope(), zoom);
task.height = extents.height;
task.north = extents.north;
task.west = extents.west;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/conveyal/r5/analyst/FreeFormPointSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ public Envelope getWgsEnvelope () {
public WebMercatorExtents getWebMercatorExtents () {
final int DEFAULT_ZOOM = 9;
Envelope wgsEnvelope = this.getWgsEnvelope();
WebMercatorExtents webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, DEFAULT_ZOOM);
return webMercatorExtents;
return WebMercatorExtents.forBufferedWgsEnvelope(wgsEnvelope, DEFAULT_ZOOM);
}

/** Construct a freeform point set containing one opportunity at each specified geographic coordinate. */
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/conveyal/r5/analyst/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Grid (WebMercatorExtents extents) {
* @param wgsEnvelope Envelope of grid, in absolute WGS84 lat/lon coordinates
*/
public Grid (int zoom, Envelope wgsEnvelope) {
this(WebMercatorExtents.forWgsEnvelope(wgsEnvelope, zoom));
this(WebMercatorExtents.forBufferedWgsEnvelope(wgsEnvelope, zoom));
}

public static class PixelWeight {
Expand Down Expand Up @@ -615,7 +615,7 @@ public static List<Grid> fromCsv(InputStreamProvider csvInputStreamProvider,
reader.close();

checkWgsEnvelopeSize(envelope, "CSV points");
WebMercatorExtents extents = WebMercatorExtents.forWgsEnvelope(envelope, zoom);
WebMercatorExtents extents = WebMercatorExtents.forBufferedWgsEnvelope(envelope, zoom);
checkPixelCount(extents, numericColumns.size());

if (progressListener != null) {
Expand Down Expand Up @@ -687,7 +687,7 @@ public static List<Grid> fromShapefile (File shapefile, int zoom, ProgressListen
ShapefileReader reader = new ShapefileReader(shapefile);
Envelope envelope = reader.wgs84Bounds();
checkWgsEnvelopeSize(envelope, "Shapefile");
WebMercatorExtents extents = WebMercatorExtents.forWgsEnvelope(envelope, zoom);
WebMercatorExtents extents = WebMercatorExtents.forBufferedWgsEnvelope(envelope, zoom);
List<String> numericAttributes = reader.numericAttributes();
Set<String> uniqueNumericAttributes = new HashSet<>(numericAttributes);
if (uniqueNumericAttributes.size() != numericAttributes.size()) {
Expand Down Expand Up @@ -764,14 +764,12 @@ public double getOpportunityCount (int i) {
}

/**
* Rasterize a FreeFormFointSet into a Grid.
* Currently intended only for UI display of FreeFormPointSets, or possibly for previews of accessibility results
* during
* Rasterize a FreeFormFointSet into a Grid. Currently intended only for UI display of FreeFormPointSets.
*/
public static Grid fromFreeForm (FreeFormPointSet freeForm, int zoom) {
// TODO make and us a strongly typed WgsEnvelope class here and in various places
Envelope wgsEnvelope = freeForm.getWgsEnvelope();
WebMercatorExtents webMercatorExtents = WebMercatorExtents.forWgsEnvelope(wgsEnvelope, zoom);
WebMercatorExtents webMercatorExtents = WebMercatorExtents.forBufferedWgsEnvelope(wgsEnvelope, zoom);
Grid grid = new Grid(webMercatorExtents);
grid.name = freeForm.name;
for (int f = 0; f < freeForm.featureCount(); f++) {
Expand Down

0 comments on commit 1eaa461

Please sign in to comment.