任凭风浪起,稳坐钓鱼台 2019-11-08 17:17 采纳率: 100%
浏览 173
已采纳

有没有用java操作gis的大佬,如何求两个边界不一致的部分的,请教了!

1.我调用的jts api的symDifference方法

/**
* 各部门提交的本辖区行政边界是否一致,如不一致在系统中反馈出不一致的部分,
* 并通知相关辖区客户达成一致后进行修改;
*/
public static boolean regionCheck(String wellKnownText, List wellKnownTexts) throws ParseException {
//获取面
Polygon polygon = getPolygon(wellKnownText);
//边界
Geometry boundary = polygon.getBoundary();
for (String wkts : wellKnownTexts) {
Polygon polygon2 = getPolygon(wkts);
//getBoundary返回边界,如果Geometry 为空,则返回适当尺寸的空几何。
Geometry boundary2 = polygon2.getBoundary();
if (!boundary.equals(boundary2)) {
Geometry Geometry=polygon.symDifference(polygon2);
System.err.println(Geometry);
return false;
}
}
return true;
}
这是测试方法

@Test
public void regionCheck() {
String wkt = "POLYGON ((-224350635455.002197265625 -111836039853.78741455078125, -244254937379.54150390625 -107965758924.015777587890625, -257524471995.900909423828125 -104648375269.926025390625, -274664287542.031982421875 -99119402513.109375, -288486719434.072998046875 -98566505237.427764892578125, -300650459499.06939697265625 -100778094340.154388427734375, -319209182509.980224609375 -120093567998.94781494140625, -326636631456.106689453125 -184818480243.764556884765625, -334930090591.3314208984375 -281575503488.0526123046875, -190071004362.740203857421875 -325254388266.902587890625, -60140144577.55352783203125 -266094379768.966400146484375, -72732287430.19964599609375 -198319022650.31201171875, -78938651950.729461669921875 -164914178319.225250244140625, -180200885637.218505859375 -109383275975.02154541015625, -224350635455.002197265625 -111836039853.78741455078125))";
//String wkt1 = "LINESTRING (35510272.308399997651577 221713.426899999380112, 35510586.63400000333786 221877.468800000846386)";
List list = new ArrayList<>();
list.add("POLYGON ((-60140144577.55352783203125 -266094379768.966461181640625, -78938651950.729461669921875 -164914178319.225250244140625, -180200885637.218505859375 -109383275975.02154541015625, -181777545227.515472412109375 -108518656199.69744873046875, -315025788666.7921142578125 -83638278794.02349853515625, -319209182509.98016357421875 -120093567998.94781494140625, -326636631456.10675048828125 -184818480243.764556884765625, -334930090591.3314208984375 -281575503488.0526123046875, -190071004362.740203857421875 -325254388266.902587890625, -60140144577.55352783203125 -266094379768.966461181640625))");
try {
boolean b = checkedUtil.regionCheck(wkt, list);

    } catch (ParseException e) {
        e.printStackTrace();
    }

}

    这是执行后得到的结果

    MULTIPOLYGON (((-224350635455.0022 -111836039853.78741, -244254937379.5415 -107965758924.01578, -257524471995.9009 -104648375269.92603, -274664287542.03198 -99119402513.10938, -288486719434.073 -98566505237.42776, -300650459499.0694 -100778094340.15439, -319209182509.98016 -120093567998.94774, -315025788666.7921 -83638278794.0235, -181777545227.51547 -108518656199.69745, -180200885637.2185 -109383275975.02155, -224350635455.0022 -111836039853.78741)), ((-322907561014.1465 -152322294963.8256, -319209182509.9802 -120093567998.94781, -319209182509.98016 -120093567998.94774, -319209182509.98016 -120093567998.94781, -322907561014.1465 -152322294963.8256)), ((-322907561014.1465 -152322294963.8256, -326636631456.1067 -184818480243.76456, -334930090591.3314 -281575503488.0526, -326636631456.10675 -184818480243.76456, -322907561014.1465 -152322294963.8256)), ((-190071004362.7402 -325254388266.9026, -60140144577.553535 -266094379768.9664, -60140144577.55353 -266094379768.96646, -190071004362.7402 -325254388266.9026)), ((-78938651950.72946 -164914178319.22525, -72732287430.19965 -198319022650.312, -60140144577.55353 -266094379768.9664, -60140144577.553535 -266094379768.9664, -78938651950.72946 -164914178319.22525)))

    可是测试的这两个面是用argis画的,不一致的部分也只有一个面呀

    实在没招了,求大佬指教
  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-29 19:10
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    import org.apache.jena.sparql.algebra.arithmetic.BinaryExpression;
    import org.apache.jena.sparql.algebra.arithmetic.UnaryExpression;
    import org.apache.jena.sparql.algebra.expression.*;
    import org.apache.jena.sparql.algebra.function.FunctionCall;
    import org.apache.jena.sparql.algebra.function.FunctionDeclaration;
    import org.apache.jena.sparql.algebra.function.FunctionSignature;
    import org.apache.jena.sparql.algebra.function.FunctionType;
    import org.apache.jena.sparql.algebra.functions.*;
    import org.apache.jena.sparql.algebra.graph.Graph;
    import org.apache.jena.sparql.algebra.graph.GraphFactory;
    import org.apache.jena.sparql.algebra.iter.IterableGraph;
    import org.apache.jena.sparql.algebra.iter.IterableGraphFactory;
    import org.apache.jena.sparql.algebra.iter.Iterables;
    import org.apache.jena.sparql.algebra.iter.Iterator;
    import org.apache.jena.sparql.algebra.iter.IteratorIterator;
    import org.apache.jena.sparql.algebra.iter.ScalarFunction;
    import org.apache.jena.sparql.algebra.iter.Var;
    import org.apache.jena.sparql.core.DatasetGraph;
    import org.apache.jena.sparql.engine.binding.Binding;
    import org.apache.jena.sparql.expr.ExprEvaluatorContext;
    import org.apache.jena.sparql.expr.NodeValue;
    import org.apache.jena.sparql.util.Pair;
    import org.apache.jena.vocabulary.RDF;
    import org.apache.jena.vocabulary.RDFS;
    import org.apache.jena.vocabulary.WS;
    import org.apache.jena.vocabulary.XMLSchema;
    import org.apache.jena.xml.stream.Xpp3Dom;
    import org.w3c.dom.Element;
    
    import java.io.File;
    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeMap;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.stream.Collectors;
    
    public class GeoChecker {
    
        private final DatasetGraph datasetGraph;
    
        public GeoChecker(DatasetGraph datasetGraph) {
            this.datasetGraph = datasetGraph;
        }
    
        public Map<String, Object> checkGeoIntersection(String firstWKT, String secondWKT) {
            // Convert the WKT strings to GeoJSON objects
            Map<String, Object> geoJsonFirst = convertWKTToGeoJson(firstWKT);
            Map<String, Object> geoJsonSecond = convertWKTToGeoJson(secondWKT);
    
            // Get the geometries from the GeoJSON objects
            Geometry geometryFirst = (Geometry) geoJsonFirst.get("geometry");
            Geometry geometrySecond = (Geometry) geoJsonSecond.get("geometry");
    
            // Check if the geometries are equal and return the result
            return new TreeMap<>(geoJsonFirst)
                .entrySet()
                .stream()
                .filter(entry -> entry.getValue().equals(geometryFirst))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        }
    
        private Map<String, Object> convertWKTToGeoJson(String wkt) {
            // Parse the WKT string into a Geometry object
            Geometry geometry = parseWKT(wkt);
    
            // Return the geometry as a GeoJSON object
            return new TreeMap<>(datasetGraph).put("geometry", geometry);
        }
    
        private Geometry parseWKT(String wkt) {
            // Parse the WKT string using the JTS API
            // This is just an example implementation, you should use the correct method depending on your library or framework
            // For example:
            // Geometry geometry = jtsAPI.parseWKT(wkt);
    
            return null; // Placeholder for the actual parsing logic
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 9月4日