Manual derivation of an Extent for points

1127
4
Jump to solution
12-21-2017 10:54 PM
yangwen
New Contributor III

I'm trying to understand how the xmax, xmin, ymax, ymin values of an Extent relate to point geometries that I'm trying to derive an extent for.

Say I have a collection of geometry point objects each with an x and y value.  I was under the impression that these x and y values can be used to set the mapview extent.  

However upon further examination of the mapview's extent object, it appears the x/y values of an extent is not related to the x/y coordinates of a point.

I've done some searches but found no algorithm to derive an extent from a collection of points.

I've also tried to interrogate the FeatureLayer.fullExtent property after instantiating my points based FeatureLayer.  However the fullExtent property is null in my case. The 4.x API doc doesn't specify the value of this prop for point geometryType FeatureLayer.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
yangwen
New Contributor III

Ahh! I found the reason why the manually instantiated Extent didn't work properly.  

The properties object for the new Extent call contained an extraneous spatialReference setting.  It appears re-defining the spatial reference type caused the extent to not be recognized properly by the view.

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Yang,

   Here is what I came up with:

      function getFeatureLayerSourceExtent(fl){
        var gras = fl.source.map(function(item){
          return item.geometry;
        });
        var sourcePolys = geometryEngine.convexHull(gras.toArray(), true);
        return sourcePolys[0].extent;
      }‍‍‍‍‍‍‍
yangwen
New Contributor III

So in using the convexHull method, the extent that's returned simply contains xmin, xmax, ymin, ymax that are the respective min and max values from the geometries of my source data.   I had already derived the xmin, xmax, ymin, ymax values when I tried to manually instantiate the Extent object.  Perhaps I didn't instantiate the Extent with all the necessary parameters.  I'll keep looking.


So with this convexHull helper method, the same confusion exists.  The extent returned by it - I set it as the mapView.extent property.   However when I console.log out mapvView.extent, the xmax, ymin, ymax values are shown to be magnitudes greater than the extent values that was explicitly defined.  Perhaps this is due to the scale factor?

I was expecting the mapView's extent bounding to be essentially lat and long values.  However that doesn't seem to be the case.

Below shows the mapView extent's large x and y values.

0 Kudos
yangwen
New Contributor III

Ahh! I found the reason why the manually instantiated Extent didn't work properly.  

The properties object for the new Extent call contained an extraneous spatialReference setting.  It appears re-defining the spatial reference type caused the extent to not be recognized properly by the view.

RobertScheitlin__GISP
MVP Emeritus

Yang,

   Sorry I thought your issue was determining the geometries extent, not setting the views extent. Yes the convex hull is a polygon that has its perimeter equal to the outer most geometries so a polygon derived from the min and max of said geometries. An extent should normally contain a spatialReference.

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.