question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merge featureLayerProvider geometries in the results

See original GitHub issue

I have a case where searching for certain ZIP codes returns 2 separate polygons (because the ZIP code spans 2 counties). I need to be able to merge them to return a single polygon. Before I switched to this geocoder I returned the features and used L.esri.Util.arcgisToGeojson to push the geometries into a feature collection and then merged them using turf.js.

getCityZipBoundary: function(data){
     var df = $q.defer();
     var features = data.features;
     var featureCollection = {
         type: 'featureCollection',
         features: []
     };
     for (var i = features.length - 1; i >= 0; i--) {
         var feature = L.esri.Util.arcgisToGeojson(features[i]);
         featureCollection.features.push(feature);
     }
         var mergedPolygon = turf.merge(featureCollection);
         df.resolve(mergedPolygon);
         return df.promise;
}

Now that I’m using this geocoder plugin I’m not sure how I would be able to merge the geometries.

What I was going to try next but I’m extremely hesitant: It looks like I would need to add code to the suggestions function that checks to see if the input text matches suggestions.text and if they do then change the magicKey value to null.

suggestions: function(text, bounds, callback) {
            var query = this.query().where(this._buildQuery(text)).returnGeometry(true);
            if (bounds) {
                query.intersects(bounds)
            }
            if (this.options.idField) {
                query.fields([this.options.idField].concat(this.options.searchFields))
            }
            var request = query.run(function(error, results, raw) {
                if (error) {
                    callback(error, [])
                } else {
                    this.options.idField = raw.objectIdFieldName;
                    var suggestions = [];
                    var count = Math.min(results.features.length, this.options.maxResults);
                    for (var i = 0; i < count; i++) {
                        var feature = results.features[i];
                        suggestions.push({
                            text: this.options.formatSuggestion.call(this, feature),
                            magicKey: feature.id
                        })
                    }
                    <<<Insert code here to change magicKey value to null?>>>
                    callback(error, suggestions.slice(0, this.options.maxResults).reverse())
                }
            }, this);
            return request
        }

Then, in results function, since you wouldn’t have a key it would make a generic search and then I could merge the geometries the way I did before.

results: function(text, key, bounds, callback) {
            var query = this.query();
            if (key) {
                query.featureIds([key])
            } else {
                query.where(this._buildQuery(text))
            }
            if (bounds) {
                query.within(bounds)
            }
            return query.run(L.Util.bind(function(error, features) {
                var results = [];
                <<<Insert code here to merge features?>>>
                for (var i = 0; i < features.features.length; i++) {
                    var feature = features.features[i];
                    if (feature) {
                        var bounds = this._featureBounds(feature);
                        var result = {
                            latlng: bounds.getCenter(),
                            bounds: bounds,
                            text: this.options.formatSuggestion.call(this, feature),
                            properties: feature.properties,
                            geojson: feature
                        };
                        results.push(result)
                    }
                }
                callback(error, results)
            }, this))
        },

Am I on the right track or is this a terrible idea or am I completely missing the obvious solution?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AnnieGitUrGuncommented, Nov 10, 2016

I’ve tested and can confirm it solves my problem. Thank you!

0reactions
jgravoiscommented, Nov 10, 2016

awesome. thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merge (Data Management)—ArcGIS Pro | Documentation
Use this tool to combine datasets from multiple sources into a new, single output dataset. All input feature classes must be of the...
Read more >
FAQ: Is it possible to merge two or more features into one ...
In ArcGIS Web AppBuilder, use the Merge tool in the Edit widget to merge two or more polygon features into one feature. The...
Read more >
Building Apps with Esri Leaflet - YouTube
We'll combine these tools with other plugins from t Learn how to build lightweight mapping applications with Leaflet and open source Esri ...
Read more >
unify getWhere across list and search · f09d27ad42 - maps
return this.options.where + ' AND (' + queryString.join(' OR ') + ')'; ... data-location="${place.feature.geometry.coordinates.toString()}". >.
Read more >
org.deegree.rendering.r3d.opengl (deegree 3.1.0 API) - Index of
org.deegree.geometry.metadata.jaxb · org.deegree.geometry.multi · org.deegree.geometry.points · org.deegree.geometry.precision
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found