Skip to content

Commit 03297e6

Browse files
committed
update octreetiler
1 parent 22b9fe3 commit 03297e6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/b3dm.tileset/GeometryRepository.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static double[] GetGeometriesBoundingBox(NpgsqlConnection conn, string ge
8585
}
8686
}
8787

88-
public static List<GeometryRecord> GetGeometrySubset(NpgsqlConnection conn, string geometry_table, string geometry_column, double[] bbox, int source_epsg, int target_srs, string shaderColumn = "", string attributesColumns = "", string query = "", string radiusColumn = "", bool keepProjection = false, HashSet<string> excludeHashes = null, int? maxFeatures = null)
88+
public static List<GeometryRecord> GetGeometrySubset(NpgsqlConnection conn, string geometry_table, string geometry_column, double[] bbox, int source_epsg, int target_srs, string shaderColumn = "", string attributesColumns = "", string query = "", string radiusColumn = "", bool keepProjection = false, HashSet<string> excludeHashes = null, int? maxFeatures = null, SubdivisionScheme scheme = SubdivisionScheme.QUADTREE)
8989
{
9090
var sqlselect = GetSqlSelect(geometry_column, shaderColumn, attributesColumns, radiusColumn, target_srs);
9191
var sqlFrom = "FROM " + geometry_table;
@@ -100,7 +100,7 @@ public static List<GeometryRecord> GetGeometrySubset(NpgsqlConnection conn, stri
100100
sqlWhere += $" AND MD5(ST_AsBinary({geometry_column})::text) != ALL(@excludeHashes)";
101101
}
102102

103-
var sqlOrderBy = GetOrderBy(geometry_column);
103+
var sqlOrderBy = GetOrderBy(geometry_column, scheme);
104104
var sqlLimit = maxFeatures.HasValue ? $" LIMIT {maxFeatures.Value}" : "";
105105
var sql = sqlselect + sqlFrom + " where " + sqlWhere + sqlOrderBy + sqlLimit;
106106

@@ -175,8 +175,11 @@ public static string GetGeometryColumn(string geometry_column, int target_srs)
175175
return $"st_transform({geometry_column}, {target_srs})";
176176
}
177177

178-
public static string GetOrderBy(string geometry_column)
178+
public static string GetOrderBy(string geometry_column, SubdivisionScheme scheme)
179179
{
180+
if (scheme == SubdivisionScheme.OCTREE) {
181+
return $" ORDER BY (ST_XMax({geometry_column}) - ST_XMin({geometry_column})) *(ST_YMax({geometry_column}) - ST_YMin({geometry_column})) DESC";
182+
}
180183
return $" ORDER BY ST_Area(ST_Envelope({geometry_column})) DESC";
181184
}
182185

src/b3dm.tileset/OctreeTiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private HashSet<string> CreateTileForLargestGeometries3D(BoundingBox3D bbox, int
103103
int target_srs = tilingSettings.KeepProjection ? inputTable.EPSGCode : 4978;
104104

105105
var bbox1 = new double[] { bbox.XMin, bbox.YMin, bbox.XMax, bbox.YMax, bbox.ZMin, bbox.ZMax };
106-
var geometriesToProcess = GeometryRepository.GetGeometrySubset(conn, inputTable.TableName, inputTable.GeometryColumn, bbox1, inputTable.EPSGCode, target_srs, inputTable.ShadersColumn, inputTable.AttributeColumns, where, inputTable.RadiusColumn, tilingSettings.KeepProjection, processedGeometries, tilingSettings.MaxFeaturesPerTile);
106+
var geometriesToProcess = GeometryRepository.GetGeometrySubset(conn, inputTable.TableName, inputTable.GeometryColumn, bbox1, inputTable.EPSGCode, target_srs, inputTable.ShadersColumn, inputTable.AttributeColumns, where, inputTable.RadiusColumn, tilingSettings.KeepProjection, processedGeometries, tilingSettings.MaxFeaturesPerTile, SubdivisionScheme.OCTREE);
107107

108108
if (geometriesToProcess.Count > 0) {
109109
foreach (var geom in geometriesToProcess.Where(geom => !string.IsNullOrEmpty(geom.Hash))) {
@@ -129,7 +129,7 @@ private void CreateTile3D(BoundingBox3D bbox, int level, Tile3D tile, List<Tile3
129129
int target_srs = tilingSettings.KeepProjection ? inputTable.EPSGCode : 4978;
130130

131131
var bbox1 = new double[] { bbox.XMin, bbox.YMin, bbox.XMax, bbox.YMax, bbox.ZMin, bbox.ZMax };
132-
var geometries = GeometryRepository.GetGeometrySubset(conn, inputTable.TableName, inputTable.GeometryColumn, bbox1, inputTable.EPSGCode, target_srs, inputTable.ShadersColumn, inputTable.AttributeColumns, where, inputTable.RadiusColumn, tilingSettings.KeepProjection, processedGeometries);
132+
var geometries = GeometryRepository.GetGeometrySubset(conn, inputTable.TableName, inputTable.GeometryColumn, bbox1, inputTable.EPSGCode, target_srs, inputTable.ShadersColumn, inputTable.AttributeColumns, where, inputTable.RadiusColumn, tilingSettings.KeepProjection, processedGeometries, tilingSettings.MaxFeaturesPerTile, SubdivisionScheme.OCTREE);
133133

134134
if (geometries.Count > 0) {
135135
// Collect hashes of processed geometries

0 commit comments

Comments
 (0)