Mapping


In this topic


Overview

The capabilities of an ArcGIS Server map service using the SOAP application programming interface (API) are defined by the MapServerBindingStub class methods. These methods initiate stateless requests to a map service and return results. The capabilities of MapServerBindingStub mirror the stateless ArcObjects interfaces implemented by the map server objects IMapServer and ITiledMapServer.
Two important differences between the SOAP proxy and ArcObjects Component Object Model (COM) proxies are as follows:
  • The MapServerBindingStub object is a native Java object. IMapServer and ITiledMapServer are interfaces to a remote COM object on the geographic information system (GIS) server (ArcSOC.exe).
  • Input parameters and output results share a common naming scheme but are different object types. The MapServerBindingStub object uses native Java objects (value objects), while the server object interfaces use references to remote COM objects on the GIS server. For example, both share the method ExportMapImage. However, MapServerBindingStub takes two input parameters, native Java objects of type MapDescription and ImageDescription. The ArcObjects IMapServer interface takes two input parameters—interface references to COM objects running on the GIS server of type IMapDescription and IImageDescription. MapServerBindingStub returns a native Java MapImage value object, while IMapServer returns an IMapImage reference to a COM object on the GIS server.
The following sample code snippets illustrate the use of selected methods to accomplish a common action. The samples use the Web service SOAP proxy (MapServerProxy) and value objects included with the Web Application Developer Framework (ADF) ESRI.ArcGIS.ADF.ArcGISServer library. The same patterns apply to dynamically generated proxy classes and value objects except that the proxy class name is <service name>_MapServer and the namespace for the proxy and value objects is user defined.
The proxy and value objects for an ArcGIS Server service need only be generated once per service type. For example, once the Web service proxy and value objects for an ArcGIS Server map service have been created, they can be reused for other ArcGIS Server Web map services. For dynamic proxy classes, use the setURL method to define the Web service endpoint for the ArcGIS Server Web map service you want to use. For Web ADF proxy classes that are pre-generated, the proxy constructor requires a URL input parameter to define the Web service endpoint for the ArcGIS Server Web map service you want to use. The same applies to geocode services, geoprocessing services, and so on.

Creating a map image

The following sample code shows how to create a map image.
[Java]
String endpoint = "http://myserver:8399/arcgis/services/my_map_service/MapServer";
MapServerBindingStub mapserver = new MapServerBindingStub(new java.net.URL(endpoint),
    null);
MapServerInfo mapinfo = mapserver.getServerInfo(mapserver.getDefaultMapName());
MapDescription mapdesc = mapinfo.getDefaultMapDescription();
ImageType imgtype = new ImageType();
imgtype.setImageFormat(EsriImageFormat.esriImageJPG);
imgtype.setImageReturnType(EsriImageReturnType.esriImageReturnURL);
ImageDisplay imgdisp = new ImageDisplay();
imgdisp.setImageHeight(500);
imgdisp.setImageWidth(600);
imgdisp.setImageDPI(96);
ImageDescription imgdesc = new ImageDescription();
imgdesc.setImageDisplay(imgdisp);
imgdesc.setImageType(imgtype);
MapImage mapimg = mapserver.exportMapImage(mapdesc, imgdesc);

Adding graphics to a map image

