Skip to content

Vector tiles: Replace boundary polygons with lines, add centroids #701

Closed

Description

@1ec5

A boundary that changes often results in many overlapping features in the vector tiles that are mostly redundant to each other. For example, a tile containing San José, California, weighs in the tens of megabytes, even though it contains little besides boundaries: #698 (comment). San José might be an outlier in terms of the sheer number of annexations,1 but we can expect more problem spots in the future, particularly as mappers begin recording land swaps along river boundaries, which are complex to begin with.

The overlapping boundaries inherently come with exorbitant size overhead, even if we simplify the geometries aggressively: #702. For a sense of scale, the boundary polygons representing San José over time currently contain a total of 2,444,653 separately encoded coordinates, whereas a corresponding set of boundary polylines would contain only 69,674 separately encoded coordinates, since concurrent boundary edges would be encoded only once. Boundary edge polylines also require much less effort to render on the client side than full polygons.

Some of this redundancy is necessary, since a given edge might run in opposite directions after applying winding order to each boundary. In lay terms, along a given north–south boundary edge, San José might lie to the west of the boundary in one year but to the east in another year. A rigorous solution like #603 would probably have to address this problem comprehensively, but for now we could either defer boundary edge labels or find a way to keep two distinct linestring features running in opposite directions.

A polygon representation of boundaries has some utility, especially for rendering boundary halos of different colors, for example when a national park abuts an administrative boundary. It’s also essential for making a choropleth map out of administrative areas: #700. However, overlapping polygons make it impossible to reliably style boundaries as dashes: openmaptiles/openmaptiles#1604 (comment). For example, if we were to reintroduce dashed lines of different lengths based on admin_level=*, the dashes would clump up together forming a solid line whenever a municipal boundary runs concurrently with a county or state boundary.

A naïve approach would be to replace existing usage of ST_AsMVTGeom with whatever we did in OpenHistoricalMap/ohm-deploy#89 to copy the details of an associatedStreet relation onto the member ways. We’ll also need to generate centroid point features for these boundaries at the same time: #543 (comment). But we won’t be able to encode any side-dependent attributes, such as names, until we copy each polyline feature once per winding order.

Footnotes

  1. 1,174 distinct iterations for San José, compared to only 891 for Columbus, Ohio, another major city that experienced sprawl. ↩

