Cambodia cities

Important

Please see here for more details

import geopandas

Original dataset is downloaded (manually) from:

url = (
    "https://jeodpp.jrc.ec.europa.eu/ftp/"\
    "jrc-opendata/GHSL/GHS_STAT_UCDB2015MT_GLOBE_R2019A/"\
    "V1-2/GHS_STAT_UCDB2015MT_GLOBE_R2019A.zip/GHS_STAT_UCDB2015MT_GLOBE_R2019A_V1_2.gpkg"
)
url
'https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/GHSL/GHS_STAT_UCDB2015MT_GLOBE_R2019A/V1-2/GHS_STAT_UCDB2015MT_GLOBE_R2019A.zip/GHS_STAT_UCDB2015MT_GLOBE_R2019A_V1_2.gpkg'

Read

Then read in:

p = "GHS_STAT_UCDB2015MT_GLOBE_R2019A/GHS_STAT_UCDB2015MT_GLOBE_R2019A_V1_2.gpkg"
db = geopandas.read_file(p)
/opt/conda/lib/python3.8/site-packages/geopandas/geodataframe.py:422: RuntimeWarning: Sequential read of iterator was interrupted. Resetting iterator. This can negatively impact the performance.
  for feature in features_lst:

Thin

We are interested in Cambodian cities only:

khm = db.query("CTR_MN_NM == 'Cambodia'")

And only on a subset of the attributes available:

vars_to_keep = [
    "ID_HDC_G0", # Unique ID
    "UC_NM_MN",  # City name
    "NTL_AV",    # Mean night time light
    "E_GR_AV14", # Mean greenness 2014
    "geometry"
]

Centroid for geoms

khm.geometry = khm.to_crs(
    epsg=5726
).centroid.to_crs(
    epsg=4326
)
/opt/conda/lib/python3.8/site-packages/geopandas/geodataframe.py:853: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  super(GeoDataFrame, self).__setitem__(key, value)

Write out

out_f = "cambodian_cities.geojson"
! rm -f $out_f
khm[vars_to_keep].to_file(out_f, driver="GeoJSON")
! du -h $out_f
12K	cambodian_cities.geojson