Getting the features information |
The getFeatureInfo(String version, WMSQueryParameter wmsQueryParam) method of the WMS interface can get the feature inforamtion by passing in the WMS version number and WMS query parameters. SuperMap iServer defines the WMSQueryParameter object type to store WMS query parameters.
Add the getFeatureInfo method in the WMSClientSample class, and add the corresponding code in the Main function to output the results.
// Get the feature information of the map
public WMSFeatureInfo[] getFeatureInfo() {
WMSFeatureInfo[] wmsFeatureInfos = null;
// Construct the WMS query parameter object
WMSQueryParameter wmsQueryParameter = new WMSQueryParameter();
// WMS service version number
String wmsVersion = "1.1.1";
wmsQueryParameter.mapName = "China";
wmsQueryParameter.entireBounds = new Rectangle2D(-180, -90, 180, 90);
wmsQueryParameter.bounds = new Rectangle2D(-180, -90, 180, 90);
wmsQueryParameter.layers = new String[1];
wmsQueryParameter.layers[0] = "World_Division_pl@China";
wmsQueryParameter.srs = "EPSG:4326";
wmsQueryParameter.width = 800;
wmsQueryParameter.height = 400;
wmsQueryParameter.queryLayers = new String[1];
wmsQueryParameter.queryLayers[0] = "World_Division_pl@China"
wmsQueryParameter.x = 650;
wmsQueryParameter.y = 150;
try {
wmsFeatureInfos = wmsClient.getFeatureInfo(wmsVersion, wmsQueryParameter);
} catch (Exception e) {
e.printStackTrace();
}
return wmsFeatureInfos;
}
public static void main(String[] args) {
WMSClientSample wmsClientSample = new WMSClientSample();
// Output the service title and the map title
WMSCapabilities capabilities = wmsClientSample.getCapabilities();
String wmsTitle = capabilities.serviceDescription.title;
String mapTitle = capabilities.mapTitle;
System.out.println("WMS Title is " + wmsTitle);
System.out.println("MapTitle is " + mapTitle);
// Output the map
byte[] bytes = wmsClientSample.getMap();
String fileName = "d:/map.png";
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(fileName);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
outputStream.write(bytes);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Please open d:/map.png to see the map");
// Output the feature information
WMSFeatureInfo[] wmsFeatureInfo = wmsClientSample.getFeatureInfo();
int length = wmsFeatureInfo.length;
System.out.println("Feature Info: ");
for (int i=0; i<length; i++) {
String[] fieldNames = wmsFeatureInfo[i].fieldNames;
String[] fieldValues = wmsFeatureInfo[i].fieldValues;
int nameLength = fieldNames.length;
for (int j=0; j<nameLength; j++) {
String name = fieldNames[j];
String value = fieldValues[j];
System.out.println(name + " = " + value);
}
}
}
Before running the WMSClientSample, you need to ensure that the service http://localhost:8090/iserver/services/map-china400/wms111/China has already been started.
After compiling the WMSClientSample project, right-click the WMSClientSample project, and then select Run as > Java Application to run the Java application to display the feature information, as shown below, on the console.
SMAREA = 1.6060069623493825E15
SMID = 1
SMPERIMETER = 1.6030006674231339E8
SMUSERID = 0