Select to view content in your preferred language

export map (layout) via Python

600
2
05-20-2010 03:49 AM
MichaelaRepkova
Emerging Contributor
Hi,
I'm new in python and would like to know if it's possible to export map (layout) as a jpg or png programatically in Python. I'm using ArcMap 9.3.1 and Python 2.5
0 Kudos
2 Replies
ChrisMathers
Deactivated User
I dont believe there is. I think there is that functionality in 10 with the new arcpy module.
0 Kudos
MichaelaRepkova
Emerging Contributor
I figured out this problem with java..

public class zrazky {

/**
  * @param args
  *
  */
  

public static void main(String[] args)  {

  ServerInitializer serverInitializer = null;
  ServerConnection connection = null;
  IMapServer mapServer = null;
  IMapServerObjects mapServerObjects = null;
  IImageType imageType = null;
  IImageDisplay imageDisplay = null;
  IImageDescription imageDescription = null;
  IMapServerInfo mapServerInfo = null;
  IMapDescription mapDescription = null;
  String mapLayoutUrl = null;
  IImageResult mapLayoutImage = null;
 
 
  try
  {
    
   Properties props = new Properties ();
   props.load(new FileInputStream(new File("properties.txt")));
 
      
   String domena = "domena";
   String val1 = props.getProperty(domena) ;
   String meno = "login";
   String val2 = props.getProperty(meno) ;  
   String heslo = "heslo";
   String val3 = props.getProperty(heslo) ;  
   String pocitac = "pocitac";
   String val4 = props.getProperty(pocitac) ;
   String output = "output_zrazky";
   String val5 = props.getProperty(output);
  
   
       
   serverInitializer = new ServerInitializer();
   serverInitializer.initializeServer(val1,val2,val3);
     
   connection = new ServerConnection();
   connection.connect(val4);

  
  
  
   IServerObjectManager som = connection.getServerObjectManager();
      IServerContext serverContext = som.createServerContext("koak_gis031a3", "MapServer");
      MapServer ms = (MapServer)serverContext.getServerObject();
  
      
     mapServer = new IMapServerProxy(serverContext.getServerObject());
     mapServerObjects = new IMapServerObjectsProxy(mapServer);

     imageType = new IImageTypeProxy(serverContext.createObject(ImageType.getClsid()));
     imageType.setFormat(esriImageFormat.esriImageJPG);
     imageType.setReturnType(esriImageReturnType.esriImageReturnURL);
   
    
     imageDisplay = new IImageDisplayProxy(serverContext.createObject(ImageDisplay.getClsid()));
     imageDisplay.setHeight(700);
     imageDisplay.setWidth(1100);
     imageDisplay.setDeviceResolution(100.0);

     imageDescription = new IImageDescriptionProxy(serverContext.createObject(ImageDescription.getClsid()));
     imageDescription.setDisplay(imageDisplay);
     imageDescription.setType(imageType);

     mapServerInfo = mapServer.getServerInfo(mapServer.getDefaultMapName());
     mapDescription = mapServerInfo.getDefaultMapDescription();
              
           IMapServerLayout mapServerLayout = new IMapServerLayoutProxy(mapServer);
           IPageDescription pageDescription = ms.getDefaultPageDescription();
                 
           ILayoutImage layoutImage = mapServerLayout.exportLayout(pageDescription, imageDescription);
           mapLayoutUrl = layoutImage.getURL();
         
          
           System.out.println("Map Layout URL: " + mapLayoutUrl );
     
           Calendar cal = new GregorianCalendar();
           int month = cal.get(Calendar.MONTH);
           int year = cal.get(Calendar.YEAR);
           int day = cal.get(Calendar.DAY_OF_MONTH);
              
           
           URL url = new URL(mapLayoutUrl);
           ReadableByteChannel rbc = Channels.newChannel(url.openStream());
           FileOutputStream fos = new FileOutputStream(val5 + year+ "_" + (month+1) +"_"+ day + ".jpg");
           fos.getChannel().transferFrom(rbc, 0, 1 << 24);
          
          
  }
            
             catch (AutomationException ae)
       {
           System.err.println("Caught AutomationException: " + ae.getMessage() + "\n");
           ae.printStackTrace();
       }

       catch (IOException e)
       {
           System.err.println("Caught IOException: " + e.getMessage() + "\n");
           e.printStackTrace();
       }
      }
}  

made jar file and put it to the python code:

if __name__ == "__main__":
   startingDir = os.getcwd() # save our current directory
   testDir = "D:\\espritAGS\\koak\\interpolacia\\java\\" # note that \ is windows specific, and we have to escape it
   os.chdir(testDir) # change to our test directory
   os.system("C:\\jdk1.6.0_01\\bin\\java -jar zrazky.jar required_paramter.ext")
   os.chdir(startingDir) # change back to where we started
0 Kudos