Skip to content

Allow specifying areas for custom weighting in a separate file #2037

Closed

Description

@easbar

When we use areas in a custom model file we might face the issue of having to copy and paste large amounts of geojson data into the custom model file (for example city borders). This could be improved by allowing to reference another GeoJSON file used to define the area(s)? Otherwise we'd also have to duplicate the GeoJSON data, say if we want to refer to the same areas in different custom model files.

Activity

  1. easbar commented on Jul 26, 2022

    @easbar
    MemberAuthor

    Currently we use an object where the keys are the area names and the values are GeoJSON features to specify areas in custom-models:

     "areas": {
        "custom1": {
          "type": "Feature",
          "id": "something",
          "properties": {},
          "geometry": {
            "type": "Polygon",
            "coordinates": [
              [
                [ 1.525, 42.511 ],
                [ 1.510, 42.503 ],
                [ 1.531, 42.495 ],
                [ 1.542, 42.505 ],
                [ 1.525, 42.511 ]
              ]
            ]
          }
        }
      }
    

    Unfortunately, this areas object is not compatible GeoJSON. So we cannot just use standard GeoJSON tools to view/create/modify the areas. In contrast, for the custom areas in custom_areas.directory each file needs to be a JsonFeatureCollection (with potentially multiple features).

    So using a JsonFeatureCollection instead of the object we currently use also for the areas in custom models would make it easier to work with multiple areas and more consistent with the custom areas, but we would need some convention how to define the area names. We could use the id field (or the properties object) for this, e.g.:

    "areas": {
     "type" : "FeatureCollection",
     "features" : [{ 
       "type" : "Feature", 
       "id": "custom1",
       "properties" : {},  
       "geometry": {
         "type": "Polygon",
         "coordinates": [
                 [
                    [ 1.525, 42.511 ],
                    [ 1.510, 42.503 ],
                    [ 1.531, 42.495 ],
                    [ 1.542, 42.505 ],
                    [ 1.525, 42.511 ]
                 ]
        ]
       }
     }]
    }
    

    This way we could easily allow multiple areas per file. The main advantage seems that this way we don't need a long list of area file names in the custom model, i.e. something like this (?):

    "area_files": [ "my_areas.json"]
    

    vs. this:

    "area_files": ["areas1.json", "areas2.json", ..., "area3000.json"]
    

    Of course we could also allow multiple areas per file with the current format (one object where each key is the area name and each value is a GeoJson feature describing an area), but the resulting files would be neither valid GeoJSON nor would they be compatible with those in custom_areas.directory. Then again it might be the easiest thing we could do without changing much.

    Another option would be allowing only one feature per file and using a folder structure and some wildcard syntax to organize the files and reference the areas in the custom models. Something like this:

    # files are organized in sub-directories
    custom_areas_dir
       | - eu
         | - ger
           | - berlin
             | - area1
             | - area2
             ...
    

    and this:

    "area_files": [ "eu/ger/berlin/*"]
    

    Anyway, I think the first question is: Should we allow/change/extend the current custom model format to support JsonFeatureCollection?
    To me this seems useful, but supporting both the old and the new format is not ideal either, because of the different schema. Dropping the old format would be a breaking change and the syntax becomes more verbose in case one uses only one area for example.
    So if we change the format, we should of course use JsonFeatureCollection for the new custom model area files as well. It would be easy to allow multiple areas per file and they would be compatible with the custom areas in custom_areas.directory. We could even allow sub-directories and wildcards to reference these files in the custom models on top of this.
    If no, we should either simply carry over the current format to the new files or use only one area/Feature per file, use the file name as area name and maybe allow using the sub-directories + wild-cards for more convenience.

  2. karussell commented on Jul 27, 2022

    @karussell
    Member

    Yeah the areas is not a GeoJSON: this is ugly for the client-side, but there we could display the areas directly in the map?
    And for the server-side we could use command line tools like jq to pick a single area or transform it into a JsonFeatureCollection. Or what if we make by default all areas in custom_areas available in a custom_model too with in_<id> and for id we use custom_areas.features.id?

    (Supporting a JsonFeatureCollection for a single area would be interesting too, but this is for another issue :) )

  3. otbutz commented on Jul 27, 2022

    @otbutz
    Contributor

    Just my two cents, but in the general discussion of breaking changes versus good tooling support, I'd choose tooling support any day.

    There's just so many GIS tooling out there which supports plain GeoJSON. The ability to define an area in https://geojson.io, for example, and then simply copy and paste it would make things much easier for users.

  4. easbar commented on Jan 26, 2023

    @easbar
    MemberAuthor

    Custom areas from files in the custom_areas.directory are now automatically available in all custom profiles: #2725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions