Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geometry_to_bing_tiles function for geometry collections #10627

Merged
merged 5 commits into from
May 18, 2018

Conversation

mbasmanova
Copy link
Contributor

Fix NPE in geometry_to_bing_tiles function when input is a geometry collection.

Fixes #10623

@@ -338,6 +338,11 @@ public void testGeometryToBingTiles()
assertFunction("cardinality(geometry_to_bing_tiles(ST_GeometryFromText('POLYGON ((0 0, 0 20, 20 20, 0 0))'), 14))", BIGINT, 428787L);
}

private void assertGeometryToBingTiles(String wkt, int zoomLevel, List<String> expectedQuadKeys)
{
assertFunction("transform(geometry_to_bing_tiles(ST_GeometryFromText('" + wkt +"'), " + zoomLevel + "), x -> bing_tile_quadkey(x))", new ArrayType(VARCHAR), expectedQuadKeys);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use String.format() for better readability.

points++;
}
else {
points += ((MultiVertexGeometry) geometry).getPointCount();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can also be a Segment (Line)

Copy link
Member

@arhimondr arhimondr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

zoomLevel,
BingTile.fromCoordinates(x, y, nextZoomLevel),
blockBuilder);
}
}
}

private static int getPointCount(Geometry geometry)
private static int getPointCount(OGCGeometry ogcGeometry)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method looks like an pretty generic utility method. Do you think it is worth moving to a public utility class?

}
}

return blockBuilder.build();
}

private static Envelope getEnvelope(OGCGeometry ogcGeometry)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIP: Think of moving getEnvelope , disjoint , contains, getPointCount , isPointOrRectangle to the GeometryUtils class. These methods (or at least some of them) seem to be pretty generic.

@@ -256,13 +255,59 @@ public static Block geometryToBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input
// tile covered by the geometry.
BingTile[] tiles = getTilesInBetween(leftUpperTile, rightLowerTile, OPTIMIZED_TILING_MIN_ZOOM_LEVEL);
for (BingTile tile : tiles) {
writeTilesToBlockBuilder(geometry, zoomLevel, tile, blockBuilder);
writeTilesToBlockBuilder(ogcGeometry, zoomLevel, tile, blockBuilder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/writeTilesToBlockBuilder/appendIntersectingSubtiles/

@@ -256,13 +255,59 @@ public static Block geometryToBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input
// tile covered by the geometry.
BingTile[] tiles = getTilesInBetween(leftUpperTile, rightLowerTile, OPTIMIZED_TILING_MIN_ZOOM_LEVEL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intersectingLargeTiles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arhimondr I like your other suggestion s/writeTilesToBlockBuilder/appendIntersectingSubtiles/, but I'm not sure about this one. Here, we are not looking for intersecting tiles, but rather a set of sub-tiles covering some larger tiles. One can think about this function as 2d version of sequence(start, stop, step) where start is a tile in one corner, stop is a tile in the opposite corner and step is zoom level. Perhaps, s/getTilesInBetween/tilesSequence?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the method is fine. I was talking about the variable name. But even so, i don't have a strong opinion here.

@@ -307,6 +307,12 @@ public void testGeometryToBingTiles()
assertGeometryToBingTiles("POLYGON ((10 10, -10 10, -20 -15, 10 10))", 3, ImmutableList.of("033", "211", "122"));
assertGeometryToBingTiles("POLYGON ((10 10, -10 10, -20 -15, 10 10))", 6, ImmutableList.of("211102", "211120", "033321", "033323", "211101", "211103", "211121", "033330", "033332", "211110", "211112", "033331", "033333", "211111", "122220", "122222", "122221"));

assertGeometryToBingTiles("GEOMETRYCOLLECTION (POINT (60 30.12))", 10, ImmutableList.of("1230301230"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a GEOMETRYCOLLECTION EMPTY case

@mbasmanova mbasmanova force-pushed the fix-geometry-to-bing-tiles branch 2 times, most recently from aa22a5f to 610d315 Compare May 18, 2018 05:03
}

/**
* @return true if the geometry is a point or a rectangle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

Return empty array if input geometry is empty, Before, the function threw an exception.
@mbasmanova mbasmanova merged commit 89d6508 into prestodb:master May 18, 2018
@mbasmanova mbasmanova deleted the fix-geometry-to-bing-tiles branch February 15, 2019 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants