?? featurecontent.java~6~
字號:
package secondstudy;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.dp.Attribute;
import com.mapinfo.unit.LinearUnit;
import com.mapinfo.mapj.FeatureLayer;
import java.util.List;
import java.util.ArrayList;
import com.mapinfo.dp.Feature;
import com.mapinfo.dp.FeatureSet;
import com.mapinfo.dp.TableInfo;
public class FeatureContent
{
private String mdfFilePath="e:\\MapInfo\\study\\mapmdf";
private String mdfFileName="pla.mdf";
private String mapxtremeURL="http://901-32:8083/mapxtreme47/mapxtreme";
private FeatureLayer featureLayer=null;
public FeatureContent()
{
MapJ mapj=new MapJ();
DoublePoint centerPoint=new DoublePoint(108.9608,34.2729);
LinearUnit unit=LinearUnit.kilometer ;
DoubleRect bound=new DoubleRect(0,0,800,600);
try
{
mapj.loadMapDefinition(mdfFilePath + "\\" + mdfFileName);
featureLayer=(FeatureLayer)mapj.getLayers() .get(0) ;
}catch(Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith messag "+e.getMessage() ) ;
}
}
public void getFeatureAttribute()
{/*得到feature這一記錄的每一列的值,如果columns為空,它就只返回一列的值,返回的這列的值為name列的。
要想全部返回,還必須得用columns指定,想返回多少列就指定多少列。
*/
String layerName;
try
{
layerName=featureLayer.getName() ;
TableInfo tableInfo=featureLayer.getTableInfo() ;
String colName;
List columns = new ArrayList();
for(int colIndex=0;colIndex<tableInfo.getColumnCount() ;colIndex++)
{
colName=tableInfo.getColumnName(colIndex) ;
columns.add(colName) ;
}
FeatureSet fs = featureLayer.searchAll(columns, null);
if (fs == null) {
System.out.println("null,exit");
}
Feature feature = fs.getNextFeature();
//下面這個是練習,練習如何得到feature對應的列值,因為一個層實際上對應的就是一個表,所以一個feature
//對應的應該就是一列
for (int i = 0; i < feature.getAttributeCount(); i++)
{
Attribute att = feature.getAttribute(i);
String str = att.getString();
str = "wait";
}
}catch(Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith messag "+e.getMessage() ) ;
}
}
public static void main(String[] args)
{
FeatureContent fc=new FeatureContent();
fc.getFeatureAttribute() ;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -