java解析shp文件

java geo_科学网-java利用geotools读写shp以及相关的文件-林清莹的博文 利用java读取shp以及相关的文件对应geotools版本:2.7.2读shape文件。shape格式文件最少包含3个文件,他们的后缀是:.shp, .dbf, .shx。.shp存储地理形状和位置信息,.dbf存储属性信息,.shx是索引文件。单独读取DBF文件public void readDBF(String path) {Java代码DbaseFileReader reader = nu... 阅读详情
    工作之余记录,没有美化好:
POM引入:


<!-- for geotools begin -->
    <!--处理空间数据-->
    <!-- geotools主要依赖 -->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-metadata</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-referencing</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-wkt</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>27.2</version>
    </dependency>

    <!--<dependency>-->
    <!--<groupId>org.geotools</groupId>-->
    <!--<artifactId>gt-data</artifactId>-->
    <!--<version>27.2</version>-->
    <!--</dependency>-->

    <!--<dependency>-->
    <!--<groupId>org.geotools</groupId>-->
    <!--<artifactId>gt-api</artifactId>-->
    <!--<version>27.2</version>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-main</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-swing</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-jdbc</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools.jdbc</groupId>
        <artifactId>gt-jdbc-postgis</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-opengis</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geojson</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-process-feature</artifactId>
        <version>27.2</version>
    </dependency>
    <dependency>
        <groupId>org.locationtech.jts</groupId>
        <artifactId>jts-core</artifactId>
        <version>1.18.2</version>
    </dependency>
    <!--for geotools end-->

    <!--读取geojson文件-->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.wowtools</groupId>
        <artifactId>giscat-vector-pojo</artifactId>
        <version>1.1.1-STABLE</version>
    </dependency>
    <!--读取geojson文件end-->


</dependencies>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>

    <!-- geotools的远程库 -->
    <repository>
        <id>osgeo</id>
        <name>OSGeo Release Repository</name>
        <url>https://repo.osgeo.org/repository/release/</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
    <repository>
        <id>osgeo-snapshot</id>
        <name>OSGeo Snapshot Repository</name>
        <url>https://repo.osgeo.org/repository/snapshot/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
    <!-- geotools的远程库end -->
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureSource;
import org.geotools.data.Transaction;
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureStore;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.geojson.GeoJSON;
import org.geotools.geojson.feature.FeatureJSON;
import org.geotools.geojson.geom.GeometryJSON;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.util.factory.GeoTools;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.locationtech.jts.geom.LineString;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import org.springframework.stereotype.Component;

import java.io.*;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
@Component
public class GeoToolsMethod {
    //使用openGIS FilterFactory2
    private static org.opengis.filter.FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
    //读取shp
    public FeatureSource<SimpleFeatureType, SimpleFeature> ReadShpFile(String filePath) throws Exception{
        File dir = new File(filePath);
        File[] subFiles = dir.listFiles();
        if (null!=subFiles){
            for (File subFile : subFiles) {
                if (subFile.getName().endsWith(".shp")) {
                    filePath = subFile.getPath();break;
                }
            }
        }
        File shpFile = new File(filePath);
        //源shape文件
        //ShapefileDataStore shpDataStore = (ShapefileDataStore) new ShapefileDataStoreFactory().createDataStore(subFile.toURI().toURL());
        ShapefileDataStore shpDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
        shpDataStore.setCharset(Charset.forName("UTF-8"));
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = shpDataStore.getFeatureSource();
        return featureSource;
    }
    //读取geojson
    public FeatureCollection ReadGeojsonFile(String pathfile) throws Exception{
        FeatureCollection featureCollection = null;
                //创建一个JSONParser对象
        JSONParser jsonParser = new JSONParser();
        //解析JSON文件的内容
        try {
            //String pathfile = getClass().getClassLoader().getResource("csdata").getPath()+"/csfeature.geojson";
            //先用json.simple读取geojson文件
//            org.json.simple.JSONObject obj = (org.json.simple.JSONObject) jsonParser.parse(new FileReader("D:/hjyTest/JAVA/demo_gdal2/target/classes/csdata/csfeature.geojson"));
            JSONObject obj = (JSONObject) jsonParser.parse(new FileReader(pathfile));
            //JSONObject obj = (JSONObject) jsonParser.parse(new FileReader("E:\\河南省乡镇点\\FieldPolygon.geojson"));
            //删除除features以外其它对象,方便下面所需的geojson字符串
//            obj.remove("type");
//            obj.remove("name");
//            obj.remove("crs");
            //获取features对象json字符串
            String strGeoJson =obj.toString();
            System.out.println(strGeoJson);


            // 指定GeometryJSON构造器,15位小数
            FeatureJSON fjson_15 = new FeatureJSON(new GeometryJSON(15));
            // fjson_15已经保留15位
            fjson_15.setEncodeFeatureCollectionCRS(true);
            fjson_15.setEncodeNullValues(true);

            featureCollection = fjson_15.readFeatureCollection(strGeoJson);
            fjson_15.writeFeatureCollection(featureCollection,System.out);  // 控制台输出和原始geojson一致



//            OutputStream ostream = new ByteArrayOutputStream();
//            GeoJSON.write(featureCollection, ostream);
//            // 输出:{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[116.1983,39.7832],[116.0445,39.2323],[116.8959,39.3831],[116.8698,39.9182],[116.1983,39.7832]]]},"properties":{"area":3865207830},"id":"polygon.1"}]}
//            System.out.println(ostream);

//            //获取数据
//            FeatureIterator<SimpleFeature> iterator = featureCollection.features();
//            while(iterator.hasNext()) {
//                SimpleFeature feature = iterator.next();
//                try{
//                    org.locationtech.jts.geom.Geometry geom1 = (org.locationtech.jts.geom.Geometry) feature.getDefaultGeometry();
//                    System.out.println(geom1.getCoordinate());
//                }catch (Exception e){
//
//                }
//
//
//                feature.getName();
//                Iterator<Property> it = feature.getProperties().iterator();
//                LinkedHashMap<String, Object> data = new LinkedHashMap<>();
//                String geometry = "";
//                while (it.hasNext()) {
//                    Property pro = it.next();
//                    if (pro.getValue() instanceof  org.locationtech.jts.geom.Point) {//点
//                        geometry = "'" + ((org.locationtech.jts.geom.Point) pro.getValue()).toString() + "'";
//                        data.put("geom", geometry);
//                    } else if (pro.getValue() instanceof org.locationtech.jts.geom.Polygon) {//面
//                        geometry = "'" + ((org.locationtech.jts.geom.Polygon) pro.getValue()).toString() + "'";
//                        data.put("geom", geometry);
//                    } else if (pro.getValue() instanceof org.locationtech.jts.geom.MultiPolygon) {//多面
//                        geometry = "'" + ((org.locationtech.jts.geom.MultiPolygon) pro.getValue()).toString() + "'";
//                        data.put("geom", geometry);
//                    } else if (pro.getValue() instanceof org.locationtech.jts.geom.LineString) {//线
//                        geometry = "'" + ((org.locationtech.jts.geom.LineString) pro.getValue()).toString() + "'";
//                        data.put("geom", geometry);
//                    } else {
//                        data.put(pro.getName().toString(), pro.getValue());
//                    }
//                }
//                System.out.println(data);
//            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return featureCollection;
    }
    //方法一:
    //返回其属性值
    public List<LinkedHashMap<String,Object>> getAttirbutes(String srs, FeatureCollection col){
        //srs="EPSG:4326"
        List<LinkedHashMap<String,Object>> listMap = new ArrayList<>();
        FeatureIterator<SimpleFeature> iterator = col.features();
            while(iterator.hasNext()) {
                SimpleFeature feature = iterator.next();
                //获取属性
                Iterator<Property> it = feature.getProperties().iterator();
                LinkedHashMap<String, Object> data = new LinkedHashMap<>();
                String geometry = "";
                while (it.hasNext()) {
                    Property pro = it.next();
                    if (pro.getValue() instanceof Point) {//点
                        geometry = "'"  +((Point) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    } else if (pro.getValue() instanceof Polygon) {//面
                        geometry = "'"+((Polygon) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    } else if (pro.getValue() instanceof MultiPolygon) {//多面
                        geometry = "'"+((MultiPolygon) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    } else if (pro.getValue() instanceof LineString) {//线
                        geometry = "'" +((LineString) pro.getValue()).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    } else {
                        if(pro.getValue() instanceof Date){
                            Date myDate = (Date)pro.getValue();
                            SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            String strDate3 = sdf3.format(myDate);
                            data.put(pro.getName().toString(),strDate3);
                        }else{
                            data.put(pro.getName().toString(),pro.getValue());
                        }
                    }
                }
                //System.out.println(data);
                listMap.add(data);
            }
            return listMap;
    }
    //方法二:
    //返回属性值
    public List<LinkedHashMap<String,Object>> getAttirbutes2(String srs, FeatureCollection col){
        //srs="EPSG:4326"
        List<LinkedHashMap<String,Object>> listMap = new ArrayList<>();
        //另外一种循环start
        SimpleFeatureCollection sfc = (SimpleFeatureCollection)col;
        // 获取当前矢量数据有哪些属性字段值
        List<AttributeDescriptor> attributes = sfc.getSchema().getAttributeDescriptors();
        // 拿到迭代器
        SimpleFeatureIterator simpleFeatureIterator = sfc.features();
        // 遍历每一个要素
        while(simpleFeatureIterator.hasNext()) {
            SimpleFeature simpleFeature = simpleFeatureIterator.next();
            LinkedHashMap<String, Object> data = new LinkedHashMap<>();
            // java8新特性流api
            attributes.stream().forEach((a) -> {
                Object tempobj = simpleFeature.getAttribute(a.getLocalName());
                // 依次读取这个shape中每一个属性值,当然这个属性值,可以处理其它业务
                if(a.getLocalName().indexOf("geom")>=0){
                    String geometry = "";
                    if (tempobj instanceof Point) {//点
                        geometry = "'"  +((Point) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    } else if (tempobj instanceof Polygon) {//面
                        geometry = "'"+((Polygon) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    } else if (tempobj instanceof MultiPolygon) {//多面
                        geometry = "'"+((MultiPolygon) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    } else if (tempobj instanceof LineString) {//线
                        geometry = "'" +((LineString) tempobj).toString()+ "'"+","+srs.substring(srs.indexOf(":")+1);
                        data.put("geom",geometry);
                    }
                }else{
                    if(tempobj instanceof Date){
                        Date myDate = (Date)tempobj;
                        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String strDate3 = sdf3.format(myDate);
                        data.put(a.getLocalName(),strDate3);
                    }else{
                        data.put(a.getLocalName(),tempobj);
                    }
//                    System.out.println(a.getLocalName() + ":" + simpleFeature.getAttribute(a.getLocalName()));
                }
            });
            listMap.add(data);
        }
        return listMap;
    }
    //查询 CQL
    public Filter ReturnFilter(String sql)throws Exception{
        String wkt = "POLYGON ((113.17574362102584 23.135924459989738, 113.07445367113468 22.981863911800943, 113.3121749821035 22.932375044753726, 113.3907263718155 23.073180341529934, 113.17574362102584 23.135924459989738))";
        Filter filter = null;
        // 相交
        filter =  CQL.toFilter( "OBJECTID = 5 or INTERSECTS(the_geom," + wkt + ")");
        if(sql!=null || sql!=""){
            filter = CQL.toFilter(sql);
        }
        // 在10公里以内
        //  Filter filter =  CQL.toFilter( "DWITHIN(the_geom," + wkt + ", 10, kilometers)");
        return filter;
    }
    //查询 使用openGIS FilterFactory2
    public Filter ReturnFilter2(){
        Filter filter = ff.greaterOrEqual(ff.property("OBJECTID"), ff.literal(5));
        return filter;
    }

    public static SimpleFeatureType createType(Class<?> c, String layerName) {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setCRS(DefaultGeographicCRS.WGS84);
        builder.add("FID",String.class);
        builder.add("the_geom", c);
        // 设置了图层的名字
        builder.setName(layerName);
        SimpleFeatureType simpleFeatureType = builder.buildFeatureType();
        return simpleFeatureType;
    }
  //生成shp
    public static void createShp(String shpPath, SimpleFeatureCollection collection) throws IOException {
        File shpFile = new File(shpPath);
        ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
        SimpleFeatureType simpleFeatureType = collection.getSchema();
        // 创造shpstore需要的参数
        Map<String, Serializable> params = new HashMap<>();
        params.put("url", shpFile.toURI().toURL());
        params.put("create spatial index", Boolean.TRUE);
        ShapefileDataStore newDataStore =
                (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
        newDataStore.createSchema(simpleFeatureType);
        Transaction transaction = new DefaultTransaction("create");
        String typeName = newDataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = newDataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        featureStore.setTransaction(transaction);
        featureStore.addFeatures(collection);
        featureStore.setTransaction(transaction);
        transaction.commit();
        transaction.close();
    }
/  //这里也是读取shp
    public static SimpleFeatureCollection readFeatureCollection(String shpPath) {
        SimpleFeatureCollection featureCollection = null;
        File shpFile = new File(shpPath);
        try {
            ShapefileDataStore shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
            // 设置编码,防止属性的中文字符出现乱码
            shapefileDataStore.setCharset(Charset.forName("UTF-8"));
            // 这个typeNamae不传递,默认是文件名称
            FeatureSource featuresource = shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
            featureCollection = (SimpleFeatureCollection) featuresource.getFeatures();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return featureCollection;
    }

}

@Autowired
    GeoToolsMethod geoToolsMethod;

//测试geoTools封装好的方法
    @Test
    public void Test_geoToolsMethod() throws Exception{
        //测试读取shp
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource=geoToolsMethod.ReadShpFile("D:\\ceshi\\dwq0606");
        String srs = CRS.lookupIdentifier(featureSource.getSchema().getCoordinateReferenceSystem(),true);  // 获取EPSG
        System.out.println(srs);
        FeatureCollection collection = featureSource.getFeatures();
        long startTime = System.currentTimeMillis();
        //测试获取getAttributes
        List<LinkedHashMap<String,Object>> listAttr = geoToolsMethod.getAttirbutes(srs,collection);
        long endTime = System.currentTimeMillis();
        System.out.println("运行时长:"+(endTime-startTime)+"ms"); //1128ms
        startTime = System.currentTimeMillis();
        //测试获取getAttributes2
        List<LinkedHashMap<String,Object>> listAttr2 = geoToolsMethod.getAttirbutes2(srs,collection);
        endTime = System.currentTimeMillis();
        System.out.println("运行时长:"+(endTime-startTime)+"ms"); //980ms 1015
        //System.out.println(listAttr);
    }

//做geometry 的计算距离,取交集、合并几何、difference
    @Test
    public void GeometryOperate() throws Exception{
        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
        //创建一条线
        List<Coordinate> points1 = new ArrayList<Coordinate>();
        points1.add(new Coordinate(0,0));
        points1.add(new Coordinate(1,3));
        points1.add(new Coordinate(2,3));
        Coordinate[] coords  = (Coordinate[]) points1.toArray(new Coordinate[points1.size()]);
        LineString line1 = geometryFactory.createLineString(coords);
        //创建第二条线
        List<Coordinate> points2 = new ArrayList<Coordinate>();
        points2.add(new Coordinate(3,0));
        points2.add(new Coordinate(3,3));
        points2.add(new Coordinate(5,6));
        Coordinate[] coords2  = (Coordinate[]) points2.toArray(new Coordinate[points2.size()]);
        LineString line2 = geometryFactory.createLineString(coords2);
//        返回(A)与(B)中距离最近的两个点的距离
        System.out.println(line1.distance(line2));//out 1.0
//        两个几何对象的交集
        System.out.println(line1.intersection(line2));//out GEOMETRYCOLLECTION EMPTY
//        几何对象合并
        Geometry lineunion = line1.union(line2);
        System.out.println(lineunion); //out MULTILINESTRING ((0 0, 1 3, 2 3), (3 0, 3 3, 5 6))
        //在A几何对象中有的,但是B几何对象中没有
        System.out.println(line1.difference(line2));//out LINESTRING (0 0, 1 3, 2 3)
        System.out.println(lineunion.difference(line2));//out LINESTRING (0 0, 1 3, 2 3)
        //交集
        System.out.println(lineunion.intersection(line2));//out MULTILINESTRING ((3 0, 3 3), (3 3, 5 6))

        WKTReader reader = new WKTReader(geometryFactory);
        Polygon geometry1 = (Polygon) reader.read("POLYGON((0 0, 2 0 ,2 2, 0 2,0 0))");
        Polygon geometry2 = (Polygon) reader.read("POLYGON((0 0, 4 0 , 4 1, 0 1, 0 0))");
        OverlayOp op = new OverlayOp(geometry1,geometry2);
        Geometry g =op.getResultGeometry(OverlayOp.INTERSECTION);//POLYGON ((2 0, 0 0, 0 1, 2 1, 2 0))
        //Geometry g2 = op.getResultGeometry(OverlayOp.UNION);
        //Geometry g3 = op.getResultGeometry(OverlayOp.DIFFERENCE);
        //Geometry g4 = op.getResultGeometry(OverlayOp.SYMDIFFERENCE);
        //PlanarGraph p = op.getGraph(); //图<v,e

        //LineMerger 线路合并,线路之间不能有交点,并且只在线路末尾有公共交点
        // lineMerger 和union区别,union可以在两条相交的线中生成交点(noded)
        WKTReader wktReader = new WKTReader();
        LineMerger lineMerger = new LineMerger();
        List<Geometry> list = new ArrayList<Geometry>();
        list.add(wktReader.read("LINESTRING (3 3,2 2,0 0)"));
        list.add(wktReader.read("LINESTRING (3 3,6 6,0 10)"));
        list.add(wktReader.read("LINESTRING (0 10,3 1,10 1)"));
        lineMerger.add(list);
        Collection<Geometry> mergerLineStrings = lineMerger.getMergedLineStrings();
        for (Geometry tempg : mergerLineStrings) {
            System.out.println(tempg.toText()); //LINESTRING (0 0, 2 2, 3 3, 6 6, 0 10, 3 1, 10 1)
        }

    }

java使用geotools解析矢量数据kml、geojson、shp文件 java使用geotools解析常见三种格式(kml、geojson、shp)的矢量数据。 阅读详情

相关推荐

Java读取SHP文件并提取点线坐标:GeoTools与手写解析实践

SHP文件是GIS领域常见的矢量几何数据格式,点、线、面坐标以二进制形式存储,并伴随SHX索引、DBF属性表和PRJ坐标系描述。理解ShapeType、记录结构与大小端字节序,是稳定读取几何数据的关键;在此基础上,可通过GeoTools快速完成坐标提取、属性读取和投影转换,也可手写二进制解析器控制依赖与内存。对于批量数据清洗、空间分析、路径计算和GIS服务入库等场景,合理选择解析路线能显著降低OOM与文件句柄问题。围绕Java环境下的点线坐标提取,需要兼顾坐标系校验、流式遍历与大文件处理等工程细节。

weixin_33290540的博客 145

java 解析shp文件(转GeoJSON\esrijson、生成图片)

1.下载jar包 2.根目录下新建lib文件夹,将jar包放入 3.配置maven pom文件 <!-- shp解析--> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-shapefile</artifactId> <version>19.2</version> <scop.

weixin_41963652的博客 7851

Java解析SHP文件与坐标转换:高鲁棒性工具类设计

Shapefile解析不仅是读取二进制文件,更是涵盖数据完整性校验、多坐标系精准转换、几何拓扑修复与工程化异常处理的系统工程。其核心原理在于严格遵循ESRI白皮书定义的.shp/.shx/.dbf三文件耦合规范,并区分标准投影(如WGS84↔CGCS2000)、加密坐标(如GCJ02)和地方独立坐标系(需七参数/Bursa-Wolf模型)三类转换场景。技术价值体现在脱离GIS桌面依赖下实现开箱即用、坐标精准、错得明、扩得清;典型应用场景包括高校地理信息模拟、国土空间规划系统、物流导航坐标对齐及环保监测点位纠

weixin_32308101的博客 193

Java shp文件解析

package com.shp.analysis; import javafx.application.Application; import javafx.scene.shape.Polygon; import javafx.stage.Stage; import java.io.File; import java.util.ArrayList; import java.util.List; /** * @Author: ZhangHao * @Description: shp文件解析 * .

haoranhaoshi的博客 2168

java解析上传的shp文件,包含jar,方法,shp文件

java使用geotools解析shp文件,内容包含 解析方法,使用的各种jar包,以及单区域shp和多区域shp文件

shp文件解析java实现

提供通过meteoInfo+geotools解析shp文件,提取出shp文件中的数据,javaj技术实现,获取边界线数据、中心点坐标、最大、最小经纬度值等

JAVA解析shp文件

时间:2019.12.24.20.37 之前写过JAVA实现shp文件转wkb文件 现在做一个补充,实现获取shp文件的属性信息 java代码如下 package com.atlchain.bcgis.data; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.ge...

Edgar_LQS的博客 2766

java中读取shp文件数据存入数据库

shp文件:地理信息系统,也被称作GIS,它主要的扩展类型是SHAPEFILE (.SHP),一个包含了矢量地理空间数据的流行文件格式,描述了几何形态,点,线和多边形,每一个都有他们各自的属性。 shape文件由ESRI开发,一个ESRI(Environmental Systems Research Institute)的shape文件包括一个主文件,一个索引文件,和一个dBASE表。其中主文件的后缀就是 .shp。 该方法通过java代码实现将shp文件的数据读取以及存入数据库

java解析shp文件以及坐标转换(工具类)

百度找了很多大部分都是pom的,maven项目中的,但是用maven下载不了,只能一个jar一个jar下载了,中间也遇到了很多坑,都是pom中没有提到的架包 直接上代码,最后我会解析shp文件所用到的所有jar截图粘上 package com.common.utils; import java.io.File; import java.io.IOException; import j...

許先生的博客 6073

STM32 HAL 硬件IIC驱动BNO085:从移植到姿态解算全流程解析(附源码)

本文详细解析了STM32 HAL库下硬件IIC驱动BNO085 IMU传感器的全流程,包括CubeMX配置、驱动移植、传感器初始化、Q格式数据处理及四元数转欧拉角解算。提供了完整的源码实现和常见问题解决方案,帮助开发者快速掌握高精度姿态测量技术。

palm99的专栏 1047

信号完整性仿真SI之Cadence Sigrity SPEED2000_眼图仿真(四)

今天给大家分享一个仿真的操作流程,是关于Cadence Sigrity SPEED2000的时域波形仿真和眼图仿真。我们会经常看见硬件工程师调试示波器上的一些信号的波形变化,其实这些也可以通过仿真电路的搭建来做出投板前的仿真,来优化走线,以减少版本的迭代次数。如果要和实际的信号保持一致,就要求仿真设置的参数和实际的参数保持一致,这也是仿真的重点和难点。下面先让我们了解一下Cadence Sigrity SPEED2000时域仿真的操作流程: 1.仿真模式选择与文件导入 选择Cadence Sigrity下的

刘小同学的博客 1万+

java解析地图文件shp、dbf、shx

【代码】java解析地图文件shp、dbf、shx。

weixin_45864962的博客 315

保姆级教程:用STM32标准库搞定TIM1的PWM输出(附完整代码和避坑点)

本文提供STM32F103高级定时器TIM1的PWM输出保姆级教程,涵盖从工程搭建到完整代码实现的详细步骤。重点解析TIM1作为高级定时器的特殊配置要点,包括时钟初始化、PWM通道设置和GPIO复用功能,并附常见问题排查指南和动态调整占空比的实用技巧,帮助开发者高效实现精准PWM控制。

weixin_30673611的博客 433

Java解析shp文件(ZIP压缩包)获取坐标集

在Java后台解析前台上传的shp文件,因为shp文件一般不会是单独出现包括了索引文件等,所以一般都是以压缩包的形式出现,因此如果要获取其中的坐标集,则必须先解压压缩包 解压压缩包的链接 解压压缩包 解析shp需要下载jar包,无法使用依赖直接下载 解析shp所需的jar包 <!--解析shp文件--> <dependency> <groupId>gt.api</groupId> <ar

weixin_50074995的博客 1965

Qupath软件的安装与使用

Qupath软件的安装与使用软件安装软件下载软件安装【windows版】简单使用文件打开人工标注标注导出和导入 Qupath是一款开源的医学图像标注软件,适合放射影像及数字病理切片等的查看。同时,其自带的标注功能使得医生可以直接通过该软件进行病变区域的标注和分类。跟进一步的,该软件提供groovy脚本运行接口,可供操作者编写和运行脚本,将标注信息转换为xml或者json格式的数据进行进一步的后序处...

qq_40662074的博客 3万+

PSO算法介绍

结合网上的文章对PSO进行一些介绍,并附上自己复现的算法。

Witty_Hou的博客 1万+

Java解析.shp文件中的经纬度数据

用geotools工具解析shp文件

道祖转生之重修Java 944

万字详解 PostgreSQL 的详细安装方式(Linux、Windows、macOS、Docker 全平台覆盖)

本文详细介绍了PostgreSQL在四大主流环境下的安装方法: Linux系统:针对Ubuntu/Debian和CentOS/RHEL系,分别提供APT/YUM仓库安装步骤,包括初始化配置和服务管理 Windows系统:通过图形化安装程序指导完成安装,包含组件选择、密码设置和pgAdmin配置 macOS系统:推荐使用Homebrew一键安装,支持Apple Silicon和Intel芯片 Docker容器:提供容器化部署方案(文中未展开) 文章强调安装前的版本选择、权限管理和存储规划,并针对各平台给出验证

数据知道的博客 4502

Java结合GeoTools实现SHP文件高效解析与转换实战

本文详细介绍了如何使用Java结合GeoTools库高效解析与转换SHP文件。从环境配置、基础操作到高级功能扩展,涵盖了文件读取、数据校验、空间索引优化以及格式转换等实战技巧,特别针对大型SHP文件处理提供了性能优化方案,帮助开发者提升GIS数据处理效率。

weixin_29300931的博客 341

【Frida Android】实战篇8:客户端证书认证绕过 Hook 教程

通过重写类的方法,自定义证书校验逻辑;利用配置文件,从系统层面管理证书信任策略;以及通过 OkHttp 框架提供的方法,实现证书的强绑定校验。这些内容主要围绕客户端如何验证服务端证书的合法性展开。客户端证书认证。当 APK 预置了客户端证书,并且服务端会对客户端证书进行校验时,传统的中间人攻击方式将面临新的挑战。我们将深入分析这种场景的工作原理,并详细介绍如何通过技术手段获取客户端证书、配置中间人工具,最终成功实现抓包分析。

水滴石穿 1427

Docker:快速部署 Temporal 工作流引擎的技术指南

Temporal是一个开源的分布式工作流引擎,适用于复杂业务流程(如订单处理、支付流程等),提供状态持久化、自动重试、多语言SDK支持等特性。部署简单,支持Docker Compose,包含核心服务、Web UI及数据库。以TypeScript为例,开发者可快速编写工作流(如订单处理)和Worker,通过CLI或SDK启动和管理。Temporal简化了分布式系统的可靠性设计,适合电商、自动化任务等场景。

木头 641

【Java+GeoTools实战】SHP文件解析全能助手:ZIP压缩包直读/坐标系智能识别/属性表秒级提取,3分钟完成GIS数据集成!

一站式解决SHP文件解析难题!支持ZIP压缩包直读、坐标系检测、属性表提取,3分钟快速集成!

hangbingbihai的博客 999

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

java导入shp数据并解析

java解析shp文件,springboot整合shp解析文件

weixin_45850105的博客 2173

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Java代码实现kml文件、geojson文件、shp矢量文件的解析#java实现zip文件解压#geotool#SpringBoot

本文用于记录后端开发项目经验

jingjiaohuan的博客 2927

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Java解析SHP文件与坐标转换工具类实战指南

Shapefile(SHP)是GIS领域最基础的矢量数据格式,其解析与坐标转换涉及空间参考系统(CRS)、WKT解析、投影变换等核心地理信息概念。原理上需理解SHP三件套结构、.prj坐标系定义机制,以及Java中GeoTools对CRS识别与MathTransform转换的实现逻辑。技术价值在于规避生产环境常见坑点:如.prj缺失导致默认WGS84误判、GBK编码引发中文属性乱码、环方向错误致使空间分析失效。典型应用场景包括政务系统空间数据集成、Spring Boot后端矢量预处理、WebGIS离线地图引

weixin_29574585的博客 343
上一篇: SpringBoot结合cxf自动生成webservice客户端代码插件
下一篇: SpringBoot 整合 Quartz 搭建多节点分布式任务调度平台
javaMyGod
博客等级 码龄16年 38粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值