Activity

  1. danrademacher commented on Mar 6, 2024

    @danrademacher

    Interested in thoughts from @Rub21 and @batpad on this, especially paired with #702. To me, on-the-fly replacement of polygons with lines and the generation of centroids for labels seems like it might become overly complex, but admittedly I'm beyond the limits of my understanding of what sorts of Postgres queries we can include in our TOML file without hitting some sort of query limit.

  2. Rub21 commented on Mar 8, 2024

    @Rub21
    Member

    The idea of converting polygons into lines sounds promising; it will significantly reduce the size of many tiles, and for long-term efficiency, that would be beneficial to me as well. However, I believe this adjustment needs to be made during the data loading process into PostGIS, rather than within the tiler. Therefore, it should be modified in imposm by changing a parameter to load lines instead of polygons for certain types of tags.

    To achieve this, we can initiate the process by copying the tile-imposm directory into ohm-deploy/images. This approach allows for better customization without altering the existing functionality in osm-seed.

    For clarification, is the central point intended to be added specifically for administrative boundaries? There will be two cases: if the administrative boundaries are polygons and relations. In the case of relations, they may already contain points within them. However, for polygons, we need to add a center point. Adding a central point could be challenging using imposm, but we could explore other alternatives such as a PostGIS function to create, delete, or update center points for polygons

  3. 1ec5 commented on Mar 8, 2024

    @1ec5
    MemberAuthor

    For clarification, is the central point intended to be added specifically for administrative boundaries? There will be two cases: if the administrative boundaries are polygons and relations. In the case of relations, they may already contain points within them. However, for polygons, we need to add a center point. Adding a central point could be challenging using imposm, but we could explore other alternatives such as a PostGIS function to create, delete, or update center points for polygons

    Yes, automatically generating a centroid point is important, for more than just boundaries: #543 (comment). For boundaries, we’re already working around the issue by manually mapping and styling explicit points near the centroids. So I think we can pursue that optimization in parallel.

  4. moved this from Todo - Known Path to Parking Lot in OpenHistoricalMap Dev Planningon Mar 27, 2024
  5. jeffreyameyer commented on Apr 30, 2024

    @jeffreyameyer
    Member

    @Rub21 - any update on this?

  6. Rub21 commented on May 1, 2024

    @Rub21
    Member

    @jeffreyameyer , Per voice call with Sanjay and Dan, we agree that generating the center-point for each polygon or relation that comes from OSM may be challenging. The process of adding, updating, and removing a center-point is not currently supported by IMPOSM. Apart of that, converting those boundaries into linestrings may affect names styling. we can chat bit more about it.

  7. 1ec5 commented on May 2, 2024

    @1ec5
    MemberAuthor

    Per voice call with Sanjay and Dan, we agree that generating the center-point for each polygon or relation that comes from OSM may be challenging. The process of adding, updating, and removing a center-point is not currently supported by IMPOSM.

    Are you sure the centroid point needs to be generated by imposm3? Can we instead generate it on the fly in one of the PostgreSQL queries in the tiler’s providers? For example, the landuse_points provider would query the osm_landuse_areas table, calling a PostGIS function such as ST_Centroid instead of just regurgitating the geometry verbatim.

    Apart of that, converting those boundaries into linestrings may affect names styling.

    Yes, generating the centroid points is a prerequisite for representing boundaries as lines.

    To get the performance improvements, another important step would be to either join the boundary relations to deduplicate their LineString geometries or copy the relations’ details onto the member ways at import time. imposm3 might be more of an obstacle for doing this. I think we should take a look at how OpenMapTiles implements boundaries using imposm3.

    /ref #543 (comment)

  8. 16 remaining items

  9. 1ec5 commented on May 9, 2024

    @1ec5
    MemberAuthor

    If we want to keep only one geometry as a line in this case, we may need to add all the relation information that has been part of it. it means that the line should retain information from the 164 relations, including all details necessary to display on the map, such as name, start date, and end date. as well as the following lines too, that also a lot attributes informations for a tiles size.

    Now that we’re generating separate point features for the labels, name properties on the lines wouldn’t be useful for labeling centroids anymore. They could be useful for boundary edge labels, but only if we indicate whether a name applies to the left or right side of the linestring. That would be unnecessary for now, since our styles don’t have boundary edge labels yet.

    I was thinking that we could also detect that the way is part of relations that completely cover a certain time period. My example way from San José was continuously part of a boundary relation for many years, so all we need is a single linestring with the earliest relation’s start_date and the latest relation’s end_date. I don’t know how feasible this is with the current architecture. We can track this idea in a separate issue to keep things clear.

  10. changed the title [-]Replace boundary polygons with lines in vector tiles[/-] [+]Vector tiles: Replace boundary polygons with lines, add centroids[/+] on May 15, 2024
  11. vknoppkewetzel commented on May 15, 2024

    @vknoppkewetzel

    I've updated this ticket with a new name to capture it as vector tile work, and created a separate design-related ticket for the stylesheet updates (#787 )

  12. danrademacher commented on May 17, 2024

    @danrademacher

    This task has been completed; the process of creating the centroids and avoiding them in case relations have label is working fine. https://vtiles.staging.openhistoricalmap.org/#4.26/-3.9/-88.94

    Screenshot 2024-05-08 at 5 51 54 PM

    @Rub21 can you clarify here -- in order for @vknoppkewetzel and @tsinn to style all labels for polygons, it sounds like sometimes they need to target place_points and sometimes they need to target land_ohm_centroids. Is that correct? The two will never be part of a single layer?

  13. vknoppkewetzel commented on May 20, 2024

    @vknoppkewetzel

    I can style with them as separate but it seems like it would make sense to fold into the place_points data in the future I think?

    I do know some of the attributes are slightly different.
    image
    image

    in place_points, there is no reference to admin_level like in land_ohm_centroids. In place_points however, type has a value that is useful to know (possibly?) - the naming convention may be country-dependent, but the above example screenshots shows type=county.

    This means:

    1. country name data layer styling for place_points AND country name data layer styling for land_ohm_centroids
    2. etc, 2 layers for all admin levels
  14. Rub21 commented on May 21, 2024

    @Rub21
    Member

    can you clarify here -- in order for @vknoppkewetzel and @tsinn to style all labels for polygons, it sounds like sometimes they need to target place_points and sometimes they need to target land_ohm_centroids. Is that correct? The two will never be part of a single layer?

    How is the current flow and distribution of objects in the layers?

    The place_points layer consists of all objects that have place=* according to the OpenStreetMap wiki. This includes place=city, place=town, place=village, and place=hamlet. Examples of these points are:

    When importing to the database using tiler-imposm, a conversion from place to type in the attributes is performed. These were established at the beginning of the project.

    So, if there is a relation like this one, this relation object will be added to two layers:

    1. land_ohm (relation/polygons), which is the area of the relation.
    2. place_points, because the relation has a point member with place=state.

    Screenshot

    What we are currently developing:

    For the land_ohm_lines and land_ohm_centroids layers:

    • land_ohm (relations/polygons) that are areas will be converted to linestring, and all attributes will be copied to the linestring and it will be represented as the land_ohm_lines layer.
    • land_ohm (polygons) that are areas will have their centroids calculated, and all attributes will be copied to the centroids, and it will be represented as the land_ohm_centroids layer.

    Therefore, for the layers, the same object will have the same attributes in the land_ohm_lines and land_ohm_centroids layers.

    As example:

    • A Relation 2800841 has been created with a group of ways and a label as a member. It has a label as a point member with the attribute place=state (Node 2113249224). This point will be shown in the place_points layer.
    image image

    Therefore, according to our new conversion of linestrings and centroids, we would have same object in place_points , land_ohm_lines and land_ohm_centroids, as the comment here: #701 (comment)

    image

    To resolve the issue of duplication in the place_points and land_ohm_centroids layers, we have implemented some functions in the PostgreSQL database. If there is a point member in the relation with the attribute place=*, it will be shown in the place_points layer as it currently is. Otherwise, if there is no point member, it will be shown in the land_ohm_centroids layer. This avoids having two points displaying the same attributes.

    For example, the above relation and way do not have a member point with place=*. For this reason, we are creating the centroids. Note, we need to create centroids for these objects because once we convert them into linestrings, there will be no way to show the representative names without using the centroids.

    https://vtiles.staging.openhistoricalmap.org/#7.14/-10.298/-78.884
    image

  15. vknoppkewetzel commented on May 21, 2024

    @vknoppkewetzel

    Thanks @Rub21 . Currently Country and state labels are housed in place_points , and will in the future be housed in land_ohm_centroids ?

    OR just "the relevant country and state created centroids will be brought into place labels"??? So land_ohm_centroids is everything else?

    This task has been completed; the process of creating the centroids and avoiding them in case relations have label is working fine.
    I had understood that the task was completed here, but perhaps that was just referencing the wrapping up of land_ohm_lines?

    In #787 I've updated a test style that shows the updated land_ohm_lines and includes a TEST data layer with the land_ohm_centroids highlighted in red text. I can circle back to refine those further when the centroid work is finished. Does that sound like the right next steps for me on my end?

    I am just trying to figure out how I am meant to style land_ohm_centroids. :) I initially was confused to not see as many points as I expected, and then to see them referencing a variety of admin levels - but not consistently, geographically.

    However, if the answer is just "duplicate all admin related labels and expect to pull from both place_points and land_ohm_centroids I can do that haha

  16. 1ec5 commented on May 21, 2024

    @1ec5
    MemberAuthor

    If there is a point member in the relation with the attribute place=*, it will be shown in the place_points layer as it currently is.

    Does this distinguish between the admin_centre and label roles? A member with either role would typically be a place=* node, but we would still want to generate a centroid for the United States if it lacks a label member, even if the node for Washington, D.C., is an admin_centre member. These days, I view admin_centre as somewhat off-topic for OHM, because mappers can indicate a “seat of government of” relationship in Wikidata; however, we have over 6,000 occurrences of this role, and I’d expect the number to increase over time due to influence from OSM.

  17. jeffreyameyer commented on May 25, 2024

    @jeffreyameyer
    Member

    Barring the discussion above related to admin_centre and label roles, given that this is now operating in production, is this ticket done? @danrademacher w00t!

  18. Rub21 commented on Jun 3, 2024

    @Rub21
    Member

    This ticket is done, closing here!

  19. added theissue type on Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions