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

📄 featurecontent.java

📁 CreateMyFirstMap
💻 JAVA
字号:
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为空,它就只返回一列的值,返回的这列的值为MapInfo_ID列的。
     这列是由mapinfo设置的,不是程序员指定的; 要想全部返回,还必须得用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 + -