I have read one geojson file using JSTS now all my features in the geojson file are comming as individual features. Now I want to convert all features into one collected feature like in postgres function ST_Collect. Is there any way to treat the features into single feature by using Json.stringfy like in JSTS javascript? If any provide examples for reference sir.

<!DOCTYPE html>
    <title>JSTS Integration</title>
    <link rel="stylesheet" href="http://openlayers.org/en/v3.17.1/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="http://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="http://openlayers.org/en/v3.17.1/build/ol.js"></script>
    <script src="https://cdn.rawgit.com/bjornharrtell/jsts/gh-pages/1.2.0/jsts.min.js"></script>
    <div id="map" class="map"></div>
    <button  onclick=withoutaoi();><img src="area.png"></button>

      var source = new ol.source.Vector();

      fetch('flood.geojson').then(function(response) {
        return response.json();
      }).then(function(json) {
        var format = new ol.format.GeoJSON();
        var features = format.readFeatures(json, {featureProjection: 'EPSG:3857'});
        var parser = new jsts.io.OL3Parser();

        for (var i = 0; i < features.length; i++) {
          var feature = features[i];
        // alert(feature

        // feature.forEach(function(features2){

        // alert();
        // });

          var jstsGeom = parser.read(feature.getGeometry());

          //var buffered = jstsGeom.buffer(4);



      alert(" iam two ");
       fetch('vizag_dist.geojson').then(function(response) {
        return response.json();
      }).then(function(json) {
        var format2 = new ol.format.GeoJSON();
         var features2 = format2.readFeatures(json, {featureProjection: 'EPSG:3857'});

        var parser2 = new jsts.io.OL3Parser();

        for (var i = 0; i < features2.length; i++) {

          var feature2 = features2[i];
     // var ext =  parser2.read(feature2.getGeometry().getExtent());
     // alert(ext);
          var jstsGeom2 = parser2.read(feature2.getGeometry());

         // var buffered2 = jstsGeom2.buffer(4);



      function withoutaoi() {



      var vectorLayer = new ol.layer.Vector({
        source: source

      var rasterLayer = new ol.layer.Tile({
        source: new ol.source.OSM()

      var map = new ol.Map({
        layers: [rasterLayer, vectorLayer],
        target: document.getElementById('map'),
        view: new ol.View({
        //projection: 'EPSG:4326',
          center: [79.419,15.428],
          zoom: 8
         // center: ol.proj.fromLonLat([126.979293, 37.528787]),
         // zoom: 15


Here I am trying to perform geojson1.intersects.geojson2 function in the example link https://bl.ocks.org/pgiraud/2ed05b0a9e394c5652b3 ( performed polygon intersection with the geojson file )
Now we want to perform two geojson features intersection using JSTS intersect function is it possible or not. If any other methods exist to read geojson features into single feature is also sufficient to perform intersection operation on geojson files sir.


In JSTS you can collect the geometries like this:

var geometryFactory = new jsts.geom.GeometryFactory();
var multiGeom = geometryFactory.buildGeometry(geoms);

'buildGeometry' will make a MultiLineString if all geometries are LineStrings, a MultiPolygon if all geometries are Polygons, a MultiPoint if all geometries are Points and a GeometryCollection if geometries are mixed.

Once you have collected the geometries then you make a new feature with the attributes you need. There is no one step solution in JSTS, it's a library oriented only to geometry and not to features.

I haven't used yet, but maybe you could be interested in using turf.js library. Is oriented to GeoJSON features and you can do aggregate operations easily, like collect. Here is an example of usage with OpenLayers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.