-1

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

https://code.earthengine.google.com/e7aec6c9683ed40a959a01a7ed5dd31f

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");
Map.addLayer(crimes, {}, "Crimes");
Map.addLayer(districts, {}, "Districts");

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:

https://code.earthengine.google.com/?asset=users/paulspeddin/London_Ward

Police Dataset:

https://code.earthengine.google.com/?asset=users/paulspeddin/2018-01-London

2
  • 1
    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, 2019 at 18:11
  • 1
    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, 2019 at 11:49

1 Answer 1

1

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
Map.addLayer(table1, {}, 'polygon areas');
var toMap = polygons.style('green', 3, 'circle', 2, null, 'styling', 5);
Map.addLayer(toMap);
print('output polygons sorted on their number of crimes', polygons.sort('numbPoints'));

See here for the full code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.