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):
Using the Data Function
Next, I downloaded the 'Points in Polygons' Data Function from the Exchange, and unzipped the file on my computer:
The 'SFD' file unzipped is the Data Function file of interest. To bring this into Spotfire, go to Insert > Data Function > From File:
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:
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):
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:
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:
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:
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:
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:
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.
Recommended Comments
There are no comments to display.