Search at Point – exemple Java

Cet exemple Java appelle Feature Service pour effectuer un appel Search at Point. La méthode Search at Point, si elle est utilisée sur une table contenant des polygones, est une méthode Point In Polygon.

Pour générer les classes stub permettant d'accéder à Feature Service, reportez-vous à la section Génération de code stub

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 ...

	}

}