# Summing amount of vector points in area of another vector using Google Earth Engine?

So I have 2 layers each are both vectors and not images. here the link:

I have written some basic code to display the data which is this:

``````var crimes = ee.FeatureCollection("users/paulspeddin/2018-01-London");
var districts = ee.FeatureCollection("users/paulspeddin/London_Ward");
``````

How can I sum all the points within the boundary lines? What I want is to sum all the points and then to sum the number of points within each district and then create a colour gradient coded map where red is high, green is low.

How can I access each district of the code from one layer to count if it is within the boundaries of another?

London Boundaries Dataset:

Police Dataset:

• Here's a reference to Google Earth Engine API. Pay careful attention to information on spatial joins or overlays. developers.google.com/earth-engine – smiller Apr 16 '19 at 18:11
• You have to share your assets to get help by setting 'Anyone can read'. Click on your asset and press 'share' to get there. Currently, nobody can work with your assets. – Kuik Apr 18 '19 at 11:49

To return every geometry as a coloured polygon on the map, use the function 'style' on feature collections to give them a colour based on a property. To add a colour hex as property based on a property with a number (in your case the number of crimes reported in a district), You should use this function, which create a colour hex based on a value between 0 and 255.

Then use the code below to add the coloured polygons to the map:

``````// input data
var points = table2;
var polygons = table1;
// Maxvalue should be equal to or more than the input value in 'getColor()'
// otherwise, the color outputted will be a user defined other color
var maxValue = 200;
var maxColor = 'ff00

// calculate the number of points inside each polygon
polygons = polygons.map(function(poly){
var geom = ee.Feature(poly).geometry();
var inPoly = points.filterBounds(geom);
var numbPoints = inPoly.size();
var color = getColor(numbPoints, maxValue, maxColor);
var styling = ee.Dictionary({styling: ee.Dictionary({color: color})});
return ee.Feature(geom).setMulti(styling).set('numbPoints', numbPoints);
});

// add the points to the map