better roads means faster travel
Question 1
step 1: we import the osm data and the administrative data
// import country boundaries
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017");
var cambodia = countries.filter(ee.Filter.eq("country_na","Cambodia"));
//import road feature
var roads = ee.FeatureCollection('projects/servir-mekong/osm/cambodia/gis_osm_roads');
// print the road categories
print("road categories:", roads.aggregate_histogram("fclass"));
// add data to map
Map.addLayer(roads,{},"roads")
Step 2: add some points to the map and rename the points to points

step 3: add the code below and hit run
// assign weight to road netwok
var weight = 1;
// create rasters for the road network
var roadRaster = ee.Image().toByte().paint(roads, weight).unmask(10,false);
//create friction layer
var roadFriction = roadRaster
//convert points to raster
var pointsRaster = ee.Image().toByte().paint(points, 1);
//calculate cumulative cost
var cumulativeCost = roadFriction.cumulativeCost({
source: pointsRaster,
maxDistance: 10000});
Map.addLayer(cumulativeCost.updateMask(cumulativeCost.lt(5000)), {min: 0, max: 5000, palette: ['darkgreen', 'green', 'yellow', 'orange',"red","darkred","purple","white"]}, 'accessibility', true);
Question 2:
step 1: copy the code below, paste it in the Google Earth Engine and hit the run button
// import country boundaries
var countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017");
var cambodia = countries.filter(ee.Filter.eq("country_na","Cambodia"));
//import road feature
var roads = ee.FeatureCollection('projects/servir-mekong/osm/cambodia/gis_osm_roads');
// import osm health center data
var osmhealthCenter = ee.FeatureCollection("projects/servir-mekong/osm/cambodia/hotosm_khm_health_facilities").filterBounds(cambodia);
// print the road categories
print("road categories:", roads.aggregate_histogram("fclass"));
Map.addLayer(roads,{},"roads");
Map.addLayer(osmhealthCenter.draw("red"),{},"osm health center");
step 2: filter for different types of roads using the code below
// create lists to categorize the road networks
var primary = ["primary","primary_link"];
var secondary = ["secondary","secondary_link"];
var tertiary = ["tertiary","tertiary_link"];
var other = ee.List(roads.aggregate_histogram("fclass").keys()).removeAll(primary).removeAll(secondary).removeAll(tertiary);
// filter for primary, secondary and tertiary roads
var primaryRoads = roads.filter(ee.Filter.inList("fclass",primary));
var secondaryRoads = roads.filter(ee.Filter.inList("fclass",secondary));
var tertiaryRoads = roads.filter(ee.Filter.inList("fclass",tertiary));
var otherRoads = roads.filter(ee.Filter.inList("fclass",other));
// add data to map
Map.addLayer(primaryRoads.draw("red"),{},"primary roads");
Map.addLayer(secondaryRoads.draw("green"),{},"secondary roads");
Map.addLayer(tertiaryRoads.draw("blue"),{},"tertiary roads");
Map.addLayer(otherRoads.draw("black"),{},"other roads");
step 3: use the code below to set weights and calculate the cost distance to a hospital
// assign weight to road netwok
var weightPrimary = 0.5;
var weightSecondary = 1;
var weightTertiary = 1.5;
var weightOther = 2;
var weightNonRoads = 10;
// create rasters for the road network
var primaryRaster = ee.Image().toByte().paint(primaryRoads, weightPrimary).unmask(0);
var secondaryRaster = ee.Image().toByte().paint(secondaryRoads, weightSecondary).unmask(0);
var tertiaryRaster = ee.Image().toByte().paint(tertiaryRoads, weightTertiary).unmask(0);
var otherRaster = ee.Image().toByte().paint(otherRoads, weightOther).unmask(0);
//create friction layer
var roadFriction = primaryRaster.add(secondaryRaster).add(tertiaryRaster).add(otherRaster);
roadFriction = roadFriction.where(roadFriction.eq(0),weightNonRoads);
//convert points to raster
var pointsRaster = ee.Image().toByte().paint(osmhealthCenter, 1);
//calculate cumulative cost
var cumulativeCost = roadFriction.cumulativeCost({
source: pointsRaster,
maxDistance: 100000,
geodeticDistance:false});
// add data to map
Map.addLayer(cumulativeCost.clip(cambodia), {min: 0, max: 1e5, palette: ['darkgreen', 'green', 'yellow', 'orange',"red","darkred","purple","white"]}, 'accessibility', true);