?? featureclass.java~98~
字號:
package myfirstmap;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.unit.LinearUnit;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.dp.tab.TABDataProviderHelper;
import com.mapinfo.dp.tab.TABTableDescHelper;
import com.mapinfo.mapxtreme.client.MapXtremeDataProviderRef;
import com.mapinfo.mapj.AbstractLayer;
import com.mapinfo.mapj.Layers;
//import com.mapinfo.mapj.Layer;
import com.mapinfo.mapj.FeatureLayer;
import com.mapinfo.dp.TableInfo;
import java.util.List;
import java.util.ArrayList;
import com.mapinfo.dp.util.RewindableFeatureSet;
import com.mapinfo.dp.FeatureSet;
import com.mapinfo.dp.Feature;
import com.mapinfo.dp.Attribute;
import com.mapinfo.dp.Geometry;
import com.mapinfo.dp.PointGeometry;
import com.mapinfo.dp.VectorGeometry;
import com.mapinfo.dp.PointList;
import com.mapinfo.mapj.FeatureFactory;
import com.mapinfo.graphics.Rendition;
import com.mapinfo.graphics.RenditionImpl;
import java.awt.Color;
import com.mapinfo.dp.annotation.AnnotationDataProvider;
import com.mapinfo.dp.annotation.AnnotationDataProviderHelper;
import com.mapinfo.dp.annotation.AnnotationTableDescHelper;
import com.mapinfo.dp.util.LocalDataProviderRef;
import com.mapinfo.dp.PrimaryKey;
import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
import com.mapinfo.dp.AttOperator;
import com.mapinfo.dp.AttTuple;
import com.mapinfo.dp.QueryParams;
public class FeatureClass
{
private String mapxtremeURL="http://901-32:8083/mapxtreme47/mapxtreme";
private String mdfFilePath="E:\\MapInfo\\study\\mapmdf\\pla2.mdf";
public FeatureClass()
{
}
public void getInfoFromFeature()
{
MapJ mapj=new MapJ();
DoublePoint point=new DoublePoint(018.9608,34.2729);
DoubleRect bound=new DoubleRect(point,0.31,0.21);
mapj.setBounds(bound) ;
LinearUnit unit=LinearUnit.kilometer ;
mapj.setDistanceUnits(unit) ;
mapj.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
//
try
{
mapj.loadMapDefinition(mdfFilePath);
Layers layers=mapj.getLayers() ;
AbstractLayer abstractLayer=null;
FeatureLayer featureLayer=null;
String layerName;
TableInfo tableInfo=null;
List columns=new ArrayList();
Attribute attribute=null;
Geometry geom=null;
PointGeometry pointGeom=null;
int attributeCount=0;
DoubleRect rect=null;
DoublePoint dbPoint=null;
PointList pointList=null;
VectorGeometry vectorGeometry=null;
int count=0;
for(int i=0;i<layers.size() ;i++)
{
featureLayer=(FeatureLayer)layers.get(i) ;
layerName=featureLayer.getName() ;
tableInfo=featureLayer.getTableInfo() ;
//必須清空,因為下次執行下一個表時,如果它們的字段不一樣,那么在“FeatureSet fSet=featureLayer.searchAll(columns,null);”就會出現錯誤
count=0;
columns.clear() ;
for(int j=0;j<tableInfo.getColumnCount() ;j++)
{
String columnName=tableInfo.getColumnName(j) ;
columns.add(columnName) ;
}
//perform a search to get the features(records) from the layer
FeatureSet fSet=featureLayer.searchAll(columns,null);
RewindableFeatureSet rfSet=new RewindableFeatureSet(fSet);
//get the first attribute
Feature feature=rfSet.getNextFeature() ;
//the loop throuth all feature in the layer
while(feature!=null)
{
/* get the first attribute (columnData) from the feature Note: If
we want to re-use the Attribute object later on (after the
getNextFeature loop), we would need to make a copy of the
Attribute object, using the copy constructor.
*/
attribute=feature.getAttribute(0) ;//it's error here
//get a count of all attributes in the layer
attributeCount=feature.getAttributeCount() ;
//get a reference to the grographic information from the feature
geom=feature.getGeometry() ;
//if the geometry is a point
if(geom.getType() ==Geometry.TYPE_POINT )
{
pointGeom=(PointGeometry)geom;
// get the minimum bounding rectangle for the feature
rect=pointGeom.getBounds() ;
// get the x,y location where the feature’s label will be
// anchored
dbPoint=pointGeom.getLabelPoint(null);
}else
{
vectorGeometry = (VectorGeometry) geom;
rect = vectorGeometry.getBounds();
dbPoint = vectorGeometry.getLabelPoint(null);
double[] points;
int offset=0;
int numPoints;
int pointListCount=vectorGeometry.getPointListCount() ;
for (int ii=0;ii<vectorGeometry.getPointListCount();++ii)
{
// Get the next Point List
pointList = vectorGeometry.getNextPointList();
// determine the number of Points in the point group
numPoints = pointList.getPointCount();
// Create the point array large enough to hold all the
// points
points = new double[numPoints];
// Call getNextPoints which will put the points into the
// array
pointList.getNextPoints(points, offset, numPoints/2);
}//end this for above
}//end else
count++;
if((count>332)&&(layerName.equals("Line") ))
{
System.out.println(">99") ;
}
feature=rfSet.getNextFeature() ;
}//end while
//rewind the featureSet for the future use
rfSet.rewind() ;
}//end the most outer for
}catch(java.io.IOException ioe)
{
System.out.println("get a "+ioe.getClass() +"\nwith message "+ioe.getMessage() ) ;
ioe.printStackTrace() ;
}catch(Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
e.printStackTrace() ;
}
}//end this function
public void createVariousFeature()
{
MapJ mapj=new MapJ();
DoublePoint point=new DoublePoint(108.9608,34.2729);
DoubleRect bound=new DoubleRect(point ,0.31,0.21);
mapj.setBounds(bound) ;
LinearUnit unit=LinearUnit.kilometer ;
mapj.setDistanceUnits(unit) ;
mapj.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
try
{
// mapj.loadMapDefinition(mdfFilePath);
FeatureFactory feaFac=mapj.getFeatureFactory() ;
//set attribute object
Attribute[] attributes=new Attribute[4];
attributes[0]=new Attribute("feature1");
attributes[1]=new Attribute("ellpise");
attributes[2]=new Attribute("point");
attributes[3]=new Attribute("polyline");
//set up the rendition object
//this will not work for a tab files. for tab files we must use
//com.mapinfo.tab.TABStyleFactory to create an appropirate rendition object
Rendition rend=RenditionImpl.getDefaultRendition() ;
//for circle ,specify the edge color and fill color
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -