Create points from polygons on the fly

507
7
07-27-2021 02:07 PM
Labels (2)
helenchu
Occasional Contributor II

Hi,

Is it possible to create points from polygons on the fly  and display them on the web map ? 

For example, if I go to style -> Choose attributes -> Expression, then I use the codes below to get the centroid.    I click on "Test" and see it actually returns the centroid but I have no idea how to make the point returned show up on my map.  Any help is greatly appreciated.

var vgeometry = Geometry($feature);
Console('\nvgeometry:' + vgeometry + 'dog' );
//var vline = Polyline(vgeometry);
//Console('\nvgeometry:' + vgeometry + 'dog' + '\nvline:' + vline + 'bird');
var vcentroid = Centroid(vgeometry);
//Console('\ncent:' + vcentroid + 'cat');
var vpoint = Point(vcentroid);
//Console('\npoint:' + vpoint);
console('Monkey');
console(vpoint);
return vpoint;
0 Kudos
7 Replies
RPGIS
by
Regular Contributor

Yes, there are several ways to convert polygons to points by either using a geoprocessing tool called feature to point, or running a python script that gets the central x,y, or xy coordinates.  Both of these methods can be made to use on the fly. 

0 Kudos
helenchu
Occasional Contributor II

Hi Robert,

Is there a widget for web app builder out there for me to use ?  My business case is users apply filters to get polygon features they want but when they zoom out too far those polygons are hard to see on the map.   I'm thinking about having those features displayed as points at a certain map scale.  Any idea or point of direction is greatly appreciated.

0 Kudos
RPGIS
by
Regular Contributor

No, there currently isn't a widget that can do this automatically. But you can use a map-magical method that would make it appear as if your polygons are turning into points. Simply put, you can convert your polygons to points, set the scale for the points to display when the user zooms out and the polygons to not display from the set scale, and then set polygons to display in using the same scale for when the user zooms in and the points to not display.

for example:

  • point layer: set to display from 1:25,000
  • polygon layer: set to display to 1:25,000

This will make it seem like the polygons are turning into points, but they are simply displaying based on how far out or in the user zooms.

Hope this helps.

0 Kudos
helenchu
Occasional Contributor II

My issue is users doing filters on the layer so multiple layers wont work for me unless there's a way to apply filters on both layers.  Thanks @RPGIS .

0 Kudos
RPGIS
by
Regular Contributor

Hi @helenchu,

So there are other options (in tandem with the option I provided) using one of several methods.

  1. You can use the Query Widget to filter one layer by attributes which can then filter the other layer spatially.
  2. You can create a relationship between the two layers (so long as they have a common attribute field). When one filter is applied to the main layer, the corresponding layer for which the layer relates to will be shown.
  3. You can combine the layers and use the normal filter widget to filter based on specific attributes (using a filter set) and set the parameters  to either filter by the previous or all expressions.

Play around with these and see if any of these options to see which ones work for you.

helenchu
Occasional Contributor II

Sounds good @RPGIS!  I'll definitely play around with those ideas.  Thanks a bunch.

0 Kudos
MicZatorsky_AEC
Occasional Contributor

If you are using a web app, a Group Filter will be able to filter both the point and polygon layers (assuming each has the same field and values to filter on)

0 Kudos