/[projects]/dao/FuldDaekningWorker/src/main/java/dk/daoas/fulddaekning/osrm/OSRMHelper.java
ViewVC logotype

Diff of /dao/FuldDaekningWorker/src/main/java/dk/daoas/fulddaekning/osrm/OSRMHelper.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2741 by torben, Tue Oct 6 21:26:55 2015 UTC revision 2749 by torben, Thu Oct 8 14:27:54 2015 UTC
# Line 27  import com.google.gson.Gson; Line 27  import com.google.gson.Gson;
27  import dk.daoas.fulddaekning.Adresse;  import dk.daoas.fulddaekning.Adresse;
28  import dk.daoas.fulddaekning.HttpUtil;  import dk.daoas.fulddaekning.HttpUtil;
29    
30    /*
31  import dk.thoerup.osrmbinding.OSRMBinding;  import dk.thoerup.osrmbinding.OSRMBinding;
32  import dk.thoerup.osrmbinding.ViarouteResult;  import dk.thoerup.osrmbinding.ViarouteResult;
33    */
34    
35  public class OSRMHelper {  public class OSRMHelper {
36            
37            private static final boolean ENABLE_OSRM = false;
38    
39    
40          final static Logger logger = Logger.getLogger( OSRMHelper.class.toString() );          final static Logger logger = Logger.getLogger( OSRMHelper.class.toString() );
41    
42          Gson gson = new Gson();          Gson gson = new Gson();
43    
44          static OSRMBinding binding = null;          //static OSRMBinding binding = null;
45    
46          final String host = "127.0.0.1";          //final String host = "127.0.0.1";
47            final String host = "10.30.2.103";
48          final int port = 5000;          final int port = 5000;
49          final String base_url = "http://" + host + ":" + port;          final String base_url = "http://" + host + ":" + port;
50    /*
51          private static synchronized void initOsrm() {          private static synchronized void initOsrm() {
52                  if (binding == null) {                  if (binding == null) {
53                          binding = new OSRMBinding("/home/openstreetmap/denmark-latest.osrm");                          binding = new OSRMBinding("/home/openstreetmap/denmark-latest.osrm");
54                  }                  }
55          }          }
56    */
57    
58          public Adresse getNearestTableHttp(Adresse a1, Collection<Adresse> haystack) {          public Adresse getNearestTableHttp(Adresse a1, Collection<Adresse> haystack) {
59    
# Line 93  public class OSRMHelper { Line 99  public class OSRMHelper {
99    
100                  return bedsteAdresse;                  return bedsteAdresse;
101          }          }
102            
103            
104            
105    /*
106          public Adresse getNearestTableJni(Adresse a1, Collection<Adresse> haystack) {          public Adresse getNearestTableJni(Adresse a1, Collection<Adresse> haystack) {
107                  if (binding == null) {                  if (binding == null) {
108                          initOsrm();                          initOsrm();
# Line 133  public class OSRMHelper { Line 142  public class OSRMHelper {
142                  }                  }
143    
144                  return bedsteAdresse;                  return bedsteAdresse;
145            }*/
146            
147    
148            public Adresse getNearestMultitargetHttp(Adresse a1, Collection<Adresse> haystack) {
149    
150                    Adresse bedsteAdresse = null;
151    
152                    Adresse hayArray[] = new Adresse[ haystack.size() ];
153                    haystack.toArray(hayArray);
154    
155                    StringBuilder sb = new StringBuilder();
156                    sb.append(base_url);
157                    sb.append("/multitarget?loc=").append(a1.latitude).append(",").append(a1.longitude);
158    
159                    for(int i = 0; i<hayArray.length; i++) {
160                            Adresse a = hayArray[i];
161                            sb.append("&loc=").append( a.latitude ).append(",").append(a.longitude);
162                    }
163    
164                    try {
165                            String txtResponse = HttpUtil.getContentString(sb.toString(), 500, "UTF-8");
166                            OSRMMultiTarget table = gson.fromJson(txtResponse, OSRMMultiTarget.class);
167    
168    
169                            double bedsteAfstand = Double.MAX_VALUE;
170    
171                            for (int i = 1; i<table.distances.length; i++) {
172                                    if (table.distances[i].distance < bedsteAfstand) {
173                                            bedsteAfstand = table.distances[i].distance;
174                                            bedsteAdresse = hayArray[i];
175                                    }
176                            }
177    
178                    } catch (Exception e) {
179                            logger.log(Level.SEVERE, "Lookup failed", e);
180                            System.exit(1);                
181                    }
182    
183    
184                    return bedsteAdresse;
185          }          }
186                    
187          public Adresse getNearestViarouteHttp(Adresse a1, Collection<Adresse> haystack) {          public Adresse getNearestViarouteHttp(Adresse a1, Collection<Adresse> haystack) {
# Line 200  public class OSRMHelper { Line 249  public class OSRMHelper {
249                  return bedsteAdresse;                  return bedsteAdresse;
250          }          }
251    
252            /*      
253          public Adresse getNearestViarouteJni(Adresse a1, Collection<Adresse> haystack) {          public Adresse getNearestViarouteJni(Adresse a1, Collection<Adresse> haystack) {
254    
255                  if (binding == null) {                  if (binding == null) {
# Line 239  public class OSRMHelper { Line 288  public class OSRMHelper {
288                          }                                                }                      
289    
290                  return bedsteAdresse;                  return bedsteAdresse;
291          }          }*/
292  }  }
293    
294    

Legend:
Removed from v.2741  
changed lines
  Added in v.2749

  ViewVC Help
Powered by ViewVC 1.1.20