The following sample code shows how to add graphics (point, line, polygon) to a map image using the SOAP API based on Axis.  Please refer to the Migration document on how to make appropriate changes to the code snippet below to take advantage of the new ArcGIS Java Web Services (AgsJWS) toolkit. 
[Java]
try{
    String endpoint = 
        "http://myserver:8399/arcgis/services/my_map_service/MapServer";
    MapServerBindingStub mapserver = new MapServerBindingStub(new java.net.URL
        (endpoint), null);
    MapServerInfo mapinfo = mapserver.getServerInfo(mapserver .getDefaultMapName());
    MapDescription mapdesc = mapinfo.getDefaultMapDescription();
    ImageType it = new ImageType();
    it.setImageFormat(EsriImageFormat.esriImageJPG);
    it.setImageReturnType(EsriImageReturnType.esriImageReturnURL);
    ImageDisplay idisp = new ImageDisplay();
    idisp.setImageHeight(500);
    idisp.setImageWidth(600);
    idisp.setImageDPI(96);
    ImageDescription idesc = new ImageDescription();
    idesc.setImageDisplay(idisp);
    idesc.setImageType(it);
    // Need to pass org.apache.axis.types.UnsignedByte.
    // Use a primititive if using the new ArcGIS Java Web Services Toolkit
    RgbColor rgb = new RgbColor();
    rgb.setRed(new UnsignedByte(255));
    rgb.setGreen(new UnsignedByte(0));
    rgb.setBlue(new UnsignedByte(0));
    rgb.setAlphaValue(new UnsignedByte(255));
    PointN pnt1 = new PointN();
    pnt1.setX( - 120);
    pnt1.setY(35);
    PointN pnt2 = new PointN();
    pnt2.setX( - 110);
    pnt2.setY(30);
    PointN pnt3 = new PointN();
    pnt3.setX( - 80);
    pnt3.setY(35);
    PointN[] pnts1 = new PointN[3];
    pnts1[0] = pnt1;
    pnts1[1] = pnt2;
    pnts1[2] = pnt3;
    // *** Point ***
    SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
    sms.setStyle(EsriSimpleMarkerStyle.esriSMSDiamond);
    sms.setColor(rgb);
    sms.setOutlineColor(rgb);
    sms.setSize(20.0);
    MarkerElement marker = new MarkerElement();
    marker.setSymbol(sms);
    marker.setPoint(pnt1);
    mapdesc = addGraphics(mapdesc, marker);
    // *** Polyline ***
    RgbColor rgb1 = new RgbColor();
    rgb1.setRed(new UnsignedByte(0));
    rgb1.setGreen(new UnsignedByte(0));
    rgb1.setBlue(new UnsignedByte(255));
    rgb1.setAlphaValue(new UnsignedByte(255));
    Path path1 = new Path();
    path1.setPointArray(pnts1);
    Path[] paths = new Path[1];
    paths[0] = path1;
    PolylineN pline = new PolylineN();
    pline.setPathArray(paths);
    pline.setHasID(false);
    pline.setHasM(false);
    pline.setHasZ(false);
    pline.setSpatialReference(mapinfo.getSpatialReference());
    pline.setExtent(mapinfo.getFullExtent());
    SimpleLineSymbol sls = new SimpleLineSymbol();
    sls.setColor(rgb1);
    sls.setStyle(EsriSimpleLineStyle.esriSLSSolid);
    sls.setWidth(2);
    LineElement le = new LineElement();
    le.setLine(pline);
    le.setSymbol(sls);
    mapdesc = addGraphics(mapdesc, le);
    // *** Polygon ***
    RgbColor rgb2 = new RgbColor();
    rgb2.setRed(new UnsignedByte(0));
    rgb2.setGreen(new UnsignedByte(255));
    rgb2.setBlue(new UnsignedByte(0));
    rgb2.setAlphaValue(new UnsignedByte(255));
    Ring[] rings1 = new Ring[1];
    Ring ring1 = new Ring();
    ring1.setPointArray(pnts1);
    PolygonN polygon = new PolygonN();
    rings1[0] = ring1;
    polygon.setRingArray(rings1);
    polygon.setExtent(mapdesc.getMapArea().getExtent());
    polygon.setHasID(false);
    polygon.setHasM(false);
    polygon.setHasZ(false);
    polygon.setSpatialReference(mapdesc.getSpatialReference());
    SimpleFillSymbol sfs = new SimpleFillSymbol();
    sfs.setStyle(EsriSimpleFillStyle.esriSFSCross);
    sfs.setColor(rgb2);

    PolygonElement pe = new PolygonElement();
    pe.setSymbol(sfs);
    pe.setPolygon(polygon);
    mapdesc = addGraphics(mapdesc, pe);
    // Create the map image.
    MapImage mapimg = mapserver.exportMapImage(mapdesc, idesc);

}

catch (Exception e){
    // TODO Auto-generated catch block
    e.printStackTrace();
}

