⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linksde.java

📁 使用ArcEngine java api 开发的通过arcsde读取空间数据
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

//LinkSde.java
/*
 * ArcGIS Engine Developer Sample
 * Application Name: LinkSde.java
 */

package com.esri.arcgis.samples.geodatabase.accessingdata;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;

import com.esri.arcgis.beans.map.IMapControlEvents2Adapter;
import com.esri.arcgis.beans.map.IMapControlEvents2OnAfterScreenDrawEvent;
import com.esri.arcgis.beans.map.IMapControlEvents2OnBeforeScreenDrawEvent;
import com.esri.arcgis.beans.map.IMapControlEvents2OnMouseDownEvent;
import com.esri.arcgis.beans.map.IMapControlEvents2OnMouseMoveEvent;
import com.esri.arcgis.beans.map.IMapControlEvents2OnMouseUpEvent;
import com.esri.arcgis.beans.map.MapControl;
import com.esri.arcgis.carto.esriViewDrawPhase;
import com.esri.arcgis.geometry.IEnvelope;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.systemUI.esriControlsMousePointer;

import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import com.esri.arcgis.geodatabase.esriDatasetType;
import com.esri.arcgis.geodatabase.IFeatureWorkspace;
import com.esri.arcgis.geodatabase.IFeatureClass;
import com.esri.arcgis.geodatabase.IWorkspaceProxy;
import com.esri.arcgis.geodatabase.IFeatureWorkspaceProxy;
import com.esri.arcgis.geodatabase.IEnumDatasetName;
import com.esri.arcgis.geodatabase.IWorkspace;
import com.esri.arcgis.geodatabase.IWorkspaceFactory;
import com.esri.arcgis.geodatabase.esriVersionAccess;
import com.esri.arcgis.system.IPropertySet;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.carto.IFeatureLayer;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.beans.map.MapControl;
import java.io.IOException;
import com.linar.jintegra.AutomationException;


/**
 * Description:This sample primarily demonstrates setting the MapControl's Rotation property, and
 *    secondly demonstrates setting the MapControl MouseIcon and MousePointer properties.<p/>
 *
 *    The file chooser dialog allows users to search and
 *    select map documents, which are validated and loaded into the MapControl using
 *    the CheckMxFile and LoadMxFile methods. The OnBeforeScreenDraw and OnAfterScreenDraw
 *    events are used to set the MousePointer while the display is refreshing due to Extent
 *    changes.
 *
 *    The OnMouseDown event uses either the TrackRectangle method to zoom in or the
 *    IScreenDisplay RotateStart method to start rotating around the centre of the
 *    display based upon the current mouse location. The OnMouseMove event uses the
 *    IScreenDisplay RotateMoveTo and RotateTimer methods to move and re-draw the
 *    display to the screen. The OnMouseUp event uses the IScreenDisplay RotateStop
 *    method to determine the angle of rotation. The MapControl's Rotation property
 *    is set to this angle, and the display is refreshed is reflect the change.
 *    Note: Creating custom cursor for rotation is not implemented.
 */



public class LinkSde extends JFrame implements ActionListener {

   JPanel topPanel = null;
   JPanel mainPanel = null;
   JPanel bottomPanel = null;

   JButton loadMapDocumentButton = null;
   JButton zoomToFullButton = null;
   JTextField pathField;

   String helpLabelString = "<HTML><BR> Left mouse button to zoomin <BR>" +
       "Right mouse button to rotate the display. <BR>" +
       "</HTML>";

   JLabel helpLabel = null;

   MapControl mapControl = null;
   Point mPoint = null;
   boolean rotating;


   public LinkSde() {
      super("Sde_shapefile Display");
      buildFrame();
      setSize(500, 400);
      setVisible(true);
      initControl();

   }

   /**This method builds 'this' frame as per the following diagram:
   *
   *   /----------------------------------------------------------\
   *   | JButton    BorderLayout.NORTH                            |
   *   | JTextField                                               |
   *   |----------------------------------------------------------|
   *   |                                                          |
   *   |                                                          |
   *   |                    MapControl                            |
   *   |                   BorderLayout.CENTER                    |
   *   |                                                          |
   *   |                                                          |
   *   |                                                          |
   *   |                                                          |
   *   |----------------------------------------------------------|
   *   |                  BorderLayout.SOUTH                      |
   *   |                                                          |
   *   | JButton          JLabel                                  |
   *   |                                                          |
   *   \----------------------------------------------------------/
   */


