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

📄 linksde.java

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

  }

  /**
     * Method loadFile loads the specified mxd file
    **/
   public void loadFile() throws IOException {
        //Open a JFileChooser for selecting PMF documents
      JFileChooser chooser = new JFileChooser();
      chooser.setFileFilter(new FileFilter() {
         public boolean accept(File f) {
            return (f.isDirectory() ||
                    f.getAbsolutePath().toUpperCase().endsWith(".MXD"));
         }

         public String getDescription() {
            return "Map Documents(*.mxd)";
         }
      });

      boolean loaded = false;
      int returnVal = 0;
      while (loaded != true){
          loaded = true;
          returnVal = chooser.showOpenDialog(null);
          if (returnVal == JFileChooser.APPROVE_OPTION) {
              String fileChosen =
                  chooser.getCurrentDirectory()
                      + File.separator
                      + chooser.getSelectedFile().getName();
              System.out.println("File picked: [" + fileChosen + "]");
              //check if the selected document can be loaded into MapControl
                if (mapControl.checkMxFile(fileChosen)) {
                  //load the document in the mapcontrol bean
                  pathField.setText(fileChosen);
                  mapControl.loadMxFile(fileChosen, null, null);
                  mapControl.setEnabled(true);

              } else {
                  JOptionPane.showMessageDialog(null, "The current document does not have permission to be loaded into MapControl.");
                  loaded = false;
                }
                System.out.println("Document Loaded");
          }
      }
   }

   /**
   * Description: Class which extends map control event class IMapControlEvents2Adapter
   * @see com.esri.arcgis.beans.map.IMapControlEvents2Adapter
   * */

  class MapControlListener extends IMapControlEvents2Adapter {

     /**
      * @see com.esri.arcgis.beans.map.IMapControlEvents2Adapter#onMouseMove(IMapControlEvents2OnMouseMoveEvent theEvent)
      * @param theEvent
      */

    public void onMouseMove(IMapControlEvents2OnMouseMoveEvent theEvent) {
       try {
          if(!rotating) return;
         //Create point object.
         Point point = new Point();
         //Set the coordinates of current mouse location
         point.putCoords(theEvent.getMapX(), theEvent.getMapY());

         //Rotate the display based upon the current mouse location
         mapControl.getActiveView().getScreenDisplay().rotateMoveTo(point);
         //Draw the rotated display
         mapControl.getActiveView().getScreenDisplay().rotateTimer();
       }
       catch(Exception ex) {
          System.out.println("Exception in MapControlListener#onMouseMove : " + ex);
          ex.printStackTrace();
       }

    }

    /**
      * @see com.esri.arcgis.beans.map.IMapControlEvents2Adapter#onMouseDown(IMapControlEvents2OnMouseDownEvent theEvent)
      * @param theEvent
      */

    public void onMouseDown(IMapControlEvents2OnMouseDownEvent theEvent) {
       try {
          //If left mouse button
         if(theEvent.getButton() == 1) {
            //User not rotating
            rotating = false;
           //Get IEnvelope interface
           IEnvelope envelope = null;
           envelope = mapControl.trackRectangle();
           //If user dragged a rectangle
           if(envelope != null)
              mapControl.setExtent(envelope);

         }
         else if(theEvent.getButton() == 2) {
            rotating = true;
            //Get IPoint interface
            Point point = new Point();
            //Set the coordinates of current mouse location
            point.putCoords(theEvent.getMapX(), theEvent.getMapY());
            //Set the coordinates of the center of the current extent
            double x = mapControl.getExtent().getXMin() + (mapControl.getExtent().getWidth()/2);
            double y = mapControl.getExtent().getYMin() + (mapControl.getExtent().getHeight()/2);
            mPoint.setX(x);
            mPoint.setY(y);
            //Start rotating the display
            mapControl.getActiveView().getScreenDisplay().rotateStart(point, mPoint);
         }
       }
       catch(Exception ex) {
          System.out.println("Exception in MapControlListener#onMouseDown : " + ex);
          ex.printStackTrace();
       }

    }

    /**
     * @see com.esri.arcgis.beans.map.IMapControlEvents2Adapter#onMouseUp(IMapControlEvents2OnMouseUpEvent theEvent)
     * @param theEvent
     */


    public void onMouseUp(IMapControlEvents2OnMouseUpEvent theEvent)  {
       try {
          rotating = false;
          //Get rotation angle
          double rotationAngle = mapControl.getActiveView().getScreenDisplay().rotateStop();
          //Rotate the MapControl's display
          mapControl.setRotation(rotationAngle);
          //Refresh the display
          mapControl.refresh(esriViewDrawPhase.esriViewBackground, null, null);


      }
      catch(Exception ex) {
         System.out.println("Exception in MapControlListener#onMouseUp : " + ex);
         ex.printStackTrace();
      }

    }

    /**
     * @see com.esri.arcgis.beans.map.IMapControlEvents2Adapter#onAfterScreenDraw(IMapControlEvents2OnAfterScreenDrawEvent theEvent)
     * @param theEvent
     */


    public void onAfterScreenDraw(IMapControlEvents2OnAfterScreenDrawEvent theEvent) {
       try {
         if(!rotating)
              mapControl.setMousePointer(esriControlsMousePointer.esriPointerDefault);
      }
      catch(Exception ex) {
         System.out.println("Exception in MapControlListener#onAfterScreenDraw : " + ex);
         ex.printStackTrace();
      }

    }

    /**
     * @see com.esri.arcgis.beans.map.IMapControlEvents2Adapter#onBeforeScreenDraw(IMapControlEvents2OnBeforeScreenDrawEvent theEvent)
     * @param theEvent
     */


    public void onBeforeScreenDraw(IMapControlEvents2OnBeforeScreenDrawEvent theEvent){
       try {
          if(!rotating)
              mapControl.setMousePointer(esriControlsMousePointer.esriPointerHourglass);

       }
      catch(Exception ex) {
         System.out.println("Exception in MapControlListener#onBeforeScreenDraw : " + ex);
         ex.printStackTrace();
      }

    }

	private void sde(){
		/*try {
            com.esri.arcgis.system.EngineInitializer.initializeEngine();
            com.esri.arcgis.system.EngineInitializer.initializeVisualBeans();
        } catch (Exception e) {
            e.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());
		}
	}


 }//End of MapControlListener class



  /**
   * Main program to start the program execution.
   *
   * @param s
   */


  public static void main(String s[]) {
     try {
        //Set the system look and feel
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        EngineInitializer.initializeVisualBeans();

        AoInitialize aoInit = new AoInitialize();
        aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

        LinkSde linkSde = new LinkSde();
        linkSde.setDefaultCloseOperation(LinkSde.EXIT_ON_CLOSE);
     }
     catch (Exception ex) {
        ex.printStackTrace();
     }
  }


}

⌨️ 快捷键说明

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