go-cart-io / cartogram-web

A website that makes it easy to generate contiguous area cartograms
https://go-cart.io
MIT License
1 stars 2 forks source link

Ensure the accuracy and consistency of map projections and land area calculation #10

Open atima opened 1 week ago

atima commented 1 week ago
  1. Verify the projection of maps in internal/static/cartdata, user-uploaded geospatial files, and visualizations. Make sure it is accurate across various components (e.g., should epsg:6933 be displayed as identity?)
  2. Standardize the projection between cartogram-cpp, cartogram-web, and cartdata files.
  3. Consider standardizing the world projection, especially since we may not receive a world flag from users. If not possible, I am wondering if we should save crs in json file, and select proper vega.projection based on crs instead the currentMapName === "world" condition.
  4. Check the calculation of land area data for accuracy.

Related code:

cartogram-web\internal\cartogram.py (projection for user-uploaded geospatial files)

    if minx >= -180.0 and maxx <= 180.0 and miny >= -90.0 and maxy <= 90.0:
        gdf = gdf.to_crs("epsg:6933")

    if not any(gdf.columns.str.startswith('Land Area')):
        gdf['Land Area (sq.km.)'] = gdf.area

cartogram-web\frontend\src\assets\template.vg.json (default projection)

      "name": "source_projection",
      "size": { "signal": "[width, height]" },
      "fit": { "signal": "data('source_geojson')" },
      "type": "identity",
      "reflectY": true

cartogram-web\frontend\src\viewer\components\CPanelLegend.vue (ad-hoc projection for the world map)

  if (store.currentMapName === "world" && state.version.name === 'Land Area') {
    // Gall–Peters projection
    vega.projection('cylindricalEqualArea', geoCylindricalEqualArea)
    versionSpec.projections[0].type = "cylindricalEqualArea"
    versionSpec.projections[0].reflectY = false
    versionSpec.projections[0].parallel = 45
  }
atima commented 4 days ago

After discussions with @nihalzp and @adisidev, we have decided to use cartogram-cpp for projection. Please modify both cartogram-cpp and cartogram-web to accommodate this solution.

  1. Projection and GeoJSON Handling:
    • Project and send GeoJSON to the user immediately after they select the boundary file.
    • Check for topology issues during this step. The easiest way to handle this is by throwing a custom error from cartogram.py to report any issues to the user.
  2. Temporary File Management:
    • You may write files to the system temporarily. Ensure these files are removed as soon as they are no longer needed, as users may leave the site before saving their progress.
    • Note that the cleanup script only works if there is a record in the database. Alternatively, we can save all temporary files in the /tmp folder and delete all files in this folder daily.

The cartogram binary (commit 623487f) also writes files to the internalfolder, which is undesirable. Please check if this issue has been resolved.

Possible related code cartogram-web\internal\web.py: cartogram_preprocess(), cleanup() cartogram-web\internal\cartogram.py : preprocess(), local_function() cartogram-web\internal\executable\cartwrap.py cartogram-web\internal\web.py: cleanup()