Search at Point – Java-Beispiel
Dieses Java-Beispiel veranlasst den Feature-Dienst zum Ausführen eines „Search at Point“-Aufrufs. „Search at Point“ ist, bei Anwendung auf eine Tabelle mit Polygonen, eine „Point in Polygon“-Methode.
Weitere Informationen zum Erstellen der Stub-Klassen für den Zugriff auf den Feature-Dienst finden Sie unter Generieren des Stub-Codes.
import com.mapinfo.midev.service.feature.v1.SearchAtPointRequest;
import com.mapinfo.midev.service.feature.v1.SearchAtPointResponse;
import com.mapinfo.midev.service.feature.ws.v1.FeatureService;
import com.mapinfo.midev.service.feature.ws.v1.FeatureServiceInterface;
import com.mapinfo.midev.service.feature.ws.v1.ServiceException;
import com.mapinfo.midev.service.geometries.v1.Point;
import com.mapinfo.midev.service.geometries.v1.Pos;
import com.mapinfo.midev.service.table.v1.NamedTable;
import com.mapinfo.midev.service.table.v1.Table;
import javax.xml.ws.BindingProvider;
import java.util.Map;
public final class FeatureServiceSample {
// username with the authority to call the Feature service
private static final String USERNAME = "admin";
// password of the caller
private static final String PASSWORD = "admin";
public static void main(String[] args) throws ServiceException {
// get the endpoint class
FeatureServiceInterface featureServiceInterface = new FeatureService().getFeatureServiceInterface();
// if authentication is enabled in Spectrum then the following is required
Map<String, Object> requestContext = ((BindingProvider)featureServiceInterface).getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, USERNAME);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);
// start assembling the request
SearchAtPointRequest searchAtPointRequest = new SearchAtPointRequest();
// create the search point
{
Point point = new Point();
point.setSrsName("epsg:4326");
Pos pos = new Pos();
pos.setX(-75.66);
pos.setY(47.88);
point.setPos(pos);
searchAtPointRequest.setPoint(point);
}
// set the named table
{
NamedTable table = new NamedTable();
table.setName("/Samples/NamedTables/USA");
searchAtPointRequest.setTable(table);
}
// send the request
SearchAtPointResponse searchAtPointResponse = featureServiceInterface.searchAtPoint(searchAtPointRequest);
// do what you want with the response ...
}
}