  public void buildFrame() {
     topPanel = new JPanel();
     mainPanel = new JPanel();
     bottomPanel = new JPanel();

     topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
     mainPanel.setLayout(new BorderLayout());
     bottomPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0));

     loadMapDocumentButton = new JButton("Load Shapefile from Sde");
     loadMapDocumentButton.addActionListener(this);

     pathField = new JTextField();
     pathField.setEditable(false);
     pathField.setAlignmentX(0);
     pathField.setAlignmentY(0);
     topPanel.add(loadMapDocumentButton);
     topPanel.add(Box.createVerticalStrut(5));
     topPanel.add(pathField);
     topPanel.add(Box.createVerticalStrut(5));

     zoomToFullButton = new JButton("ZoomToFullButton");
     zoomToFullButton.addActionListener(this);

     helpLabel = new JLabel(helpLabelString);
     //bottomPanel.add(zoomToFullButton);
     //bottomPanel.add(helpLabel);

     mapControl = new MapControl();
     mainPanel.add(topPanel, BorderLayout.NORTH);
     mainPanel.add(mapControl, BorderLayout.CENTER);
     mainPanel.add(bottomPanel, BorderLayout.SOUTH);
     mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

     getContentPane().add(mainPanel, BorderLayout.CENTER);


  }

  /** Initilizes control
   *  creates and intializes member variables
   * */


  public void initControl() {
   try {
      //Disbale the MapControl
      mapControl.setEnabled(false);
      mPoint = new Point();
      rotating = false;
      //Add map control listener
      mapControl.addIMapControlEvents2Listener(new MapControlListener());
   }
   catch (IOException ex) {
      System.out.println("Exception in initControl : " + ex);
      ex.printStackTrace();
   }

  }

 /**@see java.awt.event.ActionListener#actionPerformed(ActionEvent event)
   * @param event
   */

  public void actionPerformed(ActionEvent event) {
     /*if(event.getSource() == loadMapDocumentButton) {
        try {
            loadFile();
         }
         catch (IOException ex) {
            System.out.println("Exception in loadMapDocumentButton#actionPerformed" + ex);
            ex.printStackTrace();
         }
     }

     if(event.getSource() == zoomToFullButton) {
        try {
           mapControl.setExtent(mapControl.getFullExtent());
        }
        catch (IOException ex) {
           System.out.println("Exception in zoomToFullButton#actionPerformed" +
                              ex);
           ex.printStackTrace();
        }
     }*/
     try{
			IWorkspaceFactory sdeWsf = new SdeWorkspaceFactory();
			
			//IWorkspaceProxy wsp;
			//ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fwsp;

			IPropertySet ps = new PropertySet();
			ps.setProperty("Server","zfy");
			ps.setProperty("Instance","esri_sde");
			ps.setProperty("Database","sde");
			ps.setProperty("user","sde");
			ps.setProperty("password","sde");
			ps.setProperty("version", "sde.DEFAULT");

			//wsp = (IWorkspaceProxy)sdeWsf.open (ps,0); 
			IFeatureWorkspace fwsp = new IFeatureWorkspaceProxy(sdeWsf.open (ps,0));
			
			//--------------------------------------------------
			//this.AddFromWorkSpace (wsp);
			
			//IEnumDatasetName enumDSN = wsp.getDatasetNames (esriDatasetType.esriDTFeatureClass);
	        
			//String name=enumDSN.next().name;

			//IWorkspace fwsp = wsp;
			//IFeatureWorkspace fwsp = new IFeatureWorkspaceProxy(sdeWsf.open (ps,0));
				
			IFeatureLayer flayer = new FeatureLayer();
			IFeatureClass  fc = fwsp.openFeatureClass ("sde.SDE.USHIGH");

			flayer.setFeatureClassByRef(fc);

			ILayer layer= (ILayer) flayer;
			//layer.name = name;
			mapControl.addLayer (layer,0);

			//this.AddExtentToArray (this.axMapControl1.Extent );
		}
		catch(Exception ex){
			System.out.println("Exception22:"+ex.getMessage());
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -