阅读:1775回复:1
【原创】ArcGISServer java开发中,实现在服务器端新建shp文件的代码
<P> public class addandtran {<BR> AGSLocalMapResource res=null;<BR> WebContext webContext =null;<BR> static IServerContext serverContext=null;<BR> String file=null;<BR> String name=null;<BR> FeatureClass feacls=null;<BR> public WebContext getwebContext(){<BR> return webContext;<BR> }<BR> public void setwebContext(WebContext webContext){<BR> this.webContext=webContext;<BR> }<BR> public void execute() throws AutomationException, IOException {<BR> file="D:/gisdata/Beijing";<BR> name="tt30";<BR> res=(AGSLocalMapResource) webContext.getResources().get("ags0");<BR> //-----get serverContext<BR> serverContext=res.getServerContext();<BR>// -----get Workspace<BR> IWorkspaceFactory factory= new IWorkspaceFactoryProxy(serverContext.createObject(ShapefileWorkspaceFactory.getClsid()));<BR> IFeatureWorkspace ws= new IFeatureWorkspaceProxy( factory.openFromFile(file, 0));</P>
<P> Fields fields = new Fields(serverContext.createObject(Fields.getClsid()));<BR> <BR> Field pField=new Field(serverContext.createObject(Field.getClsid()));<BR> pField.setName(attName);<BR> pField.setType(esriFieldType.esriFieldTypeString);<BR> fields.addField(pField);<BR> <BR> GeometryDef geometryDef = new GeometryDef(serverContext.createObject(GeometryDef.getClsid()));<BR> geometryDef.setGeometryType(esriGeometryType.esriGeometryPolygon);<BR> ISpatialReference sr=new ISpatialReferenceProxy(serverContext.createObject(UnknownCoordinateSystem.getClsid()));<BR> geometryDef.setSpatialReferenceByRef(sr);<BR> <BR> Field ShapeField = new Field(serverContext.createObject(Field.getClsid()));<BR> ShapeField.setName("shape");<BR> ShapeField.setType(esriFieldType.esriFieldTypeGeometry);<BR> ShapeField.setGeometryDefByRef(geometryDef);<BR> fields.addField(ShapeField);</P> <P> IFeatureClass fc=ws.createFeatureClass(name, fields, null, null, esriFeatureType.esriFTSimple, "shape", "");<BR> <BR> //creatPolygon<BR> IPoint[3] point=null; <BR> <BR> point[0]=new Point(serverContext.createObject(Point.getClsid()));<BR> point[0].putCoords(116, 40);<BR> point[1]=new Point(serverContext.createObject(Point.getClsid()));<BR> point[1].putCoords(115, 40.1);<BR> point[2]=new Point(serverContext.createObject(Point.getClsid()));<BR> point[2].putCoords(115.5, .9.8);<BR> Polygon poly=null;<BR> poly= new Polygon(serverContext.createObject(Polygon.getClsid()));<BR> GeometryEnvironment gBridge = new GeometryEnvironment(serverContext.createObject(GeometryEnvironment.getClsid()));<BR> gBridge.addPoints(poly, point);</P> <P> IFeatureCursor insert = new IFeatureCursorProxy(fc.IFeatureClass_insert(true));<BR> IFeatureBuffer buffer = new IFeatureBufferProxy(fc.createFeatureBuffer());<BR> Object obj=null;<BR> obj=poly;<BR> buffer.setValue(fc.getFields().findField("shape"), obj);<BR> buffer.setValue(fc.getFields().findField("name"), "beijing"); <BR> insert.insertFeature(buffer);<BR> insert.flush(); </P> <P> }<BR> webContext.refresh();<BR> }<BR> </P> <P> }</P> |
|
1楼#
发布于:2007-08-28 08:47
<P>好帖咋没人顶呢</P>
<P>自己努力一下</P> |
|