Buffering in OpenLayers 3?Splitting a line into two in OpenLayersImplementing WPS client in OpenLayers...

Is Screenshot Time-tracking Common?

Why write a book when there's a movie in my head?

Do these large-scale, human power-plant-tending robots from the Matrix movies have a name, in-universe or out?

What is the reward?

Distribution of sum of independent exponentials with random number of summands

3D buried view in Tikz

In the Lost in Space intro why was Dr. Smith actor listed as a special guest star?

Spells that would be effective against a Modern Day army but would NOT destroy a fantasy one

How can I differentiate duration vs starting time

What is formjacking?

Why does this quiz question say that protons and electrons do not combine to form neutrons?

Build ASCII Podiums

Why is Shelob considered evil?

How does holding onto an active but un-used credit card affect your ability to get a loan?

If I have Haste cast on me, does it reduce the casting time for my spells that normally take more than a turn to cast?

How can a Sorcerer/Warlock use 4 Eldritch blasts in one round?

What does @ mean in a hostname in DNS configuration?

What's the meaning of #0?

Checking if an integer permutation is cyclic in Java

What does "don't have a baby" imply or mean in this sentence?

Why don't you get burned by the wood benches in a sauna?

How can I handle players killing my NPC outside of combat?

Can you say "leftside right"?

How can guns be countered by melee combat without raw-ability or exceptional explanations?



Buffering in OpenLayers 3?


Splitting a line into two in OpenLayersImplementing WPS client in OpenLayers 3?Buffering a polylineCreating buffer around WFS features to ease their selection in OpenLayers 2?QGIS 2.12.3 Crashes on buffering line vectorsBuffering multiple features with Geoserver WPSHow to do line based accuracy assessment with pyqgisGeoJSON layer will not display anything in OpenLayers 3?OpenLayers layer-switcher for WMS layersResample rasters after buffering in R













1















I have some line layers ,I wan't to create 0.5km and 1km buffer around the lines.



How to create the the buffer in OpenLayers 3 and which layer use like wms,wps or wfs?










share|improve this question





























    1















    I have some line layers ,I wan't to create 0.5km and 1km buffer around the lines.



    How to create the the buffer in OpenLayers 3 and which layer use like wms,wps or wfs?










    share|improve this question



























      1












      1








      1


      1






      I have some line layers ,I wan't to create 0.5km and 1km buffer around the lines.



      How to create the the buffer in OpenLayers 3 and which layer use like wms,wps or wfs?










      share|improve this question
















      I have some line layers ,I wan't to create 0.5km and 1km buffer around the lines.



      How to create the the buffer in OpenLayers 3 and which layer use like wms,wps or wfs?







      openlayers buffer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 1 '17 at 10:13









      PolyGeo

      53.5k1780240




      53.5k1780240










      asked Jun 1 '17 at 8:55









      Seema BarateSeema Barate

      739




      739






















          2 Answers
          2






          active

          oldest

          votes


















          2














          You can use the JSTS library to do the buffer, which can then be converted to OpenLayers. This is demonstrated in the buffer example among those featured by OpenLayers.



          Here's a snippet:



          // feature is an instance of ol.Feature
          var feature;

          // convert the OpenLayers geometry to a JSTS geometry
          var jstsGeom = parser.read(feature.getGeometry());

          // create a buffer of 40 meters around each line
          var buffered = jstsGeom.buffer(40);

          // convert back from JSTS and replace the geometry on the feature
          feature.setGeometry(parser.write(buffered));





          share|improve this answer































            0














            I also was interested in creating buffers around features but discovered the inaccuracies of the spherical mercator projection. Using JSTS it's possible to add buffers which are reasonably accurate (distance-wise) if you convert the first (or only) coordinate of the feature to a projection for your region. In my example I use North Carolina State Plane EPSG:32119. Then, I add the length of the buffer (in meters) to one dimension to form another point, the buffer length distance away. These two points form a line, the length of which is converted to a spherical mercator distance which is then used as the buffer distance in the JSTS code.



            The routine is incorporated in my drag-and-drop code and applies to GeoJSON files only.



            ol.proj.proj4.register(proj4);
            var sp_projection = ol.proj.get('EPSG:32119');
            var vectorSource = new ol.source.Vector();
            var ddvector = new ol.layer.Vector({
            opacity: 1.0,
            visible: 0,
            source: vectorSource,
            style: styleFunction
            });



            var dragAndDropInteraction = new ol.interaction.DragAndDrop({
            formatConstructors: [ ol.format.GPX, ol.format.GeoJSON, ol.format.IGC, ol.format.KML, ol.format.TopoJSON ]
            });



            var map = new ol.Map({
            interactions: ol.interaction.defaults().extend([dragAndDropInteraction]),
            ...
            });



            dragAndDropInteraction.on('addfeatures', function(event) {
            ddvector.setVisible(true);
            vectorSource.addFeatures(event.features, event.projection);
            if(event.file.name.endsWith(".geojson") == true && document.getElementById('buff').value > '') {
            var bufferSource = new ol.source.Vector();
            var parser = new jsts.io.OL3Parser();
            for (var i = 0; i < event.features.length; i++) {
            var feature = event.features[i];
            var jstsGeom = parser.read(feature.getGeometry());
            if(feature.getGeometry().getType() == 'Point') { var pttype = feature.getGeometry().getCoordinates(); } else { var pttype = feature.getGeometry().getFirstCoordinate(); }
            var point_sp = ol.proj.transform(pttype, 'EPSG:3857', sp_projection);
            var point_buff_sp = [point_sp[0], point_sp[1] + parseFloat(document.getElementById('buff').value)]; /* html element 'buff' holds length value */
            var buffy = ( new ol.geom.LineString([ ol.proj.transform([ point_sp[0], point_sp[1] ], sp_projection, 'EPSG:3857'), ol.proj.transform([ point_buff_sp[0], point_buff_sp[1] ], sp_projection, 'EPSG:3857') ], 'XY') ).getLength(); /* converts line 'buff' state plane meters long to a spherical mercator line and calculates length (buffy)*/
            var buffered = jstsGeom.buffer(buffy);
            feature.setGeometry(parser.write(buffered));
            }
            }
            map.getView().fit( vectorSource.getExtent(), (map.getSize()) );
            });





            share























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "79"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f242402%2fbuffering-in-openlayers-3%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              You can use the JSTS library to do the buffer, which can then be converted to OpenLayers. This is demonstrated in the buffer example among those featured by OpenLayers.



              Here's a snippet:



              // feature is an instance of ol.Feature
              var feature;

              // convert the OpenLayers geometry to a JSTS geometry
              var jstsGeom = parser.read(feature.getGeometry());

              // create a buffer of 40 meters around each line
              var buffered = jstsGeom.buffer(40);

              // convert back from JSTS and replace the geometry on the feature
              feature.setGeometry(parser.write(buffered));





              share|improve this answer




























                2














                You can use the JSTS library to do the buffer, which can then be converted to OpenLayers. This is demonstrated in the buffer example among those featured by OpenLayers.



                Here's a snippet:



                // feature is an instance of ol.Feature
                var feature;

                // convert the OpenLayers geometry to a JSTS geometry
                var jstsGeom = parser.read(feature.getGeometry());

                // create a buffer of 40 meters around each line
                var buffered = jstsGeom.buffer(40);

                // convert back from JSTS and replace the geometry on the feature
                feature.setGeometry(parser.write(buffered));





                share|improve this answer


























                  2












                  2








                  2







                  You can use the JSTS library to do the buffer, which can then be converted to OpenLayers. This is demonstrated in the buffer example among those featured by OpenLayers.



                  Here's a snippet:



                  // feature is an instance of ol.Feature
                  var feature;

                  // convert the OpenLayers geometry to a JSTS geometry
                  var jstsGeom = parser.read(feature.getGeometry());

                  // create a buffer of 40 meters around each line
                  var buffered = jstsGeom.buffer(40);

                  // convert back from JSTS and replace the geometry on the feature
                  feature.setGeometry(parser.write(buffered));





                  share|improve this answer













                  You can use the JSTS library to do the buffer, which can then be converted to OpenLayers. This is demonstrated in the buffer example among those featured by OpenLayers.



                  Here's a snippet:



                  // feature is an instance of ol.Feature
                  var feature;

                  // convert the OpenLayers geometry to a JSTS geometry
                  var jstsGeom = parser.read(feature.getGeometry());

                  // create a buffer of 40 meters around each line
                  var buffered = jstsGeom.buffer(40);

                  // convert back from JSTS and replace the geometry on the feature
                  feature.setGeometry(parser.write(buffered));






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 1 '17 at 12:28









                  Alexandre DubéAlexandre Dubé

                  45124




                  45124

























                      0














                      I also was interested in creating buffers around features but discovered the inaccuracies of the spherical mercator projection. Using JSTS it's possible to add buffers which are reasonably accurate (distance-wise) if you convert the first (or only) coordinate of the feature to a projection for your region. In my example I use North Carolina State Plane EPSG:32119. Then, I add the length of the buffer (in meters) to one dimension to form another point, the buffer length distance away. These two points form a line, the length of which is converted to a spherical mercator distance which is then used as the buffer distance in the JSTS code.



                      The routine is incorporated in my drag-and-drop code and applies to GeoJSON files only.



                      ol.proj.proj4.register(proj4);
                      var sp_projection = ol.proj.get('EPSG:32119');
                      var vectorSource = new ol.source.Vector();
                      var ddvector = new ol.layer.Vector({
                      opacity: 1.0,
                      visible: 0,
                      source: vectorSource,
                      style: styleFunction
                      });



                      var dragAndDropInteraction = new ol.interaction.DragAndDrop({
                      formatConstructors: [ ol.format.GPX, ol.format.GeoJSON, ol.format.IGC, ol.format.KML, ol.format.TopoJSON ]
                      });



                      var map = new ol.Map({
                      interactions: ol.interaction.defaults().extend([dragAndDropInteraction]),
                      ...
                      });



                      dragAndDropInteraction.on('addfeatures', function(event) {
                      ddvector.setVisible(true);
                      vectorSource.addFeatures(event.features, event.projection);
                      if(event.file.name.endsWith(".geojson") == true && document.getElementById('buff').value > '') {
                      var bufferSource = new ol.source.Vector();
                      var parser = new jsts.io.OL3Parser();
                      for (var i = 0; i < event.features.length; i++) {
                      var feature = event.features[i];
                      var jstsGeom = parser.read(feature.getGeometry());
                      if(feature.getGeometry().getType() == 'Point') { var pttype = feature.getGeometry().getCoordinates(); } else { var pttype = feature.getGeometry().getFirstCoordinate(); }
                      var point_sp = ol.proj.transform(pttype, 'EPSG:3857', sp_projection);
                      var point_buff_sp = [point_sp[0], point_sp[1] + parseFloat(document.getElementById('buff').value)]; /* html element 'buff' holds length value */
                      var buffy = ( new ol.geom.LineString([ ol.proj.transform([ point_sp[0], point_sp[1] ], sp_projection, 'EPSG:3857'), ol.proj.transform([ point_buff_sp[0], point_buff_sp[1] ], sp_projection, 'EPSG:3857') ], 'XY') ).getLength(); /* converts line 'buff' state plane meters long to a spherical mercator line and calculates length (buffy)*/
                      var buffered = jstsGeom.buffer(buffy);
                      feature.setGeometry(parser.write(buffered));
                      }
                      }
                      map.getView().fit( vectorSource.getExtent(), (map.getSize()) );
                      });





                      share




























                        0














                        I also was interested in creating buffers around features but discovered the inaccuracies of the spherical mercator projection. Using JSTS it's possible to add buffers which are reasonably accurate (distance-wise) if you convert the first (or only) coordinate of the feature to a projection for your region. In my example I use North Carolina State Plane EPSG:32119. Then, I add the length of the buffer (in meters) to one dimension to form another point, the buffer length distance away. These two points form a line, the length of which is converted to a spherical mercator distance which is then used as the buffer distance in the JSTS code.



                        The routine is incorporated in my drag-and-drop code and applies to GeoJSON files only.



                        ol.proj.proj4.register(proj4);
                        var sp_projection = ol.proj.get('EPSG:32119');
                        var vectorSource = new ol.source.Vector();
                        var ddvector = new ol.layer.Vector({
                        opacity: 1.0,
                        visible: 0,
                        source: vectorSource,
                        style: styleFunction
                        });



                        var dragAndDropInteraction = new ol.interaction.DragAndDrop({
                        formatConstructors: [ ol.format.GPX, ol.format.GeoJSON, ol.format.IGC, ol.format.KML, ol.format.TopoJSON ]
                        });



                        var map = new ol.Map({
                        interactions: ol.interaction.defaults().extend([dragAndDropInteraction]),
                        ...
                        });



                        dragAndDropInteraction.on('addfeatures', function(event) {
                        ddvector.setVisible(true);
                        vectorSource.addFeatures(event.features, event.projection);
                        if(event.file.name.endsWith(".geojson") == true && document.getElementById('buff').value > '') {
                        var bufferSource = new ol.source.Vector();
                        var parser = new jsts.io.OL3Parser();
                        for (var i = 0; i < event.features.length; i++) {
                        var feature = event.features[i];
                        var jstsGeom = parser.read(feature.getGeometry());
                        if(feature.getGeometry().getType() == 'Point') { var pttype = feature.getGeometry().getCoordinates(); } else { var pttype = feature.getGeometry().getFirstCoordinate(); }
                        var point_sp = ol.proj.transform(pttype, 'EPSG:3857', sp_projection);
                        var point_buff_sp = [point_sp[0], point_sp[1] + parseFloat(document.getElementById('buff').value)]; /* html element 'buff' holds length value */
                        var buffy = ( new ol.geom.LineString([ ol.proj.transform([ point_sp[0], point_sp[1] ], sp_projection, 'EPSG:3857'), ol.proj.transform([ point_buff_sp[0], point_buff_sp[1] ], sp_projection, 'EPSG:3857') ], 'XY') ).getLength(); /* converts line 'buff' state plane meters long to a spherical mercator line and calculates length (buffy)*/
                        var buffered = jstsGeom.buffer(buffy);
                        feature.setGeometry(parser.write(buffered));
                        }
                        }
                        map.getView().fit( vectorSource.getExtent(), (map.getSize()) );
                        });





                        share


























                          0












                          0








                          0







                          I also was interested in creating buffers around features but discovered the inaccuracies of the spherical mercator projection. Using JSTS it's possible to add buffers which are reasonably accurate (distance-wise) if you convert the first (or only) coordinate of the feature to a projection for your region. In my example I use North Carolina State Plane EPSG:32119. Then, I add the length of the buffer (in meters) to one dimension to form another point, the buffer length distance away. These two points form a line, the length of which is converted to a spherical mercator distance which is then used as the buffer distance in the JSTS code.



                          The routine is incorporated in my drag-and-drop code and applies to GeoJSON files only.



                          ol.proj.proj4.register(proj4);
                          var sp_projection = ol.proj.get('EPSG:32119');
                          var vectorSource = new ol.source.Vector();
                          var ddvector = new ol.layer.Vector({
                          opacity: 1.0,
                          visible: 0,
                          source: vectorSource,
                          style: styleFunction
                          });



                          var dragAndDropInteraction = new ol.interaction.DragAndDrop({
                          formatConstructors: [ ol.format.GPX, ol.format.GeoJSON, ol.format.IGC, ol.format.KML, ol.format.TopoJSON ]
                          });



                          var map = new ol.Map({
                          interactions: ol.interaction.defaults().extend([dragAndDropInteraction]),
                          ...
                          });



                          dragAndDropInteraction.on('addfeatures', function(event) {
                          ddvector.setVisible(true);
                          vectorSource.addFeatures(event.features, event.projection);
                          if(event.file.name.endsWith(".geojson") == true && document.getElementById('buff').value > '') {
                          var bufferSource = new ol.source.Vector();
                          var parser = new jsts.io.OL3Parser();
                          for (var i = 0; i < event.features.length; i++) {
                          var feature = event.features[i];
                          var jstsGeom = parser.read(feature.getGeometry());
                          if(feature.getGeometry().getType() == 'Point') { var pttype = feature.getGeometry().getCoordinates(); } else { var pttype = feature.getGeometry().getFirstCoordinate(); }
                          var point_sp = ol.proj.transform(pttype, 'EPSG:3857', sp_projection);
                          var point_buff_sp = [point_sp[0], point_sp[1] + parseFloat(document.getElementById('buff').value)]; /* html element 'buff' holds length value */
                          var buffy = ( new ol.geom.LineString([ ol.proj.transform([ point_sp[0], point_sp[1] ], sp_projection, 'EPSG:3857'), ol.proj.transform([ point_buff_sp[0], point_buff_sp[1] ], sp_projection, 'EPSG:3857') ], 'XY') ).getLength(); /* converts line 'buff' state plane meters long to a spherical mercator line and calculates length (buffy)*/
                          var buffered = jstsGeom.buffer(buffy);
                          feature.setGeometry(parser.write(buffered));
                          }
                          }
                          map.getView().fit( vectorSource.getExtent(), (map.getSize()) );
                          });





                          share













                          I also was interested in creating buffers around features but discovered the inaccuracies of the spherical mercator projection. Using JSTS it's possible to add buffers which are reasonably accurate (distance-wise) if you convert the first (or only) coordinate of the feature to a projection for your region. In my example I use North Carolina State Plane EPSG:32119. Then, I add the length of the buffer (in meters) to one dimension to form another point, the buffer length distance away. These two points form a line, the length of which is converted to a spherical mercator distance which is then used as the buffer distance in the JSTS code.



                          The routine is incorporated in my drag-and-drop code and applies to GeoJSON files only.



                          ol.proj.proj4.register(proj4);
                          var sp_projection = ol.proj.get('EPSG:32119');
                          var vectorSource = new ol.source.Vector();
                          var ddvector = new ol.layer.Vector({
                          opacity: 1.0,
                          visible: 0,
                          source: vectorSource,
                          style: styleFunction
                          });



                          var dragAndDropInteraction = new ol.interaction.DragAndDrop({
                          formatConstructors: [ ol.format.GPX, ol.format.GeoJSON, ol.format.IGC, ol.format.KML, ol.format.TopoJSON ]
                          });



                          var map = new ol.Map({
                          interactions: ol.interaction.defaults().extend([dragAndDropInteraction]),
                          ...
                          });



                          dragAndDropInteraction.on('addfeatures', function(event) {
                          ddvector.setVisible(true);
                          vectorSource.addFeatures(event.features, event.projection);
                          if(event.file.name.endsWith(".geojson") == true && document.getElementById('buff').value > '') {
                          var bufferSource = new ol.source.Vector();
                          var parser = new jsts.io.OL3Parser();
                          for (var i = 0; i < event.features.length; i++) {
                          var feature = event.features[i];
                          var jstsGeom = parser.read(feature.getGeometry());
                          if(feature.getGeometry().getType() == 'Point') { var pttype = feature.getGeometry().getCoordinates(); } else { var pttype = feature.getGeometry().getFirstCoordinate(); }
                          var point_sp = ol.proj.transform(pttype, 'EPSG:3857', sp_projection);
                          var point_buff_sp = [point_sp[0], point_sp[1] + parseFloat(document.getElementById('buff').value)]; /* html element 'buff' holds length value */
                          var buffy = ( new ol.geom.LineString([ ol.proj.transform([ point_sp[0], point_sp[1] ], sp_projection, 'EPSG:3857'), ol.proj.transform([ point_buff_sp[0], point_buff_sp[1] ], sp_projection, 'EPSG:3857') ], 'XY') ).getLength(); /* converts line 'buff' state plane meters long to a spherical mercator line and calculates length (buffy)*/
                          var buffered = jstsGeom.buffer(buffy);
                          feature.setGeometry(parser.write(buffered));
                          }
                          }
                          map.getView().fit( vectorSource.getExtent(), (map.getSize()) );
                          });






                          share











                          share


                          share










                          answered 4 mins ago









                          gNatgNat

                          364




                          364






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f242402%2fbuffering-in-openlayers-3%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              (145452) 2005 RN43 Классификация | Примечания | Ссылки |...

                              Щит и меч (фильм) Содержание Названия серий | Сюжет |...

                              Энтрерриос (город) Содержание История | Географическое...