- 浏览: 58081 次
- 性别:
- 来自: 北京
文章分类
最新评论
import java.io.File; import java.io.IOException; import com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory; import com.esri.arcgis.geodatabase.FeatureClass; import com.esri.arcgis.geodatabase.Field; import com.esri.arcgis.geodatabase.Fields; import com.esri.arcgis.geodatabase.GeometryDef; import com.esri.arcgis.geodatabase.IFeature; import com.esri.arcgis.geodatabase.IFeatureBuffer; import com.esri.arcgis.geodatabase.IFeatureClass; import com.esri.arcgis.geodatabase.IFeatureWorkspace; import com.esri.arcgis.geodatabase.IField; import com.esri.arcgis.geodatabase.IFieldEdit; import com.esri.arcgis.geodatabase.IFields; import com.esri.arcgis.geodatabase.IFieldsEdit; import com.esri.arcgis.geodatabase.IWorkspaceFactory; import com.esri.arcgis.geodatabase.Workspace; import com.esri.arcgis.geodatabase.esriFeatureType; import com.esri.arcgis.geodatabase.esriFieldType; import com.esri.arcgis.geometry.IGeographicCoordinateSystem; import com.esri.arcgis.geometry.ILine; import com.esri.arcgis.geometry.Line; import com.esri.arcgis.geometry.Point; import com.esri.arcgis.geometry.SpatialReferenceEnvironment; import com.esri.arcgis.geometry.UnknownCoordinateSystem; import com.esri.arcgis.geometry.esriGeometryType; import com.esri.arcgis.geometry.esriSRGeoCSType; import com.esri.arcgis.system.AoInitialize; import com.esri.arcgis.system.EngineInitializer; import com.esri.arcgis.system.esriLicenseProductCode; public class run2 { /** * Initialize ArcObjects for Engine, call the method to create a shapefile, * and shutdown. * * @param args * shapefile name and path */ public static void main(String[] args) { System.out .println("Starting CreateShapefile - An ArcObjects Java SDK Developer Sample"); String arcGISHome = null; try { arcGISHome = System.getenv("ARCGISHOME"); System.out.println("arcGISHome: " + arcGISHome); } catch (Error error) { // for Java 1.4 // BufferedReader console = new BufferedReader(new // InputStreamReader(System.in)); // System.out.print("Please enter the ArcGIS installation directory: "); // try { // arcGISHome = console.readLine(); // } // catch (IOException exception) { // exception.printStackTrace(); // } System.err.println("获取ARCGISHOME系统变量错误"); } if (!(new File(arcGISHome).exists())) { System.out.println(arcGISHome + " does not exist.\nExiting..."); System.exit(-1); } // // Change the following lines if you want to use different data // String outPath = getOutputDir() + "/createshapefile"; String outName = "newshape.shp"; File outShapefileDir = new File(outPath); outShapefileDir.mkdir(); File outShapefileFile = new File(outShapefileDir, outName); if (outShapefileFile.exists()) { System.out.println("Output shapefile already exists: " + outShapefileFile.getAbsolutePath()); System.out.println("Delete it (plus related files) and rerun"); System.exit(0); } try { EngineInitializer.initializeEngine(); AoInitialize aoInitializer = new AoInitialize(); aoInitializer .initialize(esriLicenseProductCode.esriLicenseProductCodeEngine); run2 thisSampleApp = new run2(); System.out.println("Creating new shapefile " + outShapefileFile.getAbsolutePath()); // 创建shape文件 FeatureClass feature= thisSampleApp.createAShapefile(outPath, outName); // 添加对应的台风信息 AddData.addInfo(feature); aoInitializer.shutdown(); } catch (IOException e) { System.out.println(e.getMessage()); System.out.println("Sample failed. Exiting..."); System.exit(-1); } System.out.println("Sample finished."); } private static String getOutputDir() { String userDir; if (System.getProperty("os.name").toLowerCase().indexOf("win") > -1) userDir = System.getenv("UserProfile"); else userDir = System.getenv("HOME"); String outputDir = userDir + "/arcgis_sample_output"; System.out.println("Creating output directory - " + outputDir); new File(outputDir).mkdir(); return outputDir; } // 创建Shape文件 private FeatureClass createAShapefile(String shapefilePath, String shapefileName) throws IOException { final String geometryShapeFieldName = "Shape"; Workspace workspace = null; try { // // Get a feature workspace from the specified shapefile location // ShapefileWorkspaceFactory shapefileWorkspaceFactory = new ShapefileWorkspaceFactory(); workspace = new Workspace(shapefileWorkspaceFactory.openFromFile( shapefilePath, 0)); } catch (IOException e) { throw e; } try { IFeatureClass iFeatureClass = workspace.createFeatureClass( shapefileName, ShapeHeaderName.createHeader(), null, null, esriFeatureType.esriFTSimple, geometryShapeFieldName, ""); return new FeatureClass(iFeatureClass); } catch (IOException e) { System.out .println("Could not create feature class for shapefile named: " + shapefileName); throw e; } } //添加创建Shape对应的信息 public void addInfo(FeatureClass featureClass) throws IOException { IFields fields = featureClass.getFields(); //int lngIndex = fields.findField("TextField"); int latIndex = fields.findField("eeee"); Point point = new Point(); point.setX(100); point.setY(100); // // Create a new feature and add the point's geometry to it // IFeature feature = featureClass.createFeature(); //feature.setShapeByRef(point); // // Add longitude, latitude, and value values to their individual fields // // feature.setValue(lngIndex, "sdfsdsf"); feature.setValue(latIndex,"safassdfsf"); feature.store(); } public void finalize(){ System.out.println("此方法被调用"); } }
import java.io.IOException; import com.esri.arcgis.geodatabase.Feature; import com.esri.arcgis.geodatabase.FeatureClass; import com.esri.arcgis.geodatabase.IFeature; import com.esri.arcgis.geodatabase.IFeatureBuffer; import com.esri.arcgis.geodatabase.IFields; import com.esri.arcgis.geometry.ILine; import com.esri.arcgis.geometry.IPoint; import com.esri.arcgis.geometry.Line; import com.esri.arcgis.geometry.Point; import com.esri.arcgis.geometry.Polyline; import com.esri.arcgis.interop.AutomationException; public class AddData { /** * 功能说明:往表中添加数据 */ public static void addInfo(FeatureClass featureClass){ try { IFields fields = featureClass.getFields(); int ShapeIndex = fields.findField("Shape"); int F_YEARIndex = fields.findField("F_YEAR"); int F_NATIONCODEIndex = fields.findField("F_ZYCODE"); int F_INTERNATIONCODEIndex = fields.findField("F_GJCODE"); int F_CHINESENAMEIndex = fields.findField("F_ZWNAME"); int F_ENGNAMEIndex = fields.findField("F_YWNAME"); int F_CHINEIDIndex = fields.findField("F_LJID"); int F_GENERATIONTIMEIndex = fields.findField("F_LJNYR"); int F_LANDINGPLACEIndex = fields.findField("F_DLDD"); int F_LANDINGTIMEIndex = fields.findField("F_DLSJ"); int F_ROUTELONGIndex = fields.findField("F_LJLONG"); int F_ROUTELATIIndex = fields.findField("F_LJLATI"); int F_TYPHOONCLASSIndex = fields.findField("F_TFJB"); int F_CENTERATMOSPRESS = fields.findField("F_ZXQY"); int F_BIGGESTWEEDSPEEDIndex = fields.findField("F_ZDFS"); int F_MOVEDIREIndex = fields.findField("F_YDFX"); int F_MOVESPEEDIndex = fields.findField("F_YDSD"); int F_STYLEIndex = fields.findField("F_TFTYPE"); int F_TYPHOONRADIUSIndex = fields.findField("F_TFBJ"); int F_NUMCHINEIDIndex = fields.findField("F_SJID"); int F_DATEIndex = fields.findField("F_SCTIME"); // Point[] pointes=new Point[2]; // for(int i=0;i<2;i++){ // pointes[i]=new Point(); // } // ILine pLine= new Line(); // pointes[0].putCoords(100,100); // pointes[1].putCoords(100,99); // pLine.putCoords(pointes[0], pointes[1]); // IFeatureBuffer pFeatureBuffer = featureClass.createFeatureBuffer(); // pFeatureBuffer.setShapeByRef(pLine); //Feature featurew = (Feature) featureClass.createFeature(); Polyline polyline = new Polyline(); IPoint point = new Point(); point.putCoords(496508.604 , 3417364.905); Point point2 = new Point(); point2.putCoords(496444.663 ,3417347.189); Point point3 = new Point(); point3.putCoords(496433.592 , 3417369.056); Point point4 = new Point(); point4.putCoords(496413.592, 3417369.056); polyline.addPoint(point, null, null); polyline.addPoint(point2, null, null); polyline.addPoint(point3, null, null); polyline.addPoint(point4, null, null); IFeature feature = featureClass.createFeature(); feature.setShapeByRef(polyline); //feature.setShapeByRef(point); //feature.setValue(ShapeIndex,pLine); feature.setValue(F_YEARIndex,"2011"); feature.setValue(F_NATIONCODEIndex,201110L); feature.setValue(F_INTERNATIONCODEIndex,0L); feature.setValue(F_CHINESENAMEIndex,"苗柏"); feature.setValue(F_ENGNAMEIndex,"MERBOK"); feature.setValue(F_CHINEIDIndex,0L); feature.setValue(F_GENERATIONTIMEIndex,0L); feature.setValue(F_LANDINGPLACEIndex,"8月8日14时"); feature.setValue(F_LANDINGTIMEIndex,"157.1"); feature.setValue(F_ROUTELONGIndex,"35.4"); feature.setValue(F_ROUTELATIIndex,"10"); feature.setValue(F_TYPHOONCLASSIndex,"980"); feature.setValue(F_CENTERATMOSPRESS,"28"); feature.setValue(F_BIGGESTWEEDSPEEDIndex,30L); feature.setValue(F_MOVEDIREIndex,"北东"); feature.setValue(F_MOVESPEEDIndex,0L); feature.setValue(F_STYLEIndex,0L); feature.setValue(F_TYPHOONRADIUSIndex,0L); feature.setValue(F_NUMCHINEIDIndex,0L); feature.setValue(F_DATEIndex,0L); IFeature features = featureClass.createFeature(); //feature.setShapeByRef(point); features.setValue(F_YEARIndex,"2011"); features.setValue(F_NATIONCODEIndex,201110L); features.setValue(F_INTERNATIONCODEIndex,0L); features.setValue(F_CHINESENAMEIndex,"苗柏"); features.setValue(F_ENGNAMEIndex,"MERBOK"); features.setValue(F_CHINEIDIndex,0L); features.setValue(F_GENERATIONTIMEIndex,0L); features.setValue(F_LANDINGPLACEIndex,"8月8日14时"); features.setValue(F_LANDINGTIMEIndex,"158.1"); features.setValue(F_ROUTELONGIndex,"36.4"); features.setValue(F_ROUTELATIIndex,"10"); features.setValue(F_TYPHOONCLASSIndex,"980"); features.setValue(F_CENTERATMOSPRESS,"28"); features.setValue(F_BIGGESTWEEDSPEEDIndex,30L); features.setValue(F_MOVEDIREIndex,"北东"); features.setValue(F_MOVESPEEDIndex,0L); features.setValue(F_STYLEIndex,0L); features.setValue(F_TYPHOONRADIUSIndex,0L); features.setValue(F_NUMCHINEIDIndex,0L); features.setValue(F_DATEIndex,0L); feature.store(); features.store(); //IFeatureBuffer pFeatureBuffer = featureClass.createFeatureBuffer(); //pFeatureBuffer.setShapeByRef(pLine); } catch (Exception e) { e.printStackTrace(); } } }
package com.hjkj.action.infoAna.topicmap; import java.io.IOException; import java.net.UnknownHostException; import com.esri.arcgis.geodatabase.Field; import com.esri.arcgis.geodatabase.Fields; import com.esri.arcgis.geodatabase.GeometryDef; import com.esri.arcgis.geodatabase.esriFieldType; import com.esri.arcgis.geometry.IGeographicCoordinateSystem; import com.esri.arcgis.geometry.SpatialReferenceEnvironment; import com.esri.arcgis.geometry.UnknownCoordinateSystem; import com.esri.arcgis.geometry.esriGeometryType; import com.esri.arcgis.geometry.esriSRGeoCSType; public class ShapeHeaderName { /** * ����˵����������Ҫ������Shape�ļ�ͷ������ * * @return Fields */ public Fields createHeader() { try { // ��� Field F_YEAR = new Field(); F_YEAR.setLength(50); F_YEAR.setName("F_YEAR"); F_YEAR.setType(esriFieldType.esriFieldTypeString); // ̨������̨��� Field F_NATIONCODE = new Field(); F_NATIONCODE.setLength(4); F_NATIONCODE.setName("F_ZYCODE"); F_NATIONCODE.setType(esriFieldType.esriFieldTypeInteger); // ̨���ʱ�� Field F_INTERNATIONCODE = new Field(); F_INTERNATIONCODE.setLength(4); F_INTERNATIONCODE.setName("F_GJCODE"); F_INTERNATIONCODE.setType(esriFieldType.esriFieldTypeInteger); // ������� Field F_CHINESENAME = new Field(); F_CHINESENAME.setLength(50); F_CHINESENAME.setName("F_ZWNAME"); F_CHINESENAME.setType(esriFieldType.esriFieldTypeString); // Ӣ����� Field F_ENGNAME = new Field(); F_ENGNAME.setLength(255); F_ENGNAME.setName("F_YWNAME"); F_ENGNAME.setType(esriFieldType.esriFieldTypeString); // ·����ϢID Field F_CHINEID = new Field(); F_CHINEID.setLength(4); F_CHINEID.setName("F_LJID"); F_CHINEID.setType(esriFieldType.esriFieldTypeInteger); // ·��λ��_ʱ�������� Field F_GENERATIONTIME = new Field(); F_GENERATIONTIME.setLength(255); F_GENERATIONTIME.setName("F_LJNYR"); F_GENERATIONTIME.setType(esriFieldType.esriFieldTypeString); // ��¼�ص� Field F_LANDINGPLACE = new Field(); F_LANDINGPLACE.setLength(255); F_LANDINGPLACE.setName("F_DLDD"); F_LANDINGPLACE.setType(esriFieldType.esriFieldTypeString); // ��¼ʱ�� Field F_LANDINGTIME = new Field(); F_LANDINGTIME.setLength(255); F_LANDINGTIME.setName("F_DLSJ"); F_LANDINGTIME.setType(esriFieldType.esriFieldTypeString); // ·��λ��_���� Field F_ROUTELONG = new Field(); F_ROUTELONG.setLength(9); F_ROUTELONG.setName("F_LJLONG"); F_ROUTELONG.setType(esriFieldType.esriFieldTypeDouble); // ·��λ��_γ�� Field F_ROUTELATI = new Field(); F_ROUTELATI.setLength(9); F_ROUTELATI.setName("F_LJLATI"); F_ROUTELATI.setType(esriFieldType.esriFieldTypeDouble); // ��ǰ̨�缶�� Field F_TYPHOONCLASS = new Field(); F_TYPHOONCLASS.setLength(255); F_TYPHOONCLASS.setName("F_TFJB"); F_TYPHOONCLASS.setType(esriFieldType.esriFieldTypeString); // ������ѹ���� Field F_CENTERATMOSPRESS = new Field(); F_CENTERATMOSPRESS.setLength(9); F_CENTERATMOSPRESS.setName("F_ZXQY"); F_CENTERATMOSPRESS.setType(esriFieldType.esriFieldTypeDouble); // ��������/�� Field F_BIGGESTWEEDSPEED = new Field(); F_BIGGESTWEEDSPEED.setLength(4); F_BIGGESTWEEDSPEED.setName("F_ZDFS"); F_BIGGESTWEEDSPEED.setType(esriFieldType.esriFieldTypeInteger); // �ƶ����� Field F_MOVEDIRE = new Field(); F_MOVEDIRE.setLength(50); F_MOVEDIRE.setName("F_YDFX"); F_MOVEDIRE.setType(esriFieldType.esriFieldTypeString); // �ƶ��ٶȹ���/Сʱ Field F_MOVESPEED = new Field(); F_MOVESPEED.setLength(4); F_MOVESPEED.setName("F_YDSD"); F_MOVESPEED.setType(esriFieldType.esriFieldTypeInteger); // ̨������ Field F_STYLE = new Field(); F_STYLE.setLength(50); F_STYLE.setName("F_TFTYPE"); F_STYLE.setType(esriFieldType.esriFieldTypeString); // ̨��뾶���� Field F_TYPHOONRADIUS = new Field(); F_TYPHOONRADIUS.setLength(4); F_TYPHOONRADIUS.setName("F_TFBJ"); F_TYPHOONRADIUS.setType(esriFieldType.esriFieldTypeInteger); // ���ID Field F_NUMCHINEID = new Field(); F_NUMCHINEID.setLength(4); F_NUMCHINEID.setName("F_SJID"); F_NUMCHINEID.setType(esriFieldType.esriFieldTypeInteger); // ���ʱ�� Field F_DATE = new Field(); F_DATE.setLength(50); F_DATE.setName("F_SCTIME"); F_DATE.setType(esriFieldType.esriFieldTypeString); Field F_XSD = new Field(); F_XSD.setLength(9); F_XSD.setName("F_XSD"); F_XSD.setType(esriFieldType.esriFieldTypeDouble); // // Create a Fields object and add the fields to it. // Fields fields = new Fields(); fields.addField(DefinitionShapeType()); fields.addField(F_YEAR); fields.addField(F_NATIONCODE); fields.addField(F_INTERNATIONCODE); fields.addField(F_CHINESENAME); fields.addField(F_ENGNAME); fields.addField(F_CHINEID); fields.addField(F_GENERATIONTIME); fields.addField(F_LANDINGPLACE); fields.addField(F_LANDINGTIME); fields.addField(F_ROUTELONG); fields.addField(F_ROUTELATI); fields.addField(F_TYPHOONCLASS); fields.addField(F_CENTERATMOSPRESS); fields.addField(F_BIGGESTWEEDSPEED); fields.addField(F_MOVEDIRE); fields.addField(F_MOVESPEED); fields.addField(F_STYLE); fields.addField(F_TYPHOONRADIUS); fields.addField(F_NUMCHINEID); fields.addField(F_DATE); fields.addField(F_XSD); return fields; } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } /** * ����˵��������shape�ļ������Ͷ��� * * @return Field */ public static Field DefinitionShapeType() { try { GeometryDef geometryDef = new GeometryDef(); geometryDef.setGeometryType(esriGeometryType.esriGeometryPolyline); SpatialReferenceEnvironment spatialReferenceEnvironment = new SpatialReferenceEnvironment(); IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceEnvironment .createGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984); geometryDef.setSpatialReferenceByRef(geographicCoordinateSystem); Field geometryShapeField = new Field(); geometryShapeField.setName("Shape"); geometryShapeField.setType(esriFieldType.esriFieldTypeGeometry); geometryShapeField.setGeometryDefByRef(geometryDef); return geometryShapeField; } catch (Exception e) { } return null; } }
- 生成Shape并且生成线.rar (15.5 KB)
- 下载次数: 41
相关推荐
shape文件由ESRI开发,一个ESRI(Environmental Systems Research Institute)的shape文件包括一个主文件,一个索引文件,和一个dBASE表。其中主文件的后缀就是 .shp。 该方法通过java代码实现将shp文件的数据读取...
Java创建SWF文件是一种在Java平台上生成Adobe Flash(SWF)格式内容的技术,这使得开发者能够在后端程序中创建和处理动态的富媒体内容,而无需依赖Flash IDE。SWF文件广泛用于网络上的动画、交互式图形和多媒体应用...
你可以创建自定义的QGraphicsItem子类,表示Shape文件中的一个形状,然后根据获取的几何信息在QGraphicsScene上进行绘制。 5. **添加交互性**:为了实现点击单元格显示图片,你需要监听QGraphicsView的鼠标点击事件...
SHAPE文件是ESRI推出的一种地理信息系统矢量数据文件格式,广泛应用于地理数据存储和处理,而CAD(计算机辅助设计)文件,如常见的DWG格式,是专业绘图和建模中常用的数据格式。在城市管理规划、土地资源调查以及...
在IT行业中,尤其是在地理信息系统(GIS)开发领域,`shp`文件是一种常见的地理空间数据格式,用于存储矢量图形信息,如点、线、多边形等。本篇文章将详细探讨如何使用Java语言,结合`meteoInfo`和`geotools`库来...
每个.shp文件中的形状ID在.dbf文件中有一个对应的记录,这样就可以将几何形状与其属性数据关联起来。DBF文件包含列名、数据类型、记录等信息,支持文本、数字、日期等多种数据类型。 3. **.shx文件**:这是一个索引...
在GIS(地理信息系统)工作中,有时我们需要处理包含经纬度数据的Excel文件,并将这些数据转换成Shape文件,以便于在GIS软件中进行空间分析和制图。以下是如何使用Excel中的经纬度坐标数据创建Shape文件的详细步骤:...
7. **数据编辑**:了解如何在ArcMap中直接编辑Shape文件的几何属性和属性信息,包括添加、删除和修改地理要素。 8. **投影与坐标系统**:理解GIS中的投影概念,知道如何选择正确的坐标系统,以确保数据的准确性和...
以下是一个简化的示例,演示如何使用GDAL在C#中添加字段并更新Shapefile数据: ```csharp using OSGeo.OGR; // 打开Shapefile Ogr.DataSource dataSource = Ogr.Open("Test.shp", 0); Ogr.Layer layer = ...
SHAPE 文件格式最早在1990年代初由 ESRI 公司推出,旨在提供一个开放的标准来存储和交换地理空间数据。该格式的设计目标是为了替代之前专有的数据格式,使得不同供应商之间的数据交换变得更加简单和高效。随着 GIS ...
在Java开发中,处理地理空间数据时,常常会遇到.shp(Shapefile)文件,这是一种常见的矢量地理数据格式。为了将这些数据转换为适用于地图显示的经纬度格式,我们需要特定的库和工具。本话题将详细介绍如何在Java...
中国各省边界shape文件是一种地理信息系统(GIS)数据格式,用于表示中国各省级行政区划的边界信息。这种数据通常由一系列几何对象(如多边形)组成,每个对象代表一个省份的轮廓。Shape文件是Esri公司开发的一种...
在Java编程语言中,"Java Shape"是一个概念,它涉及到创建和操作表示二维或三维图形的类。在Java中,`java.awt`和`javax.swing`包提供了多种形状类,如`Rectangle`, `Circle`, `Polygon`等,它们是图形用户界面(GUI...
在Java编程环境中,解析Shapefile(.shp)文件是一项常见的任务,特别是在地理信息系统(GIS)应用中。Shapefile是一种广泛用于存储地理空间数据的开放格式。为了在Java中处理这些文件,我们可以利用开源库GeoTools...
在GIS中,SHAPE文件格式是一种广泛用于存储矢量地理数据的标准格式,由Esri公司开发。SHAPE文件通常包括三个主要组成部分:`.shp`、`.shx`和`.dbf`。 1. `.shp` 文件: `.shp`文件是SHAPE文件的核心部分,它包含了...
世界地图的shape文件是一种地理信息系统(GIS)中常见的数据格式,用于存储地理形状和属性信息。这个特定的压缩包包含的是一个描绘全球地理边界的shapefile,可以在ArcMap这样的专业GIS软件中用作底图。ArcMap是Esri...
Java 读写Shape库主要指的是在Java环境中操作ESRI的Shapefile格式,这是一种广泛用于地理信息系统(GIS)的数据存储格式。Shapefile由一系列相互关联的文件组成,包括一个.shp文件,存储几何数据,以及一个.dbf文件...
例如,气象站点的位置信息可以转化为点对象,气象事件的空间分布可以转化为线或面对象,结合属性数据一同存储在SHAPE文件中,便于在ARCGIS中进行地图显示、分析和查询。 总的来说,深入理解SHAPE文件的结构,并掌握...