@@ -13,48 +13,6 @@ namespace B3dm.Tileset;
1313
1414public static class GeometryRepository
1515{
16- public static HashSet < string > FilterHashesByEnvelope ( NpgsqlConnection conn , string tableName , string geometryColumn , BoundingBox bbox , int source_epsg , HashSet < string > geometryHashes , bool keepProjection )
17- {
18- if ( geometryHashes . Count == 0 ) {
19- return new HashSet < string > ( ) ;
20- }
21-
22- var filteredHashes = new HashSet < string > ( ) ;
23-
24- conn . Open ( ) ;
25- try {
26- var envelope = keepProjection ?
27- $ "ST_MakeEnvelope(@xmin, @ymin, @xmax, @ymax, { source_epsg } )" :
28- $ "ST_Transform(ST_MakeEnvelope(@xmin, @ymin, @xmax, @ymax, 4326), { source_epsg } )";
29-
30- var query = $@ "
31- SELECT MD5(ST_AsBinary({ geometryColumn } )::text) as geom_hash
32- FROM { tableName }
33- WHERE MD5(ST_AsBinary({ geometryColumn } )::text) = ANY(@hashes)
34- AND ST_Within(
35- ST_Centroid(ST_Envelope({ geometryColumn } )),
36- { envelope }
37- )" ;
38-
39- using var cmd = new NpgsqlCommand ( query , conn ) ;
40- cmd . Parameters . AddWithValue ( "hashes" , geometryHashes . ToArray ( ) ) ;
41- cmd . Parameters . AddWithValue ( "xmin" , bbox . XMin ) ;
42- cmd . Parameters . AddWithValue ( "ymin" , bbox . YMin ) ;
43- cmd . Parameters . AddWithValue ( "xmax" , bbox . XMax ) ;
44- cmd . Parameters . AddWithValue ( "ymax" , bbox . YMax ) ;
45-
46- using var reader = cmd . ExecuteReader ( ) ;
47- while ( reader . Read ( ) ) {
48- var hash = reader . GetString ( 0 ) ;
49- filteredHashes . Add ( hash ) ;
50- }
51-
52- return filteredHashes ;
53- }
54- finally {
55- conn . Close ( ) ;
56- }
57- }
5816
5917 /// <summary>
6018 /// Returns double array with 6 bounding box coordinates, xmin, ymin, xmax, ymax, zmin, zmax
@@ -85,13 +43,13 @@ public static double[] GetGeometriesBoundingBox(NpgsqlConnection conn, string ge
8543 }
8644 }
8745
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 , SortBy sortBy = SortBy . AREA )
46+ 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 = "" , HashSet < string > excludeHashes = null , int ? maxFeatures = null , SortBy sortBy = SortBy . AREA )
8947 {
9048 var sqlselect = GetSqlSelect ( geometry_column , shaderColumn , attributesColumns , radiusColumn , target_srs ) ;
9149 var sqlFrom = "FROM " + geometry_table ;
9250 var points = GetPoints ( bbox ) ;
9351
94- var sqlWhere = GetWhere ( geometry_column , points . fromPoint , points . toPoint , query , source_epsg , keepProjection ) ;
52+ var sqlWhere = GetWhere ( geometry_column , points . fromPoint , points . toPoint , query , source_epsg ) ;
9553
9654 // Add hash exclusion filter using parameterized query
9755 if ( excludeHashes != null && excludeHashes . Count > 0 ) {
@@ -117,7 +75,7 @@ public static List<GeometryRecord> GetGeometrySubset(NpgsqlConnection conn, stri
11775 }
11876 }
11977
120- public static string GetWhere ( string geometry_column , Point from , Point to , string query , int source_epsg , bool keepProjection )
78+ public static string GetWhere ( string geometry_column , Point from , Point to , string query , int source_epsg )
12179 {
12280 var fromX = from . X . Value . ToString ( CultureInfo . InvariantCulture ) ;
12381 var fromY = from . Y . Value . ToString ( CultureInfo . InvariantCulture ) ;
@@ -128,22 +86,14 @@ public static string GetWhere(string geometry_column, Point from, Point to, stri
12886 var where = "" ;
12987
13088 if ( ! hasZ ) {
131- where = keepProjection ?
132- $ "ST_Centroid(ST_Envelope({ geometry_column } )) && ST_MakeEnvelope({ fromX } , { fromY } , { toX } , { toY } , { source_epsg } ) { query } " :
133- $ "ST_Centroid(ST_Envelope({ geometry_column } )) && st_transform(ST_MakeEnvelope({ fromX } , { fromY } , { toX } , { toY } , 4326), { source_epsg } ) { query } ";
89+ where = $ "ST_Centroid(ST_Envelope({ geometry_column } )) && ST_MakeEnvelope({ fromX } , { fromY } , { toX } , { toY } , { source_epsg } ) { query } ";
13490 }
13591 else {
136- var fromBox = keepProjection ?
137- $ "st_setsrid(ST_MakePoint({ fromX } , { fromY } , { from . Z . Value . ToString ( CultureInfo . InvariantCulture ) } ), { source_epsg } )" :
138- $ "st_setsrid(ST_MakePoint({ fromX } , { fromY } , { from . Z . Value . ToString ( CultureInfo . InvariantCulture ) } ), 4979)";
139- var toBox = keepProjection ?
140- $ "st_setsrid(ST_MakePoint({ toX } , { toY } , { to . Z . Value . ToString ( CultureInfo . InvariantCulture ) } ), { source_epsg } )" :
141- $ "st_setsrid(ST_MakePoint({ toX } , { toY } , { to . Z . Value . ToString ( CultureInfo . InvariantCulture ) } ), 4979)";
92+ var fromBox = $ "st_setsrid(ST_MakePoint({ fromX } , { fromY } , { from . Z . Value . ToString ( CultureInfo . InvariantCulture ) } ), { source_epsg } )";
93+ var toBox = $ "st_setsrid(ST_MakePoint({ toX } , { toY } , { to . Z . Value . ToString ( CultureInfo . InvariantCulture ) } ), { source_epsg } )";
14294
14395 var geom = $ "st_setsrid(st_makepoint((st_xmin({ geometry_column } ) + st_xmax({ geometry_column } ))/2,(st_ymin({ geometry_column } ) + st_ymax({ geometry_column } ))/2, (st_zmin({ geometry_column } ) + st_zmax({ geometry_column } ))/2), { source_epsg } )";
144- where = keepProjection ?
145- $ "ST_3DIntersects({ geom } , ST_3DMakeBox({ fromBox } , { toBox } )) { query } " :
146- $ "ST_3DIntersects({ geom } , st_transform(ST_3DMakeBox({ fromBox } , { toBox } ), { source_epsg } )) { query } ";
96+ where = $ "ST_3DIntersects({ geom } , ST_3DMakeBox({ fromBox } , { toBox } )) { query } ";
14797 }
14898
14999 return where ;
0 commit comments