Search at Point - Java Example

This Java example calls the Feature service to do a Search at Point call. The Search at Point, when used against a table with polygons, is a point in polygon method.

To generate the stub classes to access the Feature Service, see Generating Stub Code

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

	}

}