Search in sources :

Example 1 with IPageLayout

use of com.esri.arcgis.carto.IPageLayout in project sldeditor by robward-scisys.

the class ImportMXD method convert.

/**
 * Read mxd and write out the json file.
 *
 * @param fileData the file data
 */
public void convert(FileData fileData) {
    if (fileData == null) {
        return;
    }
    // Get all the known conversion classes
    RegisterClasses.initialise(data);
    System.out.println("Reading MXD : " + fileData.getInputFile().getAbsolutePath());
    SystemWin sWin = new SystemWin();
    Pointer obj = sWin.getDesktopWindow();
    int hWnd = obj.getInt(0);
    try {
        System.out.println("Opening mxd...");
        IMapDocument mapDocument = new MapDocument();
        String password = null;
        mapDocument.open(fileData.getInputFile().getAbsolutePath(), password);
        IPageLayout iPageLayout = mapDocument.getPageLayout();
        IActiveView activeView = (IActiveView) iPageLayout;
        IMap iMap = activeView.getFocusMap();
        activeView.activate(hWnd);
        JsonArray jsonLayerlist = new JsonArray();
        int count = 1;
        int total = 0;
        // Find total number of layers
        IEnumLayer layerEnum = iMap.getLayers(null, true);
        ILayer layer = layerEnum.next();
        while (layer != null) {
            layer = layerEnum.next();
            total++;
        }
        // Now work through all the layers
        layerEnum = iMap.getLayers(null, true);
        layer = layerEnum.next();
        ParseLayer parseLayer = new ParseLayer(data);
        while (layer != null) {
            parseLayer.convertLayer(count, total, jsonLayerlist, layer, (Map) iMap);
            layer = layerEnum.next();
            count++;
        }
        JsonObject jsonMXDObject = new JsonObject();
        jsonMXDObject.addProperty("mxd", mapDocument.getDocumentFilename());
        jsonMXDObject.add("layers", jsonLayerlist);
        outputJSON(jsonMXDObject, fileData.getOutputFile());
        System.out.println("Written JSON file : " + fileData.getOutputFile().getAbsolutePath());
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IMapDocument(com.esri.arcgis.carto.IMapDocument) IPageLayout(com.esri.arcgis.carto.IPageLayout) UnknownHostException(java.net.UnknownHostException) ILayer(com.esri.arcgis.carto.ILayer) JsonObject(com.google.gson.JsonObject) Pointer(com.sun.jna.Pointer) IActiveView(com.esri.arcgis.carto.IActiveView) IOException(java.io.IOException) JsonArray(com.google.gson.JsonArray) IMap(com.esri.arcgis.carto.IMap) IMapDocument(com.esri.arcgis.carto.IMapDocument) MapDocument(com.esri.arcgis.carto.MapDocument) IEnumLayer(com.esri.arcgis.carto.IEnumLayer)

Aggregations

IActiveView (com.esri.arcgis.carto.IActiveView)1 IEnumLayer (com.esri.arcgis.carto.IEnumLayer)1 ILayer (com.esri.arcgis.carto.ILayer)1 IMap (com.esri.arcgis.carto.IMap)1 IMapDocument (com.esri.arcgis.carto.IMapDocument)1 IPageLayout (com.esri.arcgis.carto.IPageLayout)1 MapDocument (com.esri.arcgis.carto.MapDocument)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Pointer (com.sun.jna.Pointer)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1