........... private static MapDescription addGraphics(MapDescription mapDescription,
    GraphicElement ge){
    if (mapDescription.getCustomGraphics() != null){
        GraphicElement[] oldges = mapDescription.getCustomGraphics();
        int cnt = oldges.length;
        GraphicElement[] newges = new GraphicElement[cnt + 1];
        System.arraycopy(oldges, 0, newges, 0, cnt);

        newges[cnt] = ge;
        mapDescription.setCustomGraphics(newges);
    }
    else{
        GraphicElement[] ges = new GraphicElement[1];
        ges[0] = ge;
        mapDescription.setCustomGraphics(ges);
    }
    return mapDescription;
}

Querying a layer

The following sample code shows how to query a layer to show selected features and to iterate through a record set.
[Java]
String endpoint = "http://myserver:8399/arcgis/services/my_map_service/MapServer";
MapServerBindingStub mapserver = new MapServerBindingStub(new java.net.URL(endpoint),
    null);
MapServerInfo mapinfo = mapserver.getServerInfo(mapserver.getDefaultMapName());
MapDescription mapdesc = mapinfo.getDefaultMapDescription();
ImageType itype = new ImageType();
itype.setImageFormat(EsriImageFormat.esriImageJPG);
itype.setImageReturnType(EsriImageReturnType.esriImageReturnURL);
ImageDisplay idisp = new ImageDisplay();
idisp.setImageHeight(500);
idisp.setImageWidth(600);
idisp.setImageDPI(96);
ImageDescription idesc = new ImageDescription();
idesc.setImageDisplay(idisp);
idesc.setImageType(itype);
MapServerInfo msi = mapserver.getServerInfo(mapserver.getDefaultMapName());
LayerDescription[] layerdescs = mapdesc.getLayerDescriptions();
// Change selection symbol and color of feature layer.
LayerDescription layer0 = layerdescs[1];
// Define spatial filter to select features.
PointN pnt1 = new PointN();
pnt1.setX( - 100);
pnt1.setY(30);
PointN pnt2 = new PointN();
pnt2.setX( - 100);
pnt2.setY(35);
PointN pnt3 = new PointN();
pnt3.setX( - 90);
pnt3.setY(35);
PointN pnt4 = new PointN();
pnt4.setX( - 90);
pnt4.setY(30);
PointN[] pnts1 = new PointN[4];
pnts1[0] = pnt1;
pnts1[1] = pnt2;
pnts1[2] = pnt3;
pnts1[3] = pnt4;
Ring[] rings1 = new Ring[1];
Ring ring1 = new Ring();
ring1.setPointArray(pnts1);
PolygonN polygon = new PolygonN();
rings1[0] = ring1;
polygon.setRingArray(rings1);
SpatialFilter sf = new SpatialFilter();
sf.setFilterGeometry(polygon);
sf.setGeometryFieldName("SHAPE");
sf.setWhereClause("");
sf.setSearchOrder(EsriSearchOrder.esriSearchOrderAttribute);
sf.setSpatialRelDescription("");
sf.setSpatialRel(EsriSpatialRelEnum.esriSpatialRelIntersects);
// Define selection symbol and color for featureLayer2.
// When setting the color values, pass org.apache.axis.types.UnsignedByte 
// instead of int.
RgbColor irgbc = new RgbColor();
irgbc.setRed(new UnsignedByte(255));
irgbc.setGreen(new UnsignedByte(0));
irgbc.setBlue(new UnsignedByte(0));
irgbc.setAlphaValue(new UnsignedByte(255));
SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
sms.setStyle(EsriSimpleMarkerStyle.esriSMSDiamond);
sms.setColor(irgbc);
sms.setOutlineColor(irgbc);
layer0.setSelectionSymbol(sms);
// #1: Query layer and set selected features.
FIDSet ifid = mapserver.queryFeatureIDs(mapdesc.getName(), layer0.getLayerID(), sf);
layer0.setSelectionFeatures(ifid.getFIDArray());
// Create the map image.
MapImage mapimg = mapserver.exportMapImage(mapdesc, idesc);

//#2: Query layer and iterate through queried records.
RecordSet recordset = mapserver.queryFeatureData(mapdesc.getName(),
    layer0.getLayerID(), sf);
//foreach (Field f in recordset.Fields.FieldArray)
for (Field f: recordset.getFields().getFieldArray()){
    // List fields.
    System.out.println(f.getName());
}

for (Record record: recordset.getRecords()){
    Object[] os = record.getValues();
    for (Object o: os){
        System.out.println(o.toString());
    }
}


See Also:

MapServer