?? featuretest.java
字號(hào):
package barchant;import java.util.*;import com.mapinfo.dp.*;import com.mapinfo.util.*;import com.mapinfo.beans.vmapj.VisualMapJ;import com.mapinfo.mapj.FeatureLayer;import com.mapinfo.dp.util.RewindableFeatureSet;/*該示例演示了有關(guān)圖元的一些方法,成功*/public class FeatureTest { public FeatureLayer world;//Feature對(duì)象用來(lái)訪問(wèn)地圖對(duì)象 public VisualMapJ myMap;//可管理地圖集的各種狀態(tài),并向服務(wù)器轉(zhuǎn)發(fā)客戶(hù)請(qǐng)求 public FeatureTest() { List columns = new ArrayList(); Feature ftr; Geometry geom; DoubleRect rect; DoublePoint dblPnt; PointGeometry pntGeometry; VectorGeometry vectorGeometry; PointList pntList; Attribute attrib; int attribCount; try{ //創(chuàng)建地圖 myMap=new VisualMapJ(); myMap.getMapJ().loadMapDefinition("d:\\program files\\MapInfo\\MapXtreme-4.7.0\\examples\\server\\data\\local\\world.mdf"); //mdf是地圖定義文件 world=(FeatureLayer)myMap.getMapJ().getLayers().get("World Countries");//得到World Countries圖層 // Get the Table information from the FeatureLayer TableInfo tabInfo = world.getTableInfo(); // fill vector with Column names // System.out.println("tableColumnCount="+tabInfo.getColumnCount()); for (int i=0;i<tabInfo.getColumnCount();i++) { columns.add(tabInfo.getColumnName(i)); // System.out.println("columnName="+tabInfo.getColumnName(i)); } // 搜索有幾條紀(jì)錄,放到可回讀的圖元集中 RewindableFeatureSet rFtrSet = new RewindableFeatureSet(world.searchAll(columns, null)); // 得到第一個(gè)圖元,圖元集中的圖元沒(méi)有順序 ftr=rFtrSet.getNextFeature(); // then loop through all features in the layer while (ftr!=null) {/* get the first attribute (columnData) from the feature Note: Ifyou want to re-use the Attribute object later on (after thegetNextFeature loop), you would need to make a copy of theAttribute object, using the copy constructor.*/ //得到一個(gè)圖元的第一個(gè)屬性 attrib = ftr.getAttribute(0); System.out.println("attribute="+attrib.toString()); //得到一個(gè)圖元的屬性數(shù)目 attribCount = ftr.getAttributeCount(); System.out.println("attributeCount="+attribCount); //得到幾何信息 geom = ftr.getGeometry(); //如果該元素是點(diǎn) if (geom.getType()==Geometry.TYPE_POINT) { System.out.println("aaaaaaaaaaaa"); //把該元素轉(zhuǎn)換成點(diǎn)元素 pntGeometry = (PointGeometry)geom; //得到該點(diǎn)元素的邊界 rect = pntGeometry.getBounds(); System.out.println(rect.toString()); //得到該點(diǎn)元素的標(biāo)注位置 dblPnt = pntGeometry.getLabelPoint(null); } else //如果不是點(diǎn)元素,就可用VectorGeometry來(lái)存儲(chǔ) { //將元素轉(zhuǎn)換成 Vector geometry vectorGeometry = (VectorGeometry)geom; // get the minimum bounding rectangle for the feature rect = vectorGeometry.getBounds(); // get the x,y location where the feature’s label will be anchored dblPnt = vectorGeometry.getLabelPoint(null); System.out.println("dblPnt:"+dblPnt.toString()); double[] pnts; int offset=0; int numPts;// Loop through all the point groups and then put the points into an array //無(wú)論是線(xiàn)元素還是區(qū)域都是由點(diǎn)構(gòu)成的 for (int i=0;i<vectorGeometry.getPointListCount();++i) { // Get the next Point List pntList = vectorGeometry.getNextPointList(); // determine the number of Points in the point group numPts = pntList.getPointCount(); // Create the point array large enough to hold all the points pnts = new double[numPts]; // Call getNextPoints which will put the points into the array pntList.getNextPoints(pnts, offset, numPts/2); //System.out.println("numPts="+numPts); } } // Get the next feature ftr=rFtrSet.getNextFeature(); } // Rewind the FeatureSet to prepare for future use重新回到第一個(gè)圖元 rFtrSet.rewind(); }catch(Exception e){ System.out.println("Error"); e.printStackTrace(); } } public static void main(String args[]){ FeatureTest bclr=new FeatureTest(); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -