Jump to content
We've recently updated our Privacy Statement, available here. ×
  • Use Geofencing to Select all Points within Polygons


    This article demonstrates how to employ the Points in Polygons Data Function from the community Exchange. This is useful if you have a set of individual points with coordinates, a separate polygon layer, and you want to select all points fenced in by certain polygons in the polygon layer. Along with visualizing this in Map Charts, this is useful for focused calculations on specific points within districts.

    63217c8b629f1174704678.gif.dded26c95265c598bd46ecccfb59a3a7.gif

    Background

    This page demonstrates how to employ the Points in Polygon's Data Function from the Exchange. This is useful if you have a set of individual points with coordinates, a separate polygon layer, and you want to select all points fenced in by certain polygons in the polygon layer. Along with visualizing this in Map Charts, this is useful for focused calculations on specific points within districts.

    In this example, I will select New York City Crime incidents (point data) via Zip Code districts (polygon data).

    Setup

    I first imported a Shapefile with only Zip Code boundaries as one data table (left), and separate NYPD Crime Incidents with only GPS coordinates as a separate data table (right):

    snag_479ac6b.thumb.png.f70dc03620e6ce56db7764b5f25b0576.png

    Using the Data Function

    Next, I downloaded the 'Points in Polygons' Data Function from the Exchange, and unzipped the file on my computer:

    2018-05-09_16-07-50.png.d42754743b9eaf49a5a51bf339775480.png

    The 'SFD' file unzipped is the Data Function file of interest. To bring this into Spotfire, go to Insert > Data Function > From File:

    2018-05-09_16-10-45.png.20ed8f112eb6bf2aba3c621715d78f6f.png

    From here, I set the Geometry and Id columns of the Data Function Parameters to the Geometry and Id columns in my Zip Code data table, and I set the Longitude and Latitude columns to respective columns  in my NYPD Crimes data table:

    2018-05-09_16-21-26.png.9cd31193f0c88aedc11edd091f161264.png

    For output, this data function creates a new Id column to be imported into the GPS Coordinate data table (NYPD Crimes data table in my case):

    2018-05-09_16-24-06.png.b7bac845dcc36908752698341b543d86.png

    Click OK to register the data function. (Note that the 'sp' and 'wkb' R packages must be installed to your TERR Engine for the Data Function to work. You can install these at any time).

    At this point, the Data Function will execute on ALL polygons and find all points within them, which may be your desired final output:

    2018-05-09_16-30-23.png.bd3071132a84c1d6d9d0ba5193993f79.png

    Selectively Choosing Polygons via Markings

    If you want to only mark points from specific polygons you independently select, you may use the Marking feature in the data function parameters. Simply go to your existing data function, choose Edit Parameters, and select your Marking. Also be sure to check the box Refresh function automatically so this data function continuously updates as you choose different polygons:

    2018-05-09_16-33-27_0.png.87411ff881925f567889b73bced0c653.png

    Within your Table Visualizations (or other calculations), you may hide the unselected points by Limiting by Marking or by using a Filter Expression for the Id column:

    2018-05-09_16-41-08.png.82763245a31978ad43be8877f67528e6.png

    This will now only show you NYPD Crime data for the Zip Codes you have selected.

    Details on Creating the Interactive Map

    The map itself requires two layers. The interactive layer should be set as your polygon layer, in my case, it's the Zip Code Boundaries layer:

    2018-05-09_16-45-34.png.a28921ba9122121fcc9fb9d71bf201eb.png

    Note that I created the 'Zip Code Boundaries' polygon layer as a Feature Layer and the 'NYPD Crimes' point data as a Marker Layer. The transparency of the 'Zip Codes Boundaries' layer should be set to the maximum, leaving only the polygon borders visible.

    To have the points belonging to certain polygons be colored by those polygons, simply choose the Id column for Colors in the 'NYPD Crimes' point data layer:

    2018-05-09_16-49-43.thumb.png.aeafff259cb0fb3176268ae89b2bc7bf.png

    Try it yourself

    When you download this Data Function from the Exchange, a sample DXP will be provided that you can explore on your own.


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...