< version > 24.1 </ version > </ dependency > <!-- https://mvnrepository.com/artifact/de.micromata.jak/JavaAPIforKml --> < dependency > < groupId > de.micromata.jak </ groupId > < artifactId > JavaAPIforKml </ artifactId > < version > 2.2.1 </ version > </ dependency > <!--postdreSQL依赖--> < dependency > < groupId > com.baomidou </ groupId > < artifactId > mybatis-plus-generator </ artifactId > < version > 3.3.2 </ version > < scope > provided </ scope > </ dependency > < dependency > < groupId > com.baomidou </ groupId > < artifactId > mybatis-plus-boot-starter </ artifactId > < version > 3.3.2 </ version > </ dependency > < dependency > < groupId > com.baomidou </ groupId > < artifactId > dynamic-datasource-spring-boot-starter </ artifactId > < version > 3.2.0 </ version > </ dependency > < dependency > < groupId > org.postgresql </ groupId > < artifactId > postgresql </ artifactId > </ dependency > < dependency > < groupId > net.postgis </ groupId > < artifactId > postgis-jdbc </ artifactId > < version > 2.5.0 </ version > </ dependency > < dependency > < groupId > com.eyougo </ groupId > < artifactId > mybatis-typehandlers-postgis </ artifactId > < version > 1.0 </ version > < exclusions > < exclusion > < groupId > org.mybatis </ groupId > < artifactId > mybatis </ artifactId > </ exclusion > < exclusion > < groupId > net.postgis </ groupId > < artifactId > postgis-jdbc </ artifactId > </ exclusion > </ exclusions > </ dependency >

存入数据库实体类

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.paramland.geo.component.FeatureSerializer;
import com.paramland.geo.component.GeometrySerializer;
import com.paramland.geo.enumn.DataSourceTypeEnum;
import com.paramland.geo.enumn.GeomCategory;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.simple.SimpleFeature;
 * 标注请求参数
@Data
@ApiModel(value = "标注请求参数", description = "标注请求参数")
public class MarkVo extends BaseVo {
     * 标注图形类型
     * 1: POINT 点
     * 2: LINESTRING 线串
     * 3: POLYGON 多边形
     * 4: MULTIPOINT 多个点
     * 5: MULTILINESTRING 多个线串
     * 6: MULTIPOLYGON 多个多边形
     * 7: GEOMETRYCOLLECTION 几何集合
     * 8: 包围盒,Polygon加上高度值
     * 9: 体
    @ApiModelProperty(value = "标注图形类型 1: POINT 点,2: LINESTRING 线串,3: POLYGON 多边形,4: MULTIPOINT 多个点," +
            "5: MULTILINESTRING 多个线串,6: MULTIPOLYGON 多个多边形,7: GEOMETRYCOLLECTION 几何集合," +
            "8: 包围盒,Polygon加上高度值,9: 体", example = "1")
    private Integer tagType;
     * 标注业务类型
     * 1: 点标绘
     * 2: 测量
     * 3:压平
     * 4:模型标绘
     * 5: 面标绘
     * 6:圆标绘
     * 7:体标绘
     * 8:多段线标绘
     * 9:抛物线标绘
     * 10:曲线标绘
    @ApiModelProperty(value = "业务类型,1: 点标绘,2: 测量,3:压平,4:模型标绘,5: 面标绘,6:圆标绘,7:体标绘,8:多段线标绘," +
            "9:抛物线标绘,10:曲线标绘,11:包围盒,13:直角线标绘,14:墙标绘,15:矩形标绘,16:线标绘,17:条带标绘,18:球体标绘", example = "1")
    private Integer bizType;
     * poi的GeoJson对应的Feature
    @ApiModelProperty(value = "poi的GeoJson对应的Feature", dataType = "com.alibaba.fastjson.JSONObject", example = "{ \"type\": \"Feature\", \"properties\": {}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [106.551808137304,29.687846285011,306.984456211726] } }")
    @JSONField(deserializeUsing = FeatureSerializer.class, serializeUsing = FeatureSerializer.class)
    private SimpleFeature feature;
     * 图形集合时
     * poi的GeoJson对应的GeometryCollection
    @ApiModelProperty(value = "图形集合时,poi的GeoJson对应的GeometryCollection", dataType = "com.alibaba.fastjson.JSONObject", example = "{ \"type\": \"GeometryCollection\", \"geometries\": [{ \"type\": \"Point\", \"coordinates\": [108.62,31.02819,301.44] }, { \"type\": \"LineString\", \"coordinates\": [ [108.896484375, 30.1071178870, 301.22], ] }] }")
    @JSONField(deserializeUsing = GeometrySerializer.class, serializeUsing = GeometrySerializer.class)
    private Geometry geometry;
     * 数据来源
    private DataSourceTypeEnum dataSource = DataSourceTypeEnum.MARK;
     * 是否永久显示,1:是,0:否
    @ApiModelProperty(value = "是否永久显示,1:是,0:否", example = "0")
    private Integer isPermanent;
     * 是否永久显示,1:是,0:否
    @ApiModelProperty(value = "文件bid", example = "0")
    private String fileBid;
     * POI图形偏移量
    @ApiModelProperty(value = "POI图形偏移量", example = "{\"x\":-100,\"y\":100,\"z\":100}")
    private JSON geomOffset;
     * 来源哪一张shp表
    @ApiModelProperty(value = "来源哪一张shp表 导入shp专用")
    private String fromShpResource;
     * 来源哪一张shp表
    @ApiModelProperty(value = "高层值")
    private Double height;
     * 图形分类 1:标绘,2:空间分析
    @ApiModelProperty(value = "图形分类 1:标绘,2:空间分析")
    private GeomCategory geomCategory;

参数实体类

KmlLine(线)

import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
 * @program: ParseKMLForJava
 * @description:
 * @Date 2021/1/11 下午4:50
 * @Version 1.0
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KmlLine {
    private List<Coordinate> points;
    private String name;
    private String description;
    private Integer type = 2 ;

KmlPoint(点)

import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
 * @program: ParseKMLForJava
 * @description:
 * @Date 2021/1/11 下午4:50
 * @Version 1.0
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KmlPoint {
    private List<Coordinate> points;
    private String name;
    private String description;
    private Integer type = 1;

KmlPolygon(面)

import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
 * @program: ParseKMLForJava
 * @description:
 * @Date 2021/1/11 下午4:50
 * @Version 1.0
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KmlPolygon {
    private List<Coordinate> points;
    private String name;
    private String description;
    private Integer type = 3;

KmlProperties(用来存储描述 文本信息)

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
 * @program: ParseKMLForJava
 * @description:
 * @Date 2021/1/11 下午4:50
 * @Version 1.0
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KmlProperties {
   private String name;
   private String description;

KmlProperty(用来存储解析的集合信息)

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
 * @program: ParseKMLForJava
 * @description:
 * @Author Mc QiLing
 * @Date 2021/1/11 下午4:50
 * @Version 1.0
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KmlProperty {
    private List<KmlPoint> kmlPoints;
    private List<KmlLine> kmlLines;
    private List<KmlPolygon> kmlPolygons;

ParsingKmlUtil(用来解析KML信息)

import de.micromata.opengis.kml.v_2_2_0.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 * @program: my_project
 * @description: KML文件解析:先获取kml文件的根节点,依次遍历当前节点的子节点的信息,
 * 如果遇到节点属于Folder、Document则继续解析其子节点;反之则解析PlaceMark节点(主要解析LineString、Point、Polygon)。
 * @create: 2021-01-11 12:39
public class ParsingKmlUtil {
    private List<KmlPoint> kmlPointList = new ArrayList<>();
    private List<KmlLine> kmlLineList = new ArrayList<>();
    private List<KmlPolygon> kmlPolygonList = new ArrayList<>();
    private KmlProperty kmlProperty = new KmlProperty();
     * 保存kml数据到临时表
     * @param file 上传的文件实体
     * @return 自定义的KML文件实体
    public KmlProperty parseKmlForJAK(File file) {
        Kml kml = Kml.unmarshal(file);
        Feature feature = kml.getFeature();
        parseFeature(feature);
        kmlProperty.setKmlPoints(kmlPointList);
        kmlProperty.setKmlLines(kmlLineList);
        kmlProperty.setKmlPolygons(kmlPolygonList);
        return kmlProperty;
     * 解析kml节点信息
     * @param feature 需要解析到要素信息
     * @return
    private void parseFeature(Feature feature) {
        if (feature != null) {
            //判断根节点是否为Document
            if (feature instanceof Document) {
                List<Feature> featureList = ((Document) feature).getFeature();
                //遍历已获取的节点信息(节点信息为List),将list使用forEach进行遍历(同for、while)
                featureList.forEach(documentFeature -> {
                            //判断遍历节点是否为PlaceMark,否则迭代解析
                            if (documentFeature instanceof Placemark) {
                                getPlaceMark((Placemark) documentFeature);
                            } else {
                                parseFeature(documentFeature);
            } else if (feature instanceof Folder) {
                //原理同上
                List<Feature> featureList = ((Folder) feature).getFeature();
                featureList.forEach(documentFeature -> {
                            if (documentFeature instanceof Placemark) {
                                getPlaceMark((Placemark) documentFeature);
                                parseFeature(documentFeature);
     * 解析PlaceMark节点下的信息
     * @return
    private void getPlaceMark(Placemark placemark) {
        String description = placemark.getDescription();
        String name = placemark.getName();
        Geometry geometry = placemark.getGeometry();
        parseGeometry(name,description,geometry);
     * 解析PlaceMark节点下的信息
     * @return
    private void parseGeometry(String name,String description, Geometry geometry) {
        if (geometry != null) {
            if (geometry instanceof Polygon) {
                Polygon polygon = (Polygon) geometry;
                Boundary outerBoundaryIs = polygon.getOuterBoundaryIs();
                if (outerBoundaryIs != null) {
                    LinearRing linearRing = outerBoundaryIs.getLinearRing();
                    if (linearRing != null) {
                        List<Coordinate> coordinates = linearRing.getCoordinates();
                        if (coordinates != null) {
                            outerBoundaryIs = ((Polygon) geometry).getOuterBoundaryIs();
                            addPolygonToList(kmlPolygonList, name, outerBoundaryIs,description);
            } else if (geometry instanceof LineString) {
                LineString lineString = (LineString) geometry;
                List<Coordinate> coordinates = lineString.getCoordinates();
                if (coordinates != null) {
                    coordinates = ((LineString) geometry).getCoordinates();
                    addLineStringToList(kmlLineList, coordinates, name,description);
            } else if (geometry instanceof Point) {
                Point point = (Point) geometry;
                List<Coordinate> coordinates = point.getCoordinates();
                if (coordinates != null) {
                    coordinates = ((Point) geometry).getCoordinates();
                    addPointToList(kmlPointList, coordinates, name ,description);
            } else if (geometry instanceof MultiGeometry) {
                List<Geometry> geometries = ((MultiGeometry) geometry).getGeometry();
                for (Geometry geometryToMult : geometries) {
                    Boundary outerBoundaryIs;
                    List<Coordinate> coordinates;
                    if (geometryToMult instanceof Point) {
                        coordinates = ((Point) geometryToMult).getCoordinates();
                        addPointToList(kmlPointList, coordinates, name, description);
                    } else if (geometryToMult instanceof LineString) {
                        coordinates = ((LineString) geometryToMult).getCoordinates();
                        addLineStringToList(kmlLineList, coordinates, name, description);
                    } else if (geometryToMult instanceof Polygon) {
                        outerBoundaryIs = ((Polygon) geometryToMult).getOuterBoundaryIs();
                        addPolygonToList(kmlPolygonList, name, outerBoundaryIs, description);
     * 将kml中所有面添加到一个list
     * @return
    private void addPolygonToList(List<KmlPolygon> kmlPolygonList, String name, Boundary outerBoundaryIs,String description) {
        LinearRing linearRing;
        List<Coordinate> coordinates;
        linearRing = outerBoundaryIs.getLinearRing();//面
        coordinates = linearRing.getCoordinates();
        KmlPolygon kmlPolygon = new KmlPolygon();
        kmlPolygon.setPoints(coordinates);
        kmlPolygon.setName(name);
        kmlPolygon.setDescription(description);
        kmlPolygonList.add(kmlPolygon);
     * 将kml中所有线添加到一个list
     * @return
    private void addLineStringToList(List<KmlLine> kmlLineList, List<Coordinate> coordinates, String name,String description) {
        KmlLine kmlLine = new KmlLine();
        kmlLine.setPoints(coordinates);
        kmlLine.setName(name);
        kmlLine.setDescription(description);
        kmlLineList.add(kmlLine);
     * 将kml中所有点添加到一个list
     * @return
    private void addPointToList(List<KmlPoint> kmlPointList, List<Coordinate> coordinates, String name,String description) {
        KmlPoint kmlPoint = new KmlPoint();
        kmlPoint.setName(name);
        kmlPoint.setPoints(coordinates);
        kmlPoint.setDescription(description);
        kmlPointList.add(kmlPoint);

CreateFeatureJson(创建GeoJSON–这里可能有更简单方法 我这里是自己手写处理)

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
 * @Author Mc QiLing
 * @Date 2021/1/13 下午5:20
 * @Version 1.0
public class CreateFeatureJson {
    public static String coverString(String jsonString){
        JSONObject parseObject = JSONObject.parseObject(jsonString);
        JSONObject geometry = parseObject.getObject("geometry", JSONObject.class);
        JSONArray coordinates = geometry.getJSONArray("coordinates");
        List<JSONObject> jsonObjectList = JSONObject.parseArray(coordinates.toJSONString(), JSONObject.class);
        List<List<Double>> coordinatesNew = new ArrayList<>();
        for (JSONObject jsonObject : jsonObjectList) {
            ArrayList<Double> doubles = new ArrayList<>();
            Double longitude = jsonObject.getDouble("longitude");
            if (longitude!=null) {
                doubles.add(longitude);
            Double latitude = jsonObject.getDouble("latitude");
            if (latitude!=null) {
                doubles.add(latitude);
            Double altitude = jsonObject.getDouble("altitude");
            if (altitude!=null) {
                doubles.add(altitude);
            coordinatesNew.add(doubles);
        JSONObject geometryNew = new JSONObject();
        geometryNew.put("type",geometry.get("type"));
        geometryNew.put("coordinates",coordinatesNew);
        JSONObject feature = new JSONObject();
        feature.put("type",parseObject.get("type"));
        feature.put("properties",parseObject.get("properties"));
        feature.put("geometry",geometryNew);
        return feature.toJSONString();

UploadUtils(文件上传工具)

import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
 * @Date 2021/1/14 下午3:14
 * @Version 1.0
public class UploadUtils {
    public static List<String> uploadKml(List<MultipartFile> files,String folder) throws Exception {
        ArrayList<String> urlList = new ArrayList<>();
        // 绝对路径
          String projectPath = System.getProperty("user.dir");
          File fileNow = new File(projectPath);
          String strParentDirectory = fileNow.getParent() + folder;
          String fileName = null;
          // 参数为空
          File directory = new File(strParentDirectory);
          if (!directory.isDirectory()) {
            directory.mkdirs();
          String s = UUID.randomUUID().toString();
          String uuid = s.substring(0, s.indexOf("-"));
          String fileUrl = null;
          for (MultipartFile file : files) {
            fileName = file.getOriginalFilename();
            String[] split = fileName.split("\\.");
            // 创建文件夹
            // 参数为空
            String dirName = split[0];
            File fileDirectory = new File(strParentDirectory + "/" + dirName + "-" + uuid);
            if (!fileDirectory.isDirectory()) {
              fileDirectory.mkdirs();
            // 获取文件后缀名
            String suffixName = split[1];
            // 重新生成文件名
            String fName = dirName + "-" + uuid + "." + suffixName;
            fileUrl = "/" + dirName + "-" + uuid + "/" + dirName + "-" + uuid;
            File dest = new File(fileDirectory, fName);
            try {
              file.transferTo(dest);
              System.out.println(fName + "上传成功!");
            } catch (IOException e) {
              System.out.println(fName + "上传异常!" + e);
              String saveUrl=strParentDirectory + fileUrl + ".kml";
              urlList.add(saveUrl);
          return urlList;

CoverCoordinate(可以自定义高层值–不使用 可以不调)

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.operation.TransformException;
 * @Author Mc QiLing
 * @Date 2021/1/14 上午10:24
 * @Version 1.0
public class CoverCoordinate {
    public static SimpleFeature coverCoordinateSystemAndSetHeight(Double height, SimpleFeature feature) throws TransformException, FactoryException {
        Geometry defaultGeometry = (Geometry) feature.getDefaultGeometry();
        for (Coordinate coordinate : defaultGeometry.getCoordinates()) {
            coordinate.setZ(height);
        feature.setDefaultGeometry(defaultGeometry);
        return feature;

生成MarkVO类

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.paramland.geo.entity.vo.MarkVo;
import com.paramland.geo.enumn.DataSourceTypeEnum;
import com.paramland.geo.enumn.GeomCategory;
import com.paramland.geo.utils.GeoJsonUtils;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import org.geotools.geojson.feature.FeatureJSON;
import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.operation.TransformException;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 * @Date 2021/1/12 上午9:51
 * @Version 1.0
public class CreateMvo {
    public static  <T> List<MarkVo> createMvo(List<T> mvo, Integer type,Double height,String fromShpResource,String bid) throws IOException, TransformException, FactoryException {
        List<MarkVo> markVos = new ArrayList<>();
        for (T t : mvo) {
            MarkVo markVo = new MarkVo();
            markVo.setHeight(height);
            markVo.setFromShpResource(fromShpResource);
            markVo.setFileBid(bid);
            String name = null;
            String description = null;
            HashMap<String, Object> geometry = new HashMap<>(16);
            if(1==type){
                KmlPoint k = (KmlPoint)t;
                List<Coordinate> points = k.getPoints();
                name = k.getName();
                description = k.getDescription();
                geometry.put("type","Point");
                geometry.put("coordinates",points);
                markVo.setTagType(1);
                markVo.setBizType(1);
            }else if(2==type){
                KmlLine k = (KmlLine)t;
                name = k.getName();
                description = k.getDescription();
                List<Coordinate> points = k.getPoints();
                markVo.setTagType(2);
                geometry.put("type","LineString");
                geometry.put("coordinates",points);
                markVo.setBizType(16);
            }else if(3==type){
                KmlPolygon k = (KmlPolygon)t;
                name = k.getName();
                description = k.getDescription();
                markVo.setTagType(3);
                List<Coordinate> points = k.getPoints();
                geometry.put("type","Polygon");
                geometry.put("coordinates",points);
                markVo.setBizType(5);
            JSONObject properties = new JSONObject();
            properties.put("name",name);
            properties.put("description",description);
            HashMap<String, Object> featureMap = new HashMap<>(16);
            featureMap.put("type","Feature");
            featureMap.put("geometry",geometry);
            featureMap.put("properties",properties);
            String jsonString = JSON.toJSONString(featureMap);
            if (!StringUtils.isEmpty(jsonString)) {
                String featureMapNew = CreateFeatureJson.coverString(jsonString);
                if (!StringUtils.isEmpty(featureMapNew)) {
                    FeatureJSON featureJSON = GeoJsonUtils.getFjson();
                    SimpleFeature featureNew = featureJSON.readFeature(featureMapNew);;
                    //-1000 用默认高层值
                  if (height!=-1000) {
                        SimpleFeature feature = CoverCoordinate.coverCoordinateSystemAndSetHeight(height, featureNew);
                        markVo.setFeature(feature);
                    }else{
                        Geometry defaultGeometry = (Geometry) featureNew.getDefaultGeometry();
                        double z = defaultGeometry.getCoordinate().getZ();
                        markVo.setFeature(featureNew);
                        markVo.setHeight(z);
                    markVo.setDataSource(DataSourceTypeEnum.IMPORTKML);
                    markVo.setGeomCategory(GeomCategory.PLOTTING);
                    markVos.add(markVo);
        return markVos;

Controller 上传多个KML

@PostMapping("/uploadKml")
    public ApiResponse uploadKml(@RequestParam("files") List<MultipartFile> files ,@RequestParam("height")Double height) throws Exception {
        if (files.isEmpty()) {
            return new ApiResponse();
        List<String> strings = UploadUtils.uploadKml(files, "/kml");
      	//service处理
        ApiResponse apiResponse = iImportShapefile.importKmlFile(strings,height);
        int errorCode = apiResponse.getErrorCode();
        if(errorCode==200){
            for (String str : strings) {
                File file = new File(str);
                deleteDir(file);
        apiResponse.setData(strings);
        return apiResponse;

服务类(service)

@Override
public ApiResponse importKmlFile(List<String> strings, double height) {
  ArrayList<MarkVo> markVos = new ArrayList<>();
  try {
    for (String string : strings) {
      String substring = string.substring(string.lastIndexOf("/") + 1);
      String[] split = substring.split("\\.");
      ImportFile importFile = new ImportFile();
      importFile.setFileType(split[1]);
      importFile.setFileName(split[0]);
      importFile.setFileUrl(string);
      importFile.setIsDelete(1);
      importFile.setIsResolved(1);
      importFileService.save(importFile);
      String bid = importFile.getBid();
      List<MarkVo> markVo = getMarkVo(string,split[0],height,bid);
      markVos.addAll(markVo);
    //保存到数据库
    mapGeometryService.transformAndSave(markVos, height);
    return ApiResponse.success();
  } catch (TransformException | FactoryException | IOException e) {
    e.printStackTrace();
    return ApiResponse.error(e.toString());
private List<MarkVo> getMarkVo(String url,String fromShpResource,double height,String bid) throws TransformException, FactoryException, IOException {
      KmlProperty kmlProperty;
      ParsingKmlUtil parsingKmlUtil =new ParsingKmlUtil();
      File file = new File(url);
      kmlProperty = parsingKmlUtil.parseKmlForJAK(file);
      List<KmlPoint> kmlPoints = kmlProperty.getKmlPoints();
      List<KmlLine> kmlLines = kmlProperty.getKmlLines();
      List<KmlPolygon> kmlPolygons = kmlProperty.getKmlPolygons();
      ArrayList<MarkVo> allMarkVos = new ArrayList<>();
      if(kmlPoints!=null && !kmlPoints.isEmpty()){
        List<MarkVo> mvo = CreateMvo.createMvo(kmlPoints, 1,height,fromShpResource,bid);
        allMarkVos.addAll(mvo);
      if(kmlLines!=null && !kmlLines.isEmpty()){
        List<MarkVo> mvo = CreateMvo.createMvo(kmlLines, 2,height,fromShpResource,bid);
        allMarkVos.addAll(mvo);
      if(kmlPolygons!=null && !kmlPolygons.isEmpty()){
        List<MarkVo> mvo = CreateMvo.createMvo(kmlPolygons, 3,height,fromShpResource,bid);
        allMarkVos.addAll(mvo);
      return allMarkVos;

数据库表设计

CREATE TABLE "public"."tagging_info" (
  "id" int4 NOT NULL DEFAULT nextval('seq_tagging_info'::regclass),
  "create_time" timestamp(6) NOT NULL,
  "update_time" timestamp(6) NOT NULL,
  "version" int4 NOT NULL,
  "bid" varchar(64) COLLATE "pg_catalog"."default" NOT NULL,
  "company_id" int4,
  "project_id" int4,
  "application_id" int4,
  "tag_type" int4,
  "geom" "public"."geometry",
  "centroid" "public"."geometry",
  "central_point" varchar(255) COLLATE "pg_catalog"."default",
  "height" float8,
  "area" float8,
  "volume" float8,
  "line_length" float8,
  "correlated" int2,
  "correlated_cnt" int4,
  "data_source" int4 DEFAULT 1,
  "biz_type" int4 DEFAULT 1,
  "is_permanent" int2 DEFAULT 0,
  "geom_offset" json,
  "from_shp_resource" varchar(255) COLLATE "pg_catalog"."default",
  "dbf_property" text COLLATE "pg_catalog"."default",
  "file_bid" varchar(64) COLLATE "pg_catalog"."default",
  "categories" int4,
  "properties" json,
  CONSTRAINT "tagging_info_pkey" PRIMARY KEY ("id"),
  CONSTRAINT "tagging_info_u_bid" UNIQUE ("bid")
ALTER TABLE "public"."tagging_info" 
  OWNER TO "postgres";
COMMENT ON COLUMN "public"."tagging_info"."id" IS '主键';
COMMENT ON COLUMN "public"."tagging_info"."create_time" IS '创建时间';
COMMENT ON COLUMN "public"."tagging_info"."update_time" IS '更新时间';
COMMENT ON COLUMN "public"."tagging_info"."version" IS '乐观锁';
COMMENT ON COLUMN "public"."tagging_info"."bid" IS '业务主键';
COMMENT ON COLUMN "public"."tagging_info"."company_id" IS '公司id';
COMMENT ON COLUMN "public"."tagging_info"."project_id" IS '项目id';
COMMENT ON COLUMN "public"."tagging_info"."application_id" IS '应用id';
COMMENT ON COLUMN "public"."tagging_info"."tag_type" IS '标注图形类型,1:POINT点,2:LINESTRING线串,3:POLYGON多边形,4:MULTIPOINT多个点,5:MULTILINESTRING多个线串,6:MULTIPOLYGON多个多边形,7:GEOMETRYCOLLECTION几何集合,8:包围盒,9:体';
COMMENT ON COLUMN "public"."tagging_info"."geom" IS '标注POI几何信息';
COMMENT ON COLUMN "public"."tagging_info"."centroid" IS '形心';
COMMENT ON COLUMN "public"."tagging_info"."central_point" IS '中心点';
COMMENT ON COLUMN "public"."tagging_info"."height" IS '高度,类型为包围盒有高度';
COMMENT ON COLUMN "public"."tagging_info"."area" IS '面积';
COMMENT ON COLUMN "public"."tagging_info"."volume" IS '体积';
COMMENT ON COLUMN "public"."tagging_info"."line_length" IS '长度';
COMMENT ON COLUMN "public"."tagging_info"."correlated" IS '是否已经关联1是0否';
COMMENT ON COLUMN "public"."tagging_info"."correlated_cnt" IS '关联次数';
COMMENT ON COLUMN "public"."tagging_info"."data_source" IS '数据来源 1:标绘 2:shape文件导入';
COMMENT ON COLUMN "public"."tagging_info"."biz_type" IS '业务类型,1:标绘,2:测量,3:压平,4:模型';
COMMENT ON COLUMN "public"."tagging_info"."is_permanent" IS '是否永久显示,1是0否';
COMMENT ON COLUMN "public"."tagging_info"."geom_offset" IS 'POI图形偏移量';
COMMENT ON COLUMN "public"."tagging_info"."from_shp_resource" IS '来源哪一张shp表';
COMMENT ON COLUMN "public"."tagging_info"."dbf_property" IS '对应的属性及其属性值';
COMMENT ON COLUMN "public"."tagging_info"."file_bid" IS '关联文件bid';
COMMENT ON COLUMN "public"."tagging_info"."categories" IS '分类:1:标绘,2:空间分析';
COMMENT ON COLUMN "public"."tagging_info"."properties" IS '画图属性参数,JSON格式';
COMMENT ON TABLE "public"."tagging_info" IS '标注POI信息表';
这个是第一个版本 写个个人感觉 太复杂 也许还有更好的方法 批量处理KML 将多类型存入数据库 希望提出和交流
                    KML 导入postgreSQL 数据库依赖导入&lt;!--geotools 工具类--&gt;&lt;dependency&gt;		&lt;groupId&gt;org.geotools&lt;/groupId&gt;		&lt;artifactId&gt;gt-geojson&lt;/artifactId&gt;		&lt;version&gt;24.1&lt;/version&gt;&lt;/dependency&gt;&lt;dependency&gt;  &lt;group
org.geotools.arcsde.data 
org.geotools.arcsde.data.versioning 
org.geotools.arcsde.data.view 
org.geotools.arcsde.filter 
org.geotools.arcsde.gce 
org.geotools.arcsde.gce.band 
org.geotools.arcsde.gce.imageio 
org.geotools.arcsde.gce.producer 
org.geotools.arcsde.pool 
org.geotools.axis 
org.geotools.brewer.color 
org.geotools.coverage 
org.geotools.coverage.grid 
org.geotools.coverage.grid.io 
org.geotools.coverage.grid.io.imageio 
org.geotools.coverage.io 
org.geotools.coverage.processing 
org.geotools.coverage.processing.operation 
org.geotools.data 
org.geotools.data.collection 
org.geotools.data.crs 
org.geotools.data.db2 
org.geotools.data.db2.filter 
org.geotools.data.dir 
org.geotools.data.gml 
org.geotools.data.gpx 
org.geotools.data.gpx.temporal 
org.geotools.data.h2 
org.geotools.data.jdbc 
org.geotools.data.jdbc.attributeio 
org.geotools.data.jdbc.datasource 
org.geotools.data.jdbc.fidmapper 
org.geotools.data.jdbc.referencing 
org.geotools.data.memory 
org.geotools.data.mif 
org.geotools.data.mysql 
org.geotools.data.oracle 
org.geotools.data.oracle.attributeio 
org.geotools.data.oracle.referencing 
org.geotools.data.oracle.sdo 
org.geotools.data.ows 
org.geotools.data.postgis 
org.geotools.data.postgis.attributeio 
org.geotools.data.postgis.collection 
org.geotools.data.postgis.fidmapper 
org.geotools.data.postgis.referencing 
org.geotools.data.property 
org.geotools.data.shapefile 
org.geotools.data.shapefile.dbf 
org.geotools.data.shapefile.indexed 
org.geotools.data.shapefile.indexed.attribute 
org.geotools.data.shapefile.prj 
org.geotools.data.shapefile.shp 
org.geotools.data.shapefile.shp.xml 
org.geotools.data.store 
org.geotools.data.tiger 
org.geotools.data.view 
org.geotools.data.vpf 
org.geotools.data.vpf.exc 
org.geotools.data.vpf.file 
org.geotools.data.vpf.ifc 
org.geotools.data.vpf.io 
org.geotools.data.vpf.readers 
org.geotools.data.vpf.util 
org.geotools.data.wfs 
org.geotools.data.wms 
org.geotools.data.wms.request 
org.geotools.data.wms.response 
org.geotools.data.wms.xml 
org.geotools.demo 
org.geotools.demo.data 
org.geotools.demo.example 
org.geotools.demo.features 
org.geotools.demo.geometry 
org.geotools.demo.introduction 
org.geotools.demo.jts 
org.geotools.demo.libraryJTS 
org.geotools.demo.main 
org.geotools.demo.mappane 
org.geotools.demo.metadata.example 
org.geotools.demo.postgis 
org.geotools.demo.swing 
org.geotools.demo.swing.process 
org.geotools.demo.widgets 
org.geotools.demo.xml 
org.geotools.display.canvas 
org.geotools.display.canvas.map 
org.geotools.display.event 
org.geotools.display.geom 
org.geotools.display.style 
org.geotools.factory 
org.geotools.feature 
org.geotools.feature.collection 
org.geotools.feature.simple 
org.geotools.feature.type 
org.geotools.feature.visitor 
org.geotools.filter 
org.geotools.filter.capability 
org.geotools.filter.expression 
org.geotools.filter.function 
org.geotools.filter.function.math 
org.geotools.filter.identity 
org.geotools.filter.parser 
org.geotools.filter.spatial 
org.geotools.filter.text.cql2 
org.geotools.filter.text.txt 
org.geotools.filter.v1_0 
org.geotools.filter.v1_0.capabilities 
org.geotools.filter.v1_1 
org.geotools.filter.v1_1.capabilities 
org.geotools.filter.visitor 
org.geotools.gce.arcgrid 
org.geotools.gce.geotiff 
org.geotools.gce.geotiff.crs_adapters 
org.geotools.gce.geotiff.IIOMetadataAdpaters 
org.geotools.gce.geotiff.IIOMetadataAdpaters.utils 
org.geotools.gce.geotiff.IIOMetadataAdpaters.utils.codes 
org.geotools.gce.gtopo30 
org.geotools.gce.image 
org.geotools.gce.imagemosaic 
org.geotools.gce.imagepyramid 
org.geotools.geometry 
org.geotools.geometry.array 
org.geotools.geometry.coordinatesequence 
org.geotools.geometry.iso 
org.geotools.geometry.iso.aggregate 
org.geotools.geometry.iso.complex 
org.geotools.geometry.iso.coordinate 
org.geotools.geometry.iso.index 
org.geotools.geometry.iso.index.quadtree 
org.geotools.geometry.iso.io 
org.geotools.geometry.iso.io.wkt 
org.geotools.geometry.iso.operation 
org.geotools.geometry.iso.operation.overlay 
org.geotools.geometry.iso.operation.relate 
org.geotools.geometry.iso.primitive 
org.geotools.geometry.iso.root 
org.geotools.geometry.iso.topograph2D 
org.geotools.geometry.iso.topograph2D.index 
org.geotools.geometry.iso.topograph2D.util 
org.geotools.geometry.iso.util 
org.geotools.geometry.iso.util.algorithm2D 
org.geotools.geometry.iso.util.algorithmND 
org.geotools.geometry.iso.util.elem2D 
org.geotools.geometry.iso.util.interpolation 
org.geotools.geometry.iso.util.topology 
org.geotools.geometry.jts 
org.geotools.geometry.jts.coordinatesequence 
org.geotools.geometry.jts.spatialschema 
org.geotools.geometry.jts.spatialschema.geometry 
org.geotools.geometry.jts.spatialschema.geometry.aggregate 
org.geotools.geometry.jts.spatialschema.geometry.complex 
org.geotools.geometry.jts.spatialschema.geometry.geometry 
org.geotools.geometry.jts.spatialschema.geometry.primitive 
org.geotools.geometry.text 
org.geotools.gml 
org.geotools.gml.producer 
org.geotools.gml2 
org.geotools.gml2.bindings 
org.geotools.gml3 
org.geotools.gml3.bindings 
org.geotools.gml3.bindings.smil 
org.geotools.gml3.smil 
org.geotools.gpx 
org.geotools.gpx.bean 
org.geotools.gpx.binding 
org.geotools.graph.build 
org.geotools.graph.build.basic 
org.geotools.graph.build.feature 
org.geotools.graph.build.line 
org.geotools.graph.build.opt 
org.geotools.graph.build.polygon 
org.geotools.graph.io 
org.geotools.graph.io.standard 
org.geotools.graph.path 
org.geotools.graph.structure 
org.geotools.graph.structure.basic 
org.geotools.graph.structure.line 
org.geotools.graph.structure.opt 
org.geotools.graph.traverse 
org.geotools.graph.traverse.basic 
org.geotools.graph.traverse.standard 
org.geotools.graph.util 
org.geotools.graph.util.delaunay 
org.geotools.graph.util.geom 
org.geotools.graph.util.graph 
org.geotools.gui.headless 
org.geotools.gui.swing 
org.geotools.gui.swing.contexttree 
org.geotools.gui.swing.contexttree.column 
org.geotools.gui.swing.contexttree.node 
org.geotools.gui.swing.contexttree.popup 
org.geotools.gui.swing.contexttree.renderer 
org.geotools.gui.swing.crschooser 
org.geotools.gui.swing.datachooser 
org.geotools.gui.swing.datachooser.model 
org.geotools.gui.swing.demo 
org.geotools.gui.swing.event 
org.geotools.gui.swing.filter 
org.geotools.gui.swing.icon 
org.geotools.gui.swing.image 
org.geotools.gui.swing.map.map2d 
org.geotools.gui.swing.map.map2d.control 
org.geotools.gui.swing.map.map2d.decoration 
org.geotools.gui.swing.map.map2d.event 
org.geotools.gui.swing.map.map2d.handler 
org.geotools.gui.swing.map.map2d.listener 
org.geotools.gui.swing.map.map2d.strategy 
org.geotools.gui.swing.misc 
org.geotools.gui.swing.misc.filter 
org.geotools.gui.swing.misc.Render 
org.geotools.gui.swing.process 
org.geotools.gui.swing.propertyedit 
org.geotools.gui.swing.propertyedit.filterproperty 
org.geotools.gui.swing.propertyedit.model 
org.geotools.gui.swing.propertyedit.styleproperty 
org.geotools.gui.swing.referencing 
org.geotools.gui.swing.style 
org.geotools.gui.swing.style.sld 
org.geotools.gui.swing.table 
org.geotools.gui.swing.tree 
org.geotools.image 
org.geotools.image.io 
org.geotools.image.io.metadata 
org.geotools.image.io.mosaic 
org.geotools.image.io.netcdf 
org.geotools.image.io.stream 
org.geotools.image.io.text 
org.geotools.image.jai 
org.geotools.image.palette 
org.geotools.index 
org.geotools.index.quadtree 
org.geotools.index.quadtree.fs 
org.geotools.index.rtree 
org.geotools.index.rtree.cachefs 
org.geotools.index.rtree.database 
org.geotools.index.rtree.database.mysql 
org.geotools.index.rtree.fs 
org.geotools.index.rtree.memory 
org.geotools.io 
org.geotools.jdbc 
org.geotools.kml 
org.geotools.kml.bindings 
org.geotools.legend 
org.geotools.map 
org.geotools.map.event 
org.geotools.math 
org.geotools.measure 
org.geotools.metadata 
org.geotools.metadata.iso 
org.geotools.metadata.iso.citation 
org.geotools.metadata.iso.constraint 
org.geotools.metadata.iso.content 
org.geotools.metadata.iso.distribution 
org.geotools.metadata.iso.extent 
org.geotools.metadata.iso.identification 
org.geotools.metadata.iso.lineage 
org.geotools.metadata.iso.maintenance 
org.geotools.metadata.iso.quality 
org.geotools.metadata.iso.spatial 
org.geotools.metadata.sql 
org.geotools.nature 
org.geotools.openoffice 
org.geotools.ows 
org.geotools.ows.bindings 
org.geotools.ows.v1_1 
org.geotools.parameter 
org.geotools.process 
org.geotools.process.impl 
org.geotools.process.literal 
org.geotools.referencing 
org.geotools.referencing.crs 
org.geotools.referencing.cs 
org.geotools.referencing.datum 
org.geotools.referencing.example 
org.geotools.referencing.factory 
org.geotools.referencing.factory.epsg 
org.geotools.referencing.factory.wms 
org.geotools.referencing.operation 
org.geotools.referencing.operation.builder 
org.geotools.referencing.operation.matrix 
org.geotools.referencing.operation.projection 
org.geotools.referencing.operation.transform 
org.geotools.referencing.piecewise 
org.geotools.referencing.wkt 
org.geotools.renderer 
org.geotools.renderer.i18n 
org.geotools.renderer.lite 
org.geotools.renderer.lite.gridcoverage2d 
org.geotools.renderer.shape 
org.geotools.renderer.shape.shapehandler.jts 
org.geotools.renderer.shape.shapehandler.simple 
org.geotools.renderer.style 
org.geotools.repository 
org.geotools.repository.adaptable 
org.geotools.repository.defaults 
org.geotools.repository.postgis 
org.geotools.repository.property 
org.geotools.repository.shapefile 
org.geotools.repository.styling 
org.geotools.repository.wfs 
org.geotools.repository.wms 
org.geotools.sld 
org.geotools.sld.bindings 
org.geotools.styling 
org.geotools.styling.visitor 
org.geotools.svg 
org.geotools.test 
org.geotools.text 
org.geotools.text.filter 
org.geotools.util 
org.geotools.util.logging 
org.geotools.utils 
org.geotools.utils.coveragetiler 
org.geotools.utils.imagemosaic 
org.geotools.utils.imageoverviews 
org.geotools.utils.imagepyramid 
org.geotools.utils.progress 
org.geotools.validation 
org.geotools.validation.attributes 
org.geotools.validation.dto 
org.geotools.validation.network 
org.geotools.validation.relate 
org.geotools.validation.spatial 
org.geotools.validation.xml 
org.geotools.wfs 
org.geotools.wfs.bindings 
org.geotools.wfs.protocol 
org.geotools.wfs.v_1_0_0.data 
org.geotools.wfs.v_1_1_0.data 
org.geotools.xlink 
org.geotools.xml 
org.geotools.xml.filter 
org.geotools.xml.gml 
org.geotools.xml.handlers 
org.geotools.xml.handlers.xsi 
org.geotools.xml.impl 
org.geotools.xml.impl.jxpath 
org.geotools.xml.schema 
org.geotools.xml.schema.impl 
org.geotools.xml.styling 
org.geotools.xml.test 
org.geotools.xml.transform 
org.geotools.xml.wfs 
org.geotools.xml.xLink 
org.geotools.xml.xsi 
org.geotools.xs 
org.geotools.xs.bindings 
org.geotools.xs.facets
最近在做利用geotools导入shp文件到Oracle表中,发现一个问题Oracle表名带下划线时导入失败,问题代码行: dsOracle.getFeatureWriterAppend(oracleTable, Transaction.AUTO_COMMIT); dsOracle为org.geotools.data.DataStore类型对象
解决方案:
网上查阅资料发现是Oracle11的java包ojdbc的版本问题,maven中搜索ojdbc发现最新版如下图
pom配置:
<!-- https://mvnrepository.com/artifact/ojdbc/
https://stackoverflow.com/questions/44068177/hibernate-spatial-mysql-5-7
https://blog.csdn.net/dream8062/article/details/80363198
				
GeoJson是一种对各种地理数据结构进行编码的格式,基于json的地理空间信息数据交换格式。GeoJson对象可以用来表示几何,特征或者特征集合。支持地理点、线、面、多点、多线、多面及几何集合。GeoJson不是本文的重点,因此不再赘述。 PostGIS是在对象关系型数据库PostgreSQL上增加了存储管理空间数据的能力的开源GIS数据库。本文的例子不能直接运行在PostgreSql数据库上,需要装扩展依赖才行(具体可参考某度的详细教程)。 本......
GIS开发对数据的操作,主要是对空间数据的操作。PostgreSql提供了一些处理空间数据的函数,操作起来是比较方便的。下面就记录一下,最近做项目里面用到的一些,也是比较常用的。 介绍这些函数之前,先了解一下什么是空间数据。空间数据是指用来表示空间实体的位置、形状、大小及其分布特征诸多方面信息的数据,它可以用来描述来自现实世界的目标,它具有定位、定性、时间和空间关系等特性。空间数据是一种用点、线、面以及实体等基本空间数据结构来表示人们赖以生存的自然世界的数据。简单来说,操作空间数据主要是对点、线、
这边有个不错的参考文章: Maven中GeoTools的引入 - Maven 的 repository 与 mirror https://blog.csdn.net/sky_tree_delivery/article/details/105415048 下载pom.xml里引入一下仓库 <repository> <id>osgeo</id> <name>OSGeo Release Repository</name>
好的,如果您出现了获取 geojson SimpleFeatureType 失败的问题,可能是由于以下原因: 1. 文件路径不正确:请确保您的文件路径是正确的,并且可以被您的程序访问。 2. 文件格式错误:请确保您的文件是符合 geojson 格式的,并且可以被 geotools 解析。 3. 编码问题:请确保您的文件的编码方式正确,并且可以被 geotools 正确解析。 对于如何读取 geojson SimpleFeatureType,您可以参考以下代码: ```java // 1. 创建一个 GeoJSON 文件对象 File file = new File("path/to/your/geojson/file"); // 2. 创建一个 GeoJSON 数据存储对象 DataStore dataStore = DataStoreFinder.getDataStore(Collections.singletonMap("url", file.toURI().toURL())); // 3. 获取 GeoJSON 数据的 FeatureSource 对象 SimpleFeatureSource featureSource = dataStore.getFeatureSource(dataStore.getTypeNames()[0]); // 4. 获取 FeatureCollection 对象 FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = featureSource.getFeatures(); // 5. 遍历 FeatureCollection 对象 try (FeatureIterator<SimpleFeature> features = featureCollection.features()) { while (features.hasNext()) { SimpleFeature feature = features.next(); // 在这里处理每个 feature 如果您还有其它问题或者需要更详细的帮助,请告诉我。
<update id="updateStandingBookBatch"> UPDATE sta_${tableName} SET <foreach collection="map.entrySet()" item="value" index="key" separator="," > <if test="key!='id'"> ${key} = #{value} </foreach> <foreach collection="map.entrySet()" item="value" index="key" separator="," > <if test="key=='id'"> where id = #{value} </foreach> </update> # 插入数据 <insert id="insetBanchImp"> INSERT INTO sta_${tableName} <foreach collection="keys" item="item" open="(" separator="," close=")" index="no" > ${item} </foreach> VALUES <foreach item="items" index="index" collection="maps" separator="," > <foreach item="item" index="index" collection="items.keys" open="(" separator="," close=")" > ${item} </foreach> </foreach> </insert> 看看最后这个Mapper 比service 更有用
easyExcel导入 无模版 实体类导入 自定义表头 存入数据库 上官少云: 请问博主iStandingBookMangerService是哪里来的