ソースを参照

修复空指针

欧阳劲驰 2 週間 前
コミット
a00bdcfbfd

+ 24 - 14
src/main/java/com/shkpr/service/alambizplugin/commtools/CRSUtil.java

@@ -98,25 +98,35 @@ public class CRSUtil {
             //构建结果
             CommCRSInfo result = new CommCRSInfo();
             //基本信息
-            result.setName(crs.getName().getCode());
-            result.setCode(crs.getIdentifiers().stream().map(Identifier::getCode).collect(Collectors.joining(",")));
-            result.setDimension(crs.getCoordinateSystem().getDimension());
-            result.setRemarks(crs.getRemarks().toString());
-            result.setAlias(crs.getAlias().stream().map(GenericName::toString).collect(Collectors.toList()));
+            if (crs.getName() != null) result.setName(crs.getName().getCode());
+            if (crs.getIdentifiers() != null)
+                result.setCode(crs.getIdentifiers().stream().map(Identifier::getCode).collect(Collectors.joining(",")));
+            if (crs.getCoordinateSystem() != null) result.setDimension(crs.getCoordinateSystem().getDimension());
+            if (crs.getRemarks() != null) result.setRemarks(crs.getRemarks().toString());
+            if (crs.getAlias() != null)
+                result.setAlias(crs.getAlias().stream().map(GenericName::toString).collect(Collectors.toList()));
             result.setWkt(crs.toWKT());
             //范围
-            result.setBoundingBoxes(crs.getDomainOfValidity().getGeographicElements().stream()
-                    .filter(it -> it instanceof GeographicBoundingBoxImpl)
-                    .map(it -> {
-                        GeographicBoundingBoxImpl boundingBox = (GeographicBoundingBoxImpl) it;
-                        return BeanUtil.copy(boundingBox, CommCRSBoundingBox.class);
-                    }).collect(Collectors.toList()));
-            result.setBoundingBoxDescription(crs.getDomainOfValidity().getDescription().toString());
+            if (crs.getDomainOfValidity() != null) {
+                if (crs.getDomainOfValidity().getGeographicElements() != null)
+                    result.setBoundingBoxes(crs.getDomainOfValidity().getGeographicElements().stream()
+                            .filter(it -> it instanceof GeographicBoundingBoxImpl)
+                            .map(it -> {
+                                GeographicBoundingBoxImpl boundingBox = (GeographicBoundingBoxImpl) it;
+                                return BeanUtil.copy(boundingBox, CommCRSBoundingBox.class);
+                            }).collect(Collectors.toList()));
+                if (crs.getDomainOfValidity().getDescription() != null)
+                    result.setBoundingBoxDescription(crs.getDomainOfValidity().getDescription().toString());
+
+            }
             //基准
             if (crs instanceof DefaultGeographicCRS) {
                 GeodeticDatum datum = ((DefaultGeographicCRS) crs).getDatum();
-                result.setDatumName(datum.getName().getCode());
-                result.setDatumCode(datum.getIdentifiers().stream().map(Identifier::getCode).collect(Collectors.joining(",")));
+                if (datum != null) {
+                    if (datum.getName() != null) result.setDatumName(datum.getName().getCode());
+                    if (datum.getIdentifiers() != null)
+                        result.setDatumCode(datum.getIdentifiers().stream().map(Identifier::getCode).collect(Collectors.joining(",")));
+                }
             }
 
             return result;