|
| 1 | +package lod.networkbuffer; |
| 2 | + |
| 3 | +import java.io.InputStream; |
| 4 | +import java.sql.Connection; |
| 5 | +import java.sql.PreparedStatement; |
| 6 | +import java.sql.ResultSet; |
| 7 | +import java.sql.SQLException; |
| 8 | +import java.sql.Statement; |
| 9 | +import java.text.DecimalFormat; |
| 10 | +import java.text.NumberFormat; |
| 11 | +import oracle.spatial.network.lod.NetworkAnalyst; |
| 12 | +import oracle.spatial.network.lod.LODNetworkManager; |
| 13 | +import oracle.spatial.network.lod.LinkCostCalculator; |
| 14 | +import oracle.spatial.network.lod.NetworkIO; |
| 15 | +import oracle.spatial.network.lod.PointOnNet; |
| 16 | +import oracle.spatial.network.lod.util.PrintUtility; |
| 17 | +import oracle.spatial.util.Logger; |
| 18 | +import oracle.spatial.network.lod.NetworkBuffer; |
| 19 | +import oracle.spatial.network.lod.NodeCostCalculator; |
| 20 | +import oracle.spatial.network.lod.config.ConfigManager; |
| 21 | +import oracle.spatial.network.lod.config.LODConfig; |
| 22 | + |
| 23 | +public class PersistentNetworkBuffer |
| 24 | +{ |
| 25 | + private static final NumberFormat formatter = new DecimalFormat("#.######"); |
| 26 | + |
| 27 | + private static NetworkAnalyst analyst; |
| 28 | + private static NetworkIO networkIO; |
| 29 | + |
| 30 | + private static void setLogLevel(String logLevel) |
| 31 | + { |
| 32 | + if("FATAL".equalsIgnoreCase(logLevel)) |
| 33 | + Logger.setGlobalLevel(Logger.LEVEL_FATAL); |
| 34 | + else if("ERROR".equalsIgnoreCase(logLevel)) |
| 35 | + Logger.setGlobalLevel(Logger.LEVEL_ERROR); |
| 36 | + else if("WARN".equalsIgnoreCase(logLevel)) |
| 37 | + Logger.setGlobalLevel(Logger.LEVEL_WARN); |
| 38 | + else if("INFO".equalsIgnoreCase(logLevel)) |
| 39 | + Logger.setGlobalLevel(Logger.LEVEL_INFO); |
| 40 | + else if("DEBUG".equalsIgnoreCase(logLevel)) |
| 41 | + Logger.setGlobalLevel(Logger.LEVEL_DEBUG); |
| 42 | + else if("FINEST".equalsIgnoreCase(logLevel)) |
| 43 | + Logger.setGlobalLevel(Logger.LEVEL_FINEST); |
| 44 | + else //default: set to ERROR |
| 45 | + Logger.setGlobalLevel(Logger.LEVEL_ERROR); |
| 46 | + } |
| 47 | + |
| 48 | + private static boolean tableExists(Connection conn, String tableName) |
| 49 | + { |
| 50 | + boolean result = false; |
| 51 | + try { |
| 52 | + Statement stmt = conn.createStatement(); |
| 53 | + String sqlStr = "SELECT COUNT(*) FROM TAB WHERE TNAME = '" + tableName.toUpperCase() + "'"; |
| 54 | + ResultSet rs = stmt.executeQuery(sqlStr); |
| 55 | + |
| 56 | + if ( rs.next() ) { |
| 57 | + int no = rs.getInt(1); |
| 58 | + if ( no != 0 ) |
| 59 | + result = true; |
| 60 | + } |
| 61 | + rs.close(); |
| 62 | + stmt.close(); |
| 63 | + } |
| 64 | + catch (Exception e) { |
| 65 | + e.printStackTrace(); |
| 66 | + } |
| 67 | + return result; |
| 68 | + } |
| 69 | + |
| 70 | +public static void main(String[] args) throws Exception |
| 71 | + { |
| 72 | + |
| 73 | + System.out.println("\n\ncreate reaching buffer\n\n"); |
| 74 | + |
| 75 | + String configXmlFile = "lod/networkbuffer/LODConfigs.xml"; |
| 76 | + String logLevel = "ERROR"; |
| 77 | + |
| 78 | + String dbUrl = ""; // jdbc url |
| 79 | + String dbUser = ""; |
| 80 | + String dbPassword = ""; |
| 81 | + |
| 82 | + String networkName = "HERE_SF_NET"; |
| 83 | + |
| 84 | + long startNodeId = 48523065; |
| 85 | + long linkId = 947224640; |
| 86 | + double percent = 0; |
| 87 | + |
| 88 | + long[] linkIds = {915260080, 711576509, -23618421, -127806843, 23618590, 23595880, 23594646, 23748128, 23611433, -127806839, 23612874, -916623909}; |
| 89 | + double[] percents = {0.2, 0.48, 0.27, 0.72, 0.63, 0.14, 0.1, 1, 0.29, 0.14, 0, 0}; |
| 90 | + |
| 91 | + |
| 92 | + int linkLevel = 1; //default link level |
| 93 | + // double cost = 10*1600; // 10 miles converted to meters |
| 94 | + double cost = 10*60; // 10 minutes converted to seconds |
| 95 | + String tableNamePrefix = "SF"; |
| 96 | + |
| 97 | + Connection conn = null; |
| 98 | + |
| 99 | + //get input parameters |
| 100 | + for(int i=0; i<args.length; i++) |
| 101 | + { |
| 102 | + if(args[i].equalsIgnoreCase("-dbUrl")) |
| 103 | + dbUrl = args[i+1]; |
| 104 | + else if(args[i].equalsIgnoreCase("-dbUser")) |
| 105 | + dbUser = args[i+1]; |
| 106 | + else if(args[i].equalsIgnoreCase("-dbPassword")) |
| 107 | + dbPassword = args[i+1]; |
| 108 | + else if(args[i].equalsIgnoreCase("-networkName") && args[i+1]!=null) |
| 109 | + networkName = args[i+1].toUpperCase(); |
| 110 | + else if(args[i].equalsIgnoreCase("-linkLevel")) |
| 111 | + linkLevel = Integer.parseInt(args[i+1]); |
| 112 | + else if(args[i].equalsIgnoreCase("-startNodeId")) |
| 113 | + startNodeId = Long.parseLong(args[i+1]); |
| 114 | + else if(args[i].equalsIgnoreCase("-cost:")) |
| 115 | + cost = Double.parseDouble(args[i]); |
| 116 | + else if(args[i].equalsIgnoreCase("-tableNamePrefix")) |
| 117 | + tableNamePrefix = args[i+1]; |
| 118 | + else if(args[i].equalsIgnoreCase("-configXmlFile")) |
| 119 | + configXmlFile = args[i+1]; |
| 120 | + else if(args[i].equalsIgnoreCase("-logLevel")) |
| 121 | + logLevel = args[i+1]; |
| 122 | + } |
| 123 | + |
| 124 | + // opening connection |
| 125 | + conn = LODNetworkManager.getConnection(dbUrl, dbUser, dbPassword); |
| 126 | + |
| 127 | + Statement stmt = conn.createStatement(); |
| 128 | + |
| 129 | + System.out.println("Network analysis for "+networkName); |
| 130 | + |
| 131 | + setLogLevel(logLevel); |
| 132 | + |
| 133 | + //load user specified LOD configuration (optional), |
| 134 | + //otherwise default configuration will be used |
| 135 | + InputStream config = ClassLoader.getSystemResourceAsStream(configXmlFile); |
| 136 | + LODNetworkManager.getConfigManager().loadConfig(config); |
| 137 | + LODConfig c = LODNetworkManager.getConfigManager().getConfig(networkName); |
| 138 | + //get network input/output object |
| 139 | + networkIO = LODNetworkManager.getCachedNetworkIO( |
| 140 | + conn, networkName, networkName, null); |
| 141 | + |
| 142 | + //get network analyst |
| 143 | + analyst = LODNetworkManager.getNetworkAnalyst(networkIO); |
| 144 | + LinkCostCalculator[] oldlccs = analyst.getLinkCostCalculators(); |
| 145 | + LinkCostCalculator[] lccs = {new LinkTravelTimeCalculator()}; |
| 146 | + try |
| 147 | + { |
| 148 | + |
| 149 | + |
| 150 | + analyst.setLinkCostCalculators(lccs); |
| 151 | + |
| 152 | + |
| 153 | + for (int i = 0; i < linkIds.length; i++) { |
| 154 | + int bufferId = i + 1; |
| 155 | + System.out.println("***** BEGIN: Network Buffer " + bufferId + " *****"); |
| 156 | + |
| 157 | + linkId = linkIds[i]; |
| 158 | + percent = percents[i]; |
| 159 | + |
| 160 | + PointOnNet[] startPoint = {new PointOnNet(linkId, percent)}; |
| 161 | + long startTime = System.currentTimeMillis(); |
| 162 | + NetworkBuffer buffer = analyst.reachingNetworkBuffer(startPoint, cost, null); |
| 163 | + long t1 = System.currentTimeMillis(); |
| 164 | + networkIO.writeNetworkBuffer(buffer, bufferId, tableNamePrefix); |
| 165 | + |
| 166 | + |
| 167 | + long endTime = System.currentTimeMillis(); |
| 168 | + |
| 169 | + System.out.println("Run times : "+" Total = "+(endTime-startTime) +" msec."+ |
| 170 | + " Analysis = "+(t1-startTime)+" msec."+" Persistence = "+ |
| 171 | + (endTime-t1)+" msec."); |
| 172 | + System.out.println("***** END: Network Buffer" + bufferId + " *****"); |
| 173 | + } |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + } |
| 178 | + catch (Exception e) |
| 179 | + { |
| 180 | + e.printStackTrace(); |
| 181 | + } |
| 182 | + |
| 183 | + |
| 184 | + if(conn!=null) |
| 185 | + try{conn.close();} catch(Exception ignore){} |
| 186 | + |
| 187 | + } |
| 188 | +} |
0 commit comments