H2 GIS - How to use multiple Geometry for st_within

22 views
Skip to first unread message

RAJIV S

unread,
Apr 20, 2020, 9:40:13 AM4/20/20
to H2 Database
Hi ,

I have a collection of lat/longs , i want to find out if what all belongs to Geometry B and what all not belongs to Geomentry B..
I have given below example, Here i have array of lat/longs,.

Instead of iterating each and every lat/longs and executing query every time ,finding out if it is within SAFE ZONE , i am trying to achieve with only one query execution and find out all at once.

This is to improve my overall processing performance time.  

Please help me ., how can i achieve multiple here,  I am using this logic in In-memory H2



private static final String LOOKUP_QUERY="select top 1  \r\n" + 
" cz.id,\r\n" + 
" cz.THE_GEOM ,\r\n" +  
" cz.name , \r\n" +  
" cz.BOUNDARY \r\n" +  
"from \r\n" + 
" SAFE_ZONE  cz \r\n" + 
"where  \r\n" + 
" st_within( st_makepoint(?,?) ,cz.THE_GEOM)";
public static Address[] findFencesInH2SafeZone(RevGeoInput[] revGeoinputs) {
Address[] arrAddress = new Address[revGeoinputs.length];
PreparedStatement prepStmt = null;
Connection connection = null;
String fenceFound = null;
Address oAddress = null;
ResultSet rs1 = null;
try {
connection = GetInMemoryConnUtil.getConnection()
prepStmt = connection.prepareStatement(LOOKUP_QUERY);
for(int i=0 ; i<revGeoinputs.length ; i++) {
RevGeoInput oRevGeoInput = revGeoinputs[i];
prepStmt.setDouble(1, oRevGeoInput.getLongitude());
prepStmt.setDouble(2, oRevGeoInput.getLatitude() );
rs1 = prepStmt.executeQuery();
oAddress = new Address();
if (rs1.next()) {
                          fenceFound = rs1.getString("name");
            
                           oAddress.setSafeZone(STR_Y);
                         arrAddress[i] = oAddress;
}else {
oAddress.setSafeZone(STR_N);
arrAddress[i] = oAddress;
}
}
}catch (SQLException e) {
        } catch (Exception e) {       
} finally {
}
return arrAddress;
}
Reply all
Reply to author
Forward
0 new messages