?? featureclass.java~98~
字號:
rend.setValue(Rendition.STROKE ,Color.cyan );
rend.setValue(Rendition.FILL ,Color.green );
// For points, specify the symbol size, font, and color
rend.setValue(Rendition.SYMBOL_STRING, "@");
rend.setValue(Rendition.FONT_SIZE, 16);
rend.setValue(Rendition.FONT_FAMILY, "MapInfo Shields");
rend.setValue(Rendition.SYMBOL_FOREGROUND, Color.blue);
// For lines, specify the line color and width
rend.setValue(Rendition.STROKE, Color.green);
rend.setValue(Rendition.STROKE_WIDTH, 4);
// For ellipses, specify the fill color and opacity
rend.setValue(Rendition.FILL, Color.blue);
rend.setValue(Rendition.FILL_OPACITY, new Float(0.40));
//create circular region
int circleType=1;
double circleRadius=2;
int circleResolution=12;
//for elliptical region
//create a integer variable to set the coordsys system of the region.o set for map coordsys,1 set for screen coordsys
int ellipseType=1;
//create a variable to set the rotation angle of the ellipse in radiant
double xRadius=1.0;
double yRadius=0.25;
//create a integer variable to specify the number of point to describe the ellipse. if 0,the default 12 will be used
int ellipseResolution=12;
//create an annotation layer for storing the feature we are creating
AnnotationTableDescHelper annotationTDHelper=new AnnotationTableDescHelper("Annotations");
AnnotationDataProviderHelper annotationDPHelper=new AnnotationDataProviderHelper();
LocalDataProviderRef localDPRef=new LocalDataProviderRef(annotationDPHelper);
FeatureLayer annotationLayer=(FeatureLayer)mapj.getLayers() .insertLayer(localDPRef,annotationTDHelper,0,"Annotations");
//PrimaryKey is taken as an argument by all the create methods and
//cannot be null
Feature retFeature;
PrimaryKey pkey = new PrimaryKey(attributes[0]);
//set the center point for the circle
DoublePoint centerPoint=new DoublePoint(108.9608,34.2729);
// Create a Circular Region
retFeature = feaFac.createCircularRegion(circleType,//type
/*
if the Type is 0, MapJ creates a region whose points are all the same geographic distance from the
center. Due to the curvature of the earth, and due to the way that coordinate systems and
map projections work, such a circle might appear lop-sided, rather than circular.
If the type parameter is 1, MapJ creates a region that appears circular on the screen.
However, different points on the circle might not be the same geographic distance from the center
of the circle.
type - An integer representing the type of coordinate system to use in creation of the circle.
Use 0 for map coords and 1 for screen coords.
*/
centerPoint,// The center of the circle given as a DoublePoint.
circleRadius,//the radius of the circle
LinearUnit.mile,//the linear unit of the distance
circleResolution,// The number of points describing the circle. If 0 it will use default of 12.
rend,//The rendition associated with this feature, may be null.
null, //The rendition associated with the label for this feature, may be null.
null,//attributes,//Attributes that are associated with this feature, may be null.
pkey//the PrimaryKey of the new Feature, may be null.
);
//add the new feature to the annotation layer
PrimaryKey pkey2=annotationLayer.addFeature(retFeature) ;
//create the ellipse region
DoublePoint ellipseCenter=new DoublePoint(108.9608,34.3729);
retFeature=feaFac.createEllipticalRegion(ellipseType,ellipseCenter,0,xRadius,yRadius,
LinearUnit.mile , ellipseResolution,rend,null,null,new PrimaryKey(attributes[1]));
annotationLayer.addFeature(retFeature) ;
//creae point
retFeature=feaFac.createPoint(new DoublePoint(108.8,34.2729),rend,null,new PrimaryKey(attributes[2]));
annotationLayer.addFeature(retFeature) ;
//create ployline
// Create PolyLine using a 2 x 6 double matrix
// Row 1 contains 3 points(x,y,x,y,x,y) and 2 line segments.
// Row 2 contains 3 points(x,y,x,y,x,y) and 2 line segments.
double pts[][] = { {108.8608,34.2720, 108.8908,34.2720,108.9208,34.270},
{108.8908,34.2680, 108.8608,34.2680,108.8408,34.2720} };
retFeature = feaFac.createPolyLine(pts, rend, null, null, new PrimaryKey(attributes[3]));
annotationLayer.addFeature(retFeature) ;
//
MapXtremeImageRenderer render=new MapXtremeImageRenderer(mapxtremeURL);
ImageRequestComposer imageRC=ImageRequestComposer.create(mapj,256,Color.white ,"image/png");
render.render(imageRC) ;
render.toFile("E:\\MapInfo\\study\\png\\created.png") ;
}catch(Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
e.printStackTrace() ;
}
}
public void searchFeature()
{
MapJ mapj=new MapJ();
DoublePoint centerPoint=new DoublePoint(108.9608,34.2729);
DoubleRect bound=new DoubleRect(centerPoint,0.31,0.21);
mapj.setBounds(bound) ;
mapj.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
Layers layers=null;
FeatureLayer featureLayer;
FeatureSet featureSet=null;
double searchRadius=2;
List resList=new ArrayList();
RewindableFeatureSet rfSet=null;
Feature feature=null;
try
{
mapj.loadMapDefinition(mdfFilePath);
layers=mapj.getLayers() ;
int count=0;
String layerName;
for(int i=0;i<layers.size() ;i++)
{
featureLayer=(FeatureLayer)layers.get(i) ;
layerName=featureLayer.getName() ;
feature=null;
count=0;
// featureSet=featureLayer.searchWithinRadius(resList,centerPoint,searchRadius,LinearUnit.kilometer ,null);
// DoubleRect rect=new DoubleRect(108.9608,34.2729,108.9908,34.3729);
// featureSet=featureLayer.searchWithinRectangle(resList,rect,null);
// featureSet=featureLayer.searchAtPoint(resList,centerPoint,null) ;
/* Attribute attLength=new Attribute(1022);
String searchCol="length";
if(layerName.equals("line") )
{
featureSet=featureLayer.searchByAttribute(resList,searchCol,attLength,null);
rfSet=new RewindableFeatureSet(featureSet);
feature=rfSet.getNextFeature() ;
}*/
int searchLen=1022;
String searchColumn="length";
//create name list
List nameList=new ArrayList();
nameList.add(searchColumn) ;
//create value list
List valueList=new ArrayList();
Attribute searchAttr=new Attribute(searchLen);
AttTuple searchTuple=new AttTuple(searchAttr);
valueList.add(searchTuple);
//create operator list
List operatorList=new ArrayList();
operatorList.add(AttOperator.eq ) ;
//do the search
if(layerName.equals("line") )
{
featureSet=featureLayer.searchByAttributes(resList,nameList,operatorList,valueList,QueryParams.m_defaultQP );
rfSet=new RewindableFeatureSet(featureSet);
feature=rfSet.getNextFeature() ;
//下面這個是練習,練習如何得到feature對應的列值,因為一個層實際上對應的就是一個表,所以一個feature
//對應的應該就是一列
for(int ii=0;ii<feature.getAttributeCount() ;ii++)
{
Attribute att=feature.getAttribute(ii) ;
String str=att.getString() ;
str="wait";
}
}
featureSet=featureLayer.searchByAttributes(resList,nameList,operatorList,valueList,QueryParams.m_defaultQP );
feature=rfSet.getNextFeature() ;
while(feature!=null)
{
//下面這個是練習,練習如何得到feature對應的列值,因為一個層實際上對應的就是一個表,所以一個feature
//對應的應該就是一列
for(int ii=0;ii<feature.getAttributeCount() ;ii++)
{
Attribute att=feature.getAttribute(ii) ;
String str=att.getString() ;
str="wait";
}
count++;
feature=rfSet.getNextFeature() ;
}
System.out.println("there are "+count+" in "+layerName+" layer ") ;
}
}catch(java.io.IOException ioe)
{
System.out.println("get a "+ioe.getClass() +"\nwith message "+ioe.getMessage() ) ;
}catch(Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -