Technology Sharing

Using jsts in Vue project openlayers to process the intersection of wkt and geojson-(geojson source zpi analysis)

2024-07-11

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Using jsts in Vue project openlayers to process the intersection of wkt and geojson-(geojson source zpi analysis)

Read the shape in the compressed package and see the previous noteThe Vue project reads the ShapeFile file in the zip and parses it into GeoJson

Openlayers uses jsts official examplehttps://openlayers.org/en/latest/examples/jsts.html

jsts official code address:https://github.com/bjornharrtell/jsts

The geojson format we read from shape is as follows:
insert image description here
There are only some coordinate points of the boundary. The following method intersects geojson and wkt and converts them into wkt and returns:


import { Component, Emit, Vue } from 'vue-property-decorator';
import { mapGetters, mapMutations } from 'vuex';

import WKT from 'ol/format/WKT';
// eslint-disable-next-line import/extensions
import * as jsts from 'jsts/dist/jsts.min.js';
import {
  Geometry,
  GeometryCollection, LinearRing, LineString, MultiLineString, MultiPoint, Point,
} from 'ol/geom';
import Polygon from 'ol/geom/Polygon';
import MultiPolygon from 'ol/geom/MultiPolygon';

@Component({
  name: 'MapMxins',
  computed: {
    ...mapGetters('map', [
      'getDrawingType',
    ]),
  },
  methods: {
    ...mapMutations('map', [
      'updateDrawingType',
    ]),
  },
})
export default class MapMxins extends Vue {
  getDrawingType;
  
  updateDrawingType;
  
  /**
   * 处理工作区范围-如果上传了shpe
   *
   * @params xzqData: 行政区数据
   * @params geojson:工作区范围数据
   * 用工作区范围和行政区范围做相交处理,保留交集就是最后的范围
   * return: {
   *  geom: 工作区范围和行政区相交的geom,如果没有相交或者工作区范围无效则返回行政区geom
   *  isValid: 工作区范围是否有效
   * }
   */
  hansleWorkspace(xzqData, geojson) {
    // console.log('处理工作区范围-如果上传了shpe:', xzqData, geojson);
    const xzqGeom = xzqData.geom; // 行政区geom
    const format = new WKT();
    const parser = new jsts.io.OL3Parser();
    parser.inject(
      Point,
      LineString,
      LinearRing,
      Polygon,
      MultiPoint,
      MultiLineString,
      MultiPolygon,
      GeometryCollection,
    );

    // eslint-disable-next-line consistent-return
    return new Promise((resolve) =