The template that allows you to use any of these simple methods:
1) Select a layer you want to search in;
2) Define a search method and search figure;
3) Perform search.
First, you may need to see all the attached layers:
public void printAllLayers( Map map, JspWriter out) throws RMException, IOException { LayerList llist = map.getLayers(); Layer layer; for( int i=0; i < llist.getCount(); i++) { layer = llist.getLayer( i); out.println( i+". <b>'"+layer.getName()+"'</b> Visible: <b>" + layer.isVisible()+"</b><br>"); } }
Sample output:
0. 'My database' Visible: true
1. 'Cities' Visible: true
2. 'Business Listings' Visible: true
3. 'Exits' Visible: true
4. 'Airports' Visible: true
5. 'Landmarks' Visible: true
6. 'Arches, Craters, Geysers' Visible: true
7. 'Summits' Visible: true
8. 'Interstate Highways' Visible: true
9. 'Highways' Visible: true
10. 'Major Roads' Visible: true
11. 'Streets' Visible: true
12. 'Railroads' Visible: true
13. 'Minor Rivers, Creeks' Visible: true
14. 'State Borders' Visible: true
15. 'Lakes, Major Rivers' Visible: true
16. 'Parks, Forests' Visible: true
17. 'Landmark Boundaries' Visible: true
18. 'City Limits' Visible: true
19. 'Counties' Visible: true
20. 'States' Visible: true
Any one of the layers can be selected by either the layer name or the layer number.
Let's try to find, for example, all airports around Redlands, CA within specified radius.
There is a new feature in RouteMAP IMS version 3.0 that allows sorting the results
found within a circle by distance. This is one using the
SearchDef.setSearchMethod.
1) To find locations within a circle with a specified radius;
// get the layer Layer layer = map.getLayers().getLayerByName("Airports"); // create the SearchDef object SearchDef searchDef = new SearchDef(); //************************************************************************** // convert current units (miles or kilometers) to map units double radius = map.convertDistance( 20, map.getMeasureUnits(), MeasureUnit.MAPUNITS); GeoLocation center = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531); searchDef.setSearchMethod( SearchDef.SORT_DISTANCE); searchDef.addCircle(center.x, center.y, radius, 0); //************************************************************************** Recordset rs = layer.search(searchDef); // returns Recordset object // prints all records from the recordset if( rs != null && rs.getRecordsCount() != 0) { int recCount = rs.getRecordsCount(); int fieldCount = rs.getFields().getFieldCount(); out.println( "<table border=1 cellspacing=0 cellpadding=2>"); out.println( "<tr bgcolor='#DDDDDD'>"); for( int i = 0; i < fieldCount; i++) out.print("<th>" + rs.getFields().getFieldName(i) + "</th>"); out.println("</tr>"); for (int i = 0; i < recCount; i++) { rs.move(i); out.println("<tr>"); for (int j = 0; j < fieldCount; j++) { String value = rs.getAsString(j); if (value == "") value = " "; out.print("<td>" + value + "</td>"); } out.println("</tr>"); } out.println("</table>"); } <% public class GeoLocation { public String label; public double x; public double y; GeoLocation (Map map, String iLabel, double iLat, double iLon) throws RMException { Projection proj = map.getProjection(); GeoPoint pt = proj.project( iLat, iLon); label = iLabel; x = pt.x; y = pt.y; } } %>
Output:
Name | Hub Size | State | Shape |
---|---|---|---|
Flabob | CA | shape | |
Redlands Muni | CA | shape | |
Rialto Muni /miro Fld/ | CA | shape | |
San Bernardino International | CA | shape | |
March Air Force Base | G | CA | shape |
Riverside Muni | G | CA | shape |
Banning Muni | CA | shape |
You can easily modify this code sample to find locations by the other methods. Simply replace
the code outlined by asterisks above with the code below.
2) To find locations within a polygon:
GeoLocation locs[] = new GeoLocation[5]; locs[0] = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531); locs[1] = new GeoLocation( map, "Loma Linda, CA", 34.0484, -117.2629); locs[2] = new GeoLocation( map, "Bloomington, CA", 34.0704, -117.3976); locs[3] = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046); locs[4] = new GeoLocation( map, "Highland, CA", 34.1282, -117.2106); GeoPointsImpl gp = new GeoPointsImpl(); for(int i = 0; i < locs.length; i++) gp.addPoint( locs[i].x, locs[i].y); searchDef.addPolygon( gp, 0);3) To find locations within a rectangle:
GeoLocation locs[] = new GeoLocation[2]; locs[0] = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046); locs[1] = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531); GeoRectangle rc = new GeoRectangle(); rc.left = locs[0].x; rc.top = locs[0].y; rc.right = locs[1].x; rc.bottom = locs[1].y; searchDef.addRectangle( rc, 0);4) To find locations along a line:
GeoLocation locs[] = new GeoLocation[2]; locs[0] = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531); locs[1] = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046); GeoPointsImpl gp = new GeoPointsImpl(); for(int i = 0; i < locs.length; i++) gp.addPoint( locs[i].x, locs[i].y); searchDef.addLineBuffer( gp, map.convertDistance( 10, map.getMeasureUnits(), MeasureUnit.MAPUNITS), 0);5) To find locations along a route;
GeoLocation stops[] = new GeoLocation[2]; stops[0] = new GeoLocation( map, "Redlands, CA", 34.0528, -117.1531); stops[1] = new GeoLocation( map, "San Bernardino, CA", 34.1214, -117.3046); // see the Routing section for details String routeID = findRoute( map, stops, 50, RoutingProblem.QUICKEST, false); searchDef.addRouteBuffer( routeID, map.convertDistance( 10, map.getMeasureUnits(), MeasureUnit.MAPUNITS), 0);