Realize spatial query in cesium (idea analysis plus source code)

Realize spatial query in cesium (idea analysis plus source code)

As the basic means of GIS data analysis, spatial query is also indispensable in 3D GIS. The specific implementation is introduced below.


table of Contents

Realize spatial query in cesium (idea analysis plus source code)

Preface

1. Get the point to be queried

Two, get the face to be queried

Second, the intersection of faces and points

to sum up

Four, more



Preface

If you are not a GIS major, then you may be very unfamiliar with spatial query. Below I will briefly explain what spatial query is. There are many points in a range. You can circle a part of the area at will and find out your circle. What are the points in the area that comes out, this is the spatial query.


1. Get the point to be queried

The first step is to prepare the point data we need to query. Methods as below:

         var res = response.data;
          var Towerspoints = [];
          for (var i = 0; i < res.length; i++) {
            var feature = new Object();
            feature.type = "Feature";
            feature.properties = { Name: res[i].evid };
            feature.geometry = {
              type: "Point",
              coordinates: [res[i].jingdu, res[i].weidu],
            };
            Towerspoints.push(feature);
          }

          TowersCollection = {
            type: "FeatureCollection",
            features: Towerspoints,
          };

Two, get the face to be queried

The second step is to prepare the data of the range (that is, the area object) we need to query. Methods as below:

     var ellipsoid = viewer.scene.globe.ellipsoid;
      for (var i = 0; i < arrPoint.length; i++) {
        var cartograhpinc = ellipsoid.cartesianToCartographic(arrPoint[i]);
        var lng = Cesium.Math.toDegrees(cartograhpinc.longitude); //经度
        var lat = Cesium.Math.toDegrees(cartograhpinc.latitude); //维度
        searchRegion.push([lng, lat]);
      }
      var startPoint = ellipsoid.cartesianToCartographic(arrPoint[0]);
      var lng_S = Cesium.Math.toDegrees(startPoint.longitude);
      var lat_S = Cesium.Math.toDegrees(startPoint.latitude);
      searchRegion.push([lng_S, lat_S]);
      searchWithin.push(searchRegion);
      var searchWithinEntity = Cesium.turf.polygon(searchWithin);
   

Second, the intersection of faces and points

This step is the last step. The space calculation can be done by using the point objects and area objects we prepared in the previous two steps. Here we use the turf library. The method is as follows:

 var ptsWithin = Cesium.turf.pointsWithinPolygon(
        TowersCollection,
        searchWithinEntity
      );

to sum up

1. Mainly the cesium object and the turf object communicate with each other

2. The second is to use the turf interface for intersection calculation

The effect is as follows:

Spatial query
Spatial query results

Four, more

There is a point to be explained here. Due to limited space and time, not all the code has been written. The main implementation ideas are listed here.

If you still don’t understand,

If you still need to communicate with cesium,

Let's study and discuss together.

You can join our base, the address of our base is: 450342630 (QQ group number)

Guess you like

Origin blog.csdn.net/qq_27532167/article/details